Documentation ¶
Overview ¶
Package openai is the OpenAI llm provider
Index ¶
- Constants
- type ChatCompletionMessage
- type OpenAIProvider
- func (p *OpenAIProvider) GetChatCompletions(userInstruction string) (*ai.InvokeResponse, error)
- func (p *OpenAIProvider) GetOverview() (*ai.OverviewResponse, error)
- func (p *OpenAIProvider) ListToolCalls() (map[uint32]ai.ToolCall, error)
- func (p *OpenAIProvider) Name() string
- func (p *OpenAIProvider) RegisterFunction(tag uint32, functionDefinition *ai.FunctionDefinition, connID uint64) error
- func (p *OpenAIProvider) UnregisterFunction(_ string, connID uint64) error
- type ReqBody
- type RespBody
- type RespChoice
- type RespMessage
- type RespUsage
Constants ¶
const APIEndpoint = "https://api.openai.com/v1/chat/completions"
APIEndpoint is the endpoint for OpenAI
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatCompletionMessage ¶
type ChatCompletionMessage struct { // Role is the messages author Role string `json:"role"` // Content of the message Content string `json:"content"` // Name describes participant, provides the model information to differentiate // between participants of the same role. Name string `json:"name,omitempty"` // ToolCalls describes the tool calls generated by the model. ToolCalls []ai.ToolCall `json:"tool_calls,omitempty"` // ToolCallID is the ID of the tool call ToolCallID string `json:"tool_call_id,omitempty"` }
ChatCompletionMessage describes `messages` for /chat/completions
type OpenAIProvider ¶
type OpenAIProvider struct { // APIKey is the API key for OpenAI APIKey string // Model is the model for OpenAI // eg. "gpt-3.5-turbo-1106", "gpt-4-turbo-preview", "gpt-4-vision-preview", "gpt-4" Model string }
OpenAIProvider is the provider for OpenAI
func NewProvider ¶
func NewProvider(apiKey string, model string) *OpenAIProvider
NewProvider creates a new OpenAIProvider
func (*OpenAIProvider) GetChatCompletions ¶
func (p *OpenAIProvider) GetChatCompletions(userInstruction string) (*ai.InvokeResponse, error)
GetChatCompletions get chat completions for ai service
func (*OpenAIProvider) GetOverview ¶
func (p *OpenAIProvider) GetOverview() (*ai.OverviewResponse, error)
GetOverview get overview for ai service
func (*OpenAIProvider) ListToolCalls ¶
func (p *OpenAIProvider) ListToolCalls() (map[uint32]ai.ToolCall, error)
ListToolCalls list tool functions
func (*OpenAIProvider) Name ¶
func (p *OpenAIProvider) Name() string
Name returns the name of the provider
func (*OpenAIProvider) RegisterFunction ¶
func (p *OpenAIProvider) RegisterFunction(tag uint32, functionDefinition *ai.FunctionDefinition, connID uint64) error
RegisterFunction register function
func (*OpenAIProvider) UnregisterFunction ¶
func (p *OpenAIProvider) UnregisterFunction(_ string, connID uint64) error
UnregisterFunction unregister function Be careful: a function can have multiple instances, remove the offline instance only.
type ReqBody ¶
type ReqBody struct { // Model describes the ID of the model to use for the completion. Model string `json:"model"` // Messages describes the messages in the conversation. Messages []ChatCompletionMessage `json:"messages"` // Tools describes the tool calls generated by the model. Tools []ai.ToolCall `json:"tools"` // chatCompletionTool }
ReqBody is the request body
type RespBody ¶
type RespBody struct { // ID is the unique identifier for the chat completion. ID string `json:"id"` // Object describes the object type, it is always "chat.completion". Object string `json:"object"` // Created describes the timestamp when the chat completion was created. Created int `json:"created"` // Model describes the model used for the chat completion. Model string `json:"model"` // Choices describes the choices made by the model, can more than one if `n`>1 Choices []RespChoice `json:"choices"` // Usage describes the token usage statistics for the chat completion request. Usage RespUsage `json:"usage"` // SystemFingerprint describes the system fingerprint of the chat completion. SystemFingerprint string `json:"system_fingerprint"` }
RespBody is the response body
type RespChoice ¶
type RespChoice struct { FinishReason string `json:"finish_reason"` Index int `json:"index"` Message ChatCompletionMessage `json:"message"` }
RespChoice is used to indicate the choice in Response by `FinishReason`