Documentation ¶
Index ¶
- Constants
- Variables
- type APIType
- type Chat
- func (o *Chat) Call(ctx context.Context, messages []schema.ChatMessage, options ...llms.CallOption) (*schema.AIChatMessage, error)
- func (o *Chat) CreateEmbedding(ctx context.Context, inputTexts []string) ([][]float64, error)
- func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, ...) ([]*llms.Generation, error)
- func (o *Chat) GeneratePrompt(ctx context.Context, promptValues []schema.PromptValue, ...) (llms.LLMResult, error)
- func (o *Chat) GetNumTokens(text string) int
- type ChatMessage
- type LLM
- func (o *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOption) (string, error)
- func (o *LLM) CreateEmbedding(ctx context.Context, inputTexts []string) ([][]float64, error)
- func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error)
- func (o *LLM) GeneratePrompt(ctx context.Context, promptValues []schema.PromptValue, ...) (llms.LLMResult, error)
- func (o *LLM) GetNumTokens(text string) int
- type Option
- func WithAPIType(apiType APIType) Option
- func WithAPIVersion(apiVersion string) Option
- func WithBaseURL(baseURL string) Option
- func WithEmbeddingModel(embeddingModel string) Option
- func WithHTTPClient(client openaiclient.Doer) Option
- func WithModel(model string) Option
- func WithOrganization(organization string) Option
- func WithToken(token string) Option
Constants ¶
const ( RoleSystem = "system" RoleAssistant = "assistant" RoleUser = "user" RoleFunction = "function" )
const ( APITypeOpenAI APIType = APIType(openaiclient.APITypeOpenAI) APITypeAzure = APIType(openaiclient.APITypeAzure) APITypeAzureAD = APIType(openaiclient.APITypeAzureAD) )
const (
DefaultAPIVersion = "2023-05-15"
)
Variables ¶
var ( ErrEmptyResponse = errors.New("no response") ErrMissingToken = errors.New("missing the OpenAI API key, set it in the OPENAI_API_KEY environment variable") //nolint:lll ErrMissingAzureEmbeddingModel = errors.New("embeddings model needs to be provided when using Azure API") ErrUnexpectedResponseLength = errors.New("unexpected length of response") )
Functions ¶
This section is empty.
Types ¶
type APIType ¶
type APIType openaiclient.APIType
type Chat ¶
func (*Chat) Call ¶
func (o *Chat) Call(ctx context.Context, messages []schema.ChatMessage, options ...llms.CallOption) (*schema.AIChatMessage, error)
Call requests a chat response for the given messages.
func (*Chat) CreateEmbedding ¶
CreateEmbedding creates embeddings for the given input texts.
func (*Chat) Generate ¶
func (o *Chat) Generate(ctx context.Context, messageSets [][]schema.ChatMessage, options ...llms.CallOption) ([]*llms.Generation, error)
func (*Chat) GeneratePrompt ¶
func (o *Chat) GeneratePrompt(ctx context.Context, promptValues []schema.PromptValue, options ...llms.CallOption) (llms.LLMResult, error)
func (*Chat) GetNumTokens ¶
type ChatMessage ¶
type ChatMessage = openaiclient.ChatMessage
type LLM ¶
func (*LLM) CreateEmbedding ¶
CreateEmbedding creates embeddings for the given input texts.
func (*LLM) Generate ¶
func (o *LLM) Generate(ctx context.Context, prompts []string, options ...llms.CallOption) ([]*llms.Generation, error)
func (*LLM) GeneratePrompt ¶
func (o *LLM) GeneratePrompt(ctx context.Context, promptValues []schema.PromptValue, options ...llms.CallOption) (llms.LLMResult, error)
func (*LLM) GetNumTokens ¶
type Option ¶
type Option func(*options)
func WithAPIType ¶
WithAPIType passes the api type to the client. If not set, the default value is APITypeOpenAI.
func WithAPIVersion ¶
WithAPIVersion passes the api version to the client. If not set, the default value is DefaultAPIVersion.
func WithBaseURL ¶
WithBaseURL passes the OpenAI base url to the client. If not set, the base url is read from the OPENAI_BASE_URL environment variable. If still not set in ENV VAR OPENAI_BASE_URL, then the default value is https://api.openai.com/v1 is used.
func WithEmbeddingModel ¶
WithEmbeddingModel passes the OpenAI model to the client. Required when ApiType is Azure.
func WithHTTPClient ¶
func WithHTTPClient(client openaiclient.Doer) Option
WithHTTPClient allows setting a custom HTTP client. If not set, the default value is http.DefaultClient.
func WithModel ¶
WithModel passes the OpenAI model to the client. If not set, the model is read from the OPENAI_MODEL environment variable.
func WithOrganization ¶
WithOrganization passes the OpenAI organization to the client. If not set, the organization is read from the OPENAI_ORGANIZATION.