Documentation
¶
Index ¶
- Constants
- Variables
- func ExtractToolParts(msg *openai.ChatMessage) ([]llm.ContentPart, []llm.ToolCall)
- type APIType
- 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 openai.Doer) Option
- func WithHooks(hooks llm.ProviderHooks) Option
- func WithModel(model string) Option
- func WithOrganization(organization string) Option
- func WithResponseFormat(responseFormat *ResponseFormat) Option
- func WithToken(token string) Option
- type Provider
- func (o *Provider) Call(ctx context.Context, prompt string, options ...llm.ContentOption) (string, error)
- func (o *Provider) CreateEmbedding(ctx context.Context, inputTexts []string) ([][]float32, error)
- func (o *Provider) GenerateContent(ctx context.Context, messages []llm.Message, options ...llm.ContentOption) (*llm.ContentResponse, error)
- type ResponseFormat
- type ResponseFormatJSONSchema
- type ResponseFormatJSONSchemaProperty
Constants ¶
const ( APITypeOpenAI APIType = APIType(openai.APITypeOpenAI) APITypeAzure = APIType(openai.APITypeAzure) APITypeAzureAD = APIType(openai.APITypeAzureAD) )
const DefaultAPIVersion = "2023-05-15"
Variables ¶
var ( ErrEmptyResponse = fmt.Errorf("no response") ErrMissingToken = fmt.Errorf("missing the OpenAI API key, set it in the OPENAI_API_KEY environment variable") ErrMissingAzureModel = fmt.Errorf("model needs to be provided when using Azure API") ErrMissingAzureEmbeddingModel = fmt.Errorf("embeddings model needs to be provided when using Azure API") ErrUnexpectedResponseLength = fmt.Errorf("unexpected length of response") )
var ResponseFormatJSON = &ResponseFormat{Type: "json_object"}
ResponseFormatJSON is the JSON response format.
Functions ¶
func ExtractToolParts ¶
func ExtractToolParts(msg *openai.ChatMessage) ([]llm.ContentPart, []llm.ToolCall)
ExtractToolParts extracts the tool parts from a message.
Types ¶
type Option ¶
type Option func(*options)
Option is a functional option for the OpenAI client.
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 ¶
WithHTTPClient allows setting a custom HTTP client. If not set, the default value is http.DefaultClient.
func WithHooks ¶
func WithHooks(hooks llm.ProviderHooks) Option
WithHooks allows setting a custom Callback Handler.
func WithModel ¶
WithModel passes the OpenAI model to the client. If not set, the model is read from the OPENAI_MODEL environment variable. Required when ApiType is Azure.
func WithOrganization ¶
WithOrganization passes the OpenAI organization to the client. If not set, the organization is read from the OPENAI_ORGANIZATION.
func WithResponseFormat ¶
func WithResponseFormat(responseFormat *ResponseFormat) Option
WithResponseFormat allows setting a custom response format.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is an llm.Provider implementation for OpenAI.
func (*Provider) Call ¶
func (o *Provider) Call(ctx context.Context, prompt string, options ...llm.ContentOption) (string, error)
Call requests a completion for the given prompt.
func (*Provider) CreateEmbedding ¶
CreateEmbedding creates embeddings for the given input texts.
func (*Provider) GenerateContent ¶
func (o *Provider) GenerateContent(ctx context.Context, messages []llm.Message, options ...llm.ContentOption) (*llm.ContentResponse, error)
GenerateContent implements the llm.Provider interface.
type ResponseFormat ¶
type ResponseFormat = openai.ResponseFormat
ResponseFormat is the response format for the OpenAI client.
type ResponseFormatJSONSchema ¶
type ResponseFormatJSONSchema = openai.ResponseFormatJSONSchema
ResponseFormatJSONSchema is the JSON Schema response format in structured output.
type ResponseFormatJSONSchemaProperty ¶
type ResponseFormatJSONSchemaProperty = openai.ResponseFormatJSONSchemaProperty
ResponseFormatJSONSchemaProperty is the JSON Schema property in structured output.