Documentation
¶
Overview ¶
Package openai implements the OpenAI provider.
Index ¶
Constants ¶
View Source
const Name = "openai"
Name of the provider.
Variables ¶
This section is empty.
Functions ¶
func ProcessResponse ¶
func ProcessResponse(resp ResponseBody) (string, error)
ProcessResponse processes the response from the API.
Types ¶
type Choice ¶
type Choice struct {
FinishReason string `json:"finish_reason"`
Index int `json:"index"`
Message message.Message `json:"message"`
}
Choice OpenAI API definition.
type OpenAI ¶
type OpenAI struct {
*provider.Provider
// Endpoint of the LLM provider.
Endpoint string `json:"url" validate:"required"`
// Token of the LLM provider.
Token string `json:"-" validate:"required"`
// contains filtered or unexported fields
}
OpenAI provider definition.
func New ¶
func New( options ...provider.ClientFunc, ) (*OpenAI, error)
New creates a new OpenAI provider.
func NewDefault ¶
func NewDefault(options ...provider.ClientFunc) (*OpenAI, error)
NewDefault creates a new OpenAI provider with default values.
func (*OpenAI) Completion ¶
Completion generates a completion using the provider API. Optionally pass WithResponseBody to unmarshal the response body. It will always return the original, unparsed response body, if no error.
NOTE: Not all options are available for all providers.
type RequestBody ¶
type RequestBody struct {
Messages []message.Message `json:"messages"`
Model string `json:"model"`
Stream bool `json:"stream"`
MaxTokens int `json:"max_completion_tokens,omitempty"`
Seed int `json:"seed,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
}
RequestBody represents the request body for the OpenAI API.
Click to show internal directories.
Click to hide internal directories.