Documentation ¶
Index ¶
- type APISettings
- type APIType
- type AnthropicMetadata
- type Chat
- func (c *Chat) AddAssistantMessage(s string)
- func (c *Chat) AddUserMessage(s string)
- func (c *Chat) ClearMessages()
- func (c *Chat) ClearSystemMessage()
- func (c *Chat) GetMessages() []Message
- func (c *Chat) GetMessagesWithoutSystemMessage() []Message
- func (c *Chat) GetSystemMessage() string
- func (c *Chat) ReplaceLastAssistantMessage(s string)
- func (c *Chat) SetSystemMessage(s string)
- func (c *Chat) String() string
- type Client
- func (c *Client) AddModelDefinition(modelDefinition ModelDefinition)
- func (c *Client) CreateResponse() (int, chan MessageChunk, error)
- func (c *Client) CreateResponseWithPrompt(usrPrompt string, assistantResponse string) (int, chan MessageChunk, error)
- func (c *Client) ResetChat()
- func (c Client) String() string
- type JsonMessage
- type Message
- type MessageChunk
- type MessageType
- type MistralResponseFormat
- type ModelDefinition
- type ModelSettings
- type ModelSettingsAnthropic
- type ModelSettingsMistral
- type ModelSettingsOpenAI
- type OpenAIResponseFormat
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APISettings ¶
APISettings is a struct representing the settings needed to interact with an API. It contains the API key, the API endpoint, and the API type.
type APIType ¶
type APIType int
APIType is an enum representing the type of API. It determines how the client interacts with the API, and which settings are required or supported.
type AnthropicMetadata ¶
type AnthropicMetadata struct {
UserID string `json:"user_id"`
}
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
Chat is a struct representing a chat between a user and an assistant.
func NewChatFromMessages ¶
NewChatFromMessages creates a new Chat from a list of messages. The messages are added to the chat in the order they are provided. There may only be one system message in the list of messages, and it must be the first message.
func (*Chat) AddAssistantMessage ¶
AddAssistantMessage Adds an assistant message to the chat.
func (*Chat) AddUserMessage ¶
AddUserMessage Adds a user message to the chat.
func (*Chat) ClearMessages ¶
func (c *Chat) ClearMessages()
ClearMessages Removes all non-system messages from the chat.
func (*Chat) ClearSystemMessage ¶
func (c *Chat) ClearSystemMessage()
ClearSystemMessage Removes the system message from the chat.
func (*Chat) GetMessages ¶
GetMessages returns all messages in the chat.
func (*Chat) GetMessagesWithoutSystemMessage ¶
GetMessagesWithoutSystemMessage returns all messages in the chat except the system message.
func (*Chat) GetSystemMessage ¶
GetSystemMessage returns the system message in the chat.
func (*Chat) ReplaceLastAssistantMessage ¶
ReplaceLastAssistantMessage Replaces the last assistant message in the chat with a new message. If the last message is not an assistant message, this function does nothing.
func (*Chat) SetSystemMessage ¶
SetSystemMessage Adds a system message to the chat.
type Client ¶
type Client struct { Chat Chat // contains filtered or unexported fields }
func (*Client) AddModelDefinition ¶
func (c *Client) AddModelDefinition(modelDefinition ModelDefinition)
AddModelDefinition adds a model definition to the client.
func (*Client) CreateResponse ¶
func (c *Client) CreateResponse() (int, chan MessageChunk, error)
CreateResponse creates a response to a user prompt using the model definitions added to the client. It returns the total amount of responses initiated, a channel to receive message chunks, and an error if one occurred.
func (*Client) CreateResponseWithPrompt ¶
func (c *Client) CreateResponseWithPrompt(usrPrompt string, assistantResponse string) (int, chan MessageChunk, error)
CreateResponseWithPrompt creates a response to a user prompt using the model definitions added to the client. If functions like CreateResponse, but allows for a user prompt and assistant response to be passed in first.
type JsonMessage ¶
func NewJsonMessageFromMessage ¶
func NewJsonMessageFromMessage(message Message) JsonMessage
type Message ¶
type Message struct { Type MessageType Text string }
Message is a struct representing a message in a chat. It has a type and a text.
func NewAssistantMessage ¶
NewAssistantMessage Creates a new Message with the given text of type AssistantMessage.
func NewMessage ¶
func NewMessage(t MessageType, text string) *Message
NewMessage Creates a new Message with the given type and text.
func NewSystemMessage ¶
NewSystemMessage Creates a new Message with the given text of type SystemMessage.
func NewUserMessage ¶
NewUserMessage Creates a new Message with the given text of type UserMessage.
type MessageChunk ¶
type MessageType ¶
type MessageType int
MessageType is an enum representing the type of a message in a chat. It can be a SystemMessage, UserMessage, or AssistantMessage. Chats usually start with a SystemMessage, followed by an alternating sequence of UserMessage and AssistantMessage.
const ( SystemMessage MessageType = iota UserMessage AssistantMessage )
type MistralResponseFormat ¶
type MistralResponseFormat struct {
Type string `json:"type"`
}
type ModelDefinition ¶
type ModelDefinition struct { Name string APISettings APISettings ModelSettings ModelSettings }
ModelDefinition is a struct representing a model definition. It contains a friendly name for the model and all the settings needed to interact with the model.
func NewModelDefinition ¶
func NewModelDefinition(name string, apiType APIType, apiKey string, modelName string) ModelDefinition
NewModelDefinition creates a new ModelDefinition with the given name, API type, API key, and model name. By default, the API endpoint is left as the default value and only the model name is set in the settings.
func (*ModelDefinition) CreateRequest ¶
func (m *ModelDefinition) CreateRequest(chat Chat) (*http.Request, error)
type ModelSettings ¶
type ModelSettings interface { // MakeBody creates the body of the request to the model API. MakeBody(chat Chat) []byte Set(key string, value interface{}) error }
ModelSettings is an interface representing the settings needed to interact with a model.
func NewModelSettings ¶
func NewModelSettings(apiType APIType, modelName string) ModelSettings
type ModelSettingsAnthropic ¶
type ModelSettingsAnthropic struct { ModelSettings `json:"-"` Model string `json:"model"` MaxTokens int `json:"max_tokens"` Metadata *AnthropicMetadata `json:"metadata,omitempty"` StopSequences []string `json:"stop_sequences,omitempty"` Stream null.Bool `json:"stream,omitempty"` Temperature null.Float `json:"temperature,omitempty"` TopK null.Int `json:"top_k,omitempty"` TopP null.Float `json:"top_p,omitempty"` Messages []JsonMessage `json:"messages"` System null.String `json:"system,omitempty"` }
func (ModelSettingsAnthropic) MakeBody ¶
func (m ModelSettingsAnthropic) MakeBody(chat Chat) []byte
func (ModelSettingsAnthropic) Set ¶
func (m ModelSettingsAnthropic) Set(key string, value interface{}) error
type ModelSettingsMistral ¶
type ModelSettingsMistral struct { ModelSettings `json:"-"` Model string `json:"model"` ResponseFormat *MistralResponseFormat `json:"response_format,omitempty"` Temperature null.Float `json:"temperature,omitempty"` TopP null.Float `json:"top_p,omitempty"` MaxTokens null.Int `json:"max_tokens,omitempty"` Stream null.Bool `json:"stream,omitempty"` SafePrompt null.Bool `json:"safe_prompt,omitempty"` RandomSeed null.Int `json:"random_seed,omitempty"` Messages []JsonMessage `json:"messages"` }
func (ModelSettingsMistral) MakeBody ¶
func (m ModelSettingsMistral) MakeBody(chat Chat) []byte
func (ModelSettingsMistral) Set ¶
func (m ModelSettingsMistral) Set(key string, value interface{}) error
type ModelSettingsOpenAI ¶
type ModelSettingsOpenAI struct { ModelSettings `json:"-"` Model string `json:"model"` FrequencyPenalty null.Float `json:"frequency_penalty,omitempty"` LogitBias map[string]int `json:"logit_bias,omitempty"` Logprobs null.Bool `json:"logprobs,omitempty"` TopLogprobs null.Int `json:"top_logprobs,omitempty"` MaxTokens null.Int `json:"max_tokens,omitempty"` PresencePenalty null.Float `json:"presence_penalty,omitempty"` ResponseFormat *OpenAIResponseFormat `json:"response_format,omitempty"` Seed null.Int `json:"seed,omitempty"` Stop []string `json:"stop,omitempty"` Stream null.Bool `json:"stream,omitempty"` Temperature null.Float `json:"temperature,omitempty"` TopP null.Float `json:"top_p,omitempty"` User null.String `json:"user,omitempty"` Messages []JsonMessage `json:"messages"` }
func (ModelSettingsOpenAI) MakeBody ¶
func (m ModelSettingsOpenAI) MakeBody(chat Chat) []byte
func (ModelSettingsOpenAI) Set ¶
func (m ModelSettingsOpenAI) Set(key string, value interface{}) error
type OpenAIResponseFormat ¶
type OpenAIResponseFormat struct {
Type string `json:"type"`
}