openAI

package
v0.19.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package openAI defines the data structures used for OpenAI API requests and responses. It includes models for request payloads, response data, and associated metadata.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(id, name string, v *Config, workers map[eosc.RequireId]eosc.IWorker) (eosc.IWorker, error)

Create 创建驱动实例

func NewFactory

func NewFactory() eosc.IExtenderDriverFactory

NewFactory 创建service_http驱动工厂

func Register

func Register(register eosc.IExtenderDriverRegister)

Register 注册驱动

Types

type Chat

type Chat struct {
	// contains filtered or unexported fields
}

Chat represents the chat mode implementation. It includes the endpoint and methods for request and response conversion.

func NewChat

func NewChat() *Chat

NewChat initializes and returns a new Chat instance.

func (*Chat) Endpoint

func (c *Chat) Endpoint() string

Endpoint returns the API endpoint for the Chat mode.

func (*Chat) RequestConvert

func (c *Chat) RequestConvert(ctx eocontext.EoContext, extender map[string]interface{}) error

RequestConvert converts the request body for the Chat mode. It modifies the HTTP context to include the appropriate endpoint and formatted request body.

func (*Chat) ResponseConvert

func (c *Chat) ResponseConvert(ctx eocontext.EoContext) error

ResponseConvert converts the response body for the Chat mode. It processes the response to ensure it conforms to the expected format and encoding.

type ClientRequest

type ClientRequest struct {
	// Messages is a list of messages forming the conversation history.
	Messages []*Message `json:"messages"`
}

ClientRequest represents the request payload sent to the OpenAI API.

type CompletionTokensDetails

type CompletionTokensDetails struct {
	// ReasoningTokens is the number of tokens used for reasoning in the response.
	ReasoningTokens int `json:"reasoning_tokens"`
}

CompletionTokensDetails provides detailed information about completion tokens.

type Config

type Config struct {
	APIKey       string `json:"openai_api_key"`      // APIKey is the authentication key for accessing OpenAI API.
	Organization string `json:"openai_organization"` // Organization specifies the associated organization ID (optional).
	Base         string `json:"openai_api_base"`     // Base is the base URL for OpenAI API. It can be customized if needed.
}

Config represents the configuration for OpenAI API. It includes the necessary fields for authentication and base URL configuration.

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

func (*Converter) RequestConvert

func (c *Converter) RequestConvert(ctx eocontext.EoContext, extender map[string]interface{}) error

func (*Converter) ResponseConvert

func (c *Converter) ResponseConvert(ctx eocontext.EoContext) error

type Error added in v0.19.5

type Error struct {
	Message string `json:"message"`
	Type    string `json:"type"`
}

type IModelMode

type IModelMode interface {
	Endpoint() string
	convert.IConverter
}

IModelMode defines the interface for model modes. It includes methods for retrieving the endpoint and performing data conversion.

type Message

type Message struct {
	// Role indicates the role of the message sender (e.g., "system", "user", "assistant").
	Role string `json:"role"`
	// Content contains the actual text of the message.
	Content string `json:"content"`
}

Message represents a single message in the conversation.

type ModelConfig

type ModelConfig struct {
	FrequencyPenalty float64 `json:"frequency_penalty"`
	MaxTokens        int     `json:"max_tokens"`
	PresencePenalty  float64 `json:"presence_penalty"`
	ResponseFormat   string  `json:"response_format"`
	Temperature      float64 `json:"temperature"`
	TopP             float64 `json:"top_p"`
}

type Response

type Response struct {
	// Id is the unique identifier for the response.
	Id string `json:"id"`
	// Object specifies the type of object returned (e.g., "response").
	Object string `json:"object"`
	// Created is the timestamp of when the response was generated.
	Created int `json:"created"`
	// Model indicates the model used to generate the response.
	Model string `json:"model"`
	// SystemFingerprint is a fingerprint of the system generating the response.
	SystemFingerprint string `json:"system_fingerprint"`
	// Choices contains the list of choices generated by the model.
	Choices []ResponseChoice `json:"choices"`
	// Usage provides information about token usage for the request and response.
	Usage Usage `json:"usage"`
	Error Error `json:"error"`
}

Response represents the response payload received from the OpenAI API.

type ResponseChoice

type ResponseChoice struct {
	// Index is the position of the choice in the response list.
	Index int `json:"index"`
	// Message contains the generated message for this choice.
	Message Message `json:"message"`
	// Logprobs provides log probability data for the tokens (if available).
	Logprobs interface{} `json:"logprobs"`
	// FinishReason indicates why the generation stopped (e.g., "length", "stop").
	FinishReason string `json:"finish_reason"`
}

ResponseChoice represents a single choice in the response.

type Usage

type Usage struct {
	// PromptTokens is the number of tokens used in the input prompt.
	PromptTokens int `json:"prompt_tokens"`
	// CompletionTokens is the number of tokens generated in the response.
	CompletionTokens int `json:"completion_tokens"`
	// TotalTokens is the total number of tokens used (prompt + completion).
	TotalTokens int `json:"total_tokens"`
	// CompletionTokensDetails provides a breakdown of completion tokens.
	CompletionTokensDetails CompletionTokensDetails `json:"completion_tokens_details"`
}

Usage provides information about the token counts for the request and response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL