Documentation ¶
Overview ¶
Package openai is used to call the api of ChatGPT-3.5
Index ¶
- type Chat
- func (c *Chat) AddMessageAsAssistant(content string)
- func (c *Chat) AddMessageAsSystem(content string)
- func (c *Chat) AddMessageAsUser(content string)
- func (c *Chat) GetHistoryMessages() []map[string]string
- func (c *Chat) NewChat() (*ChatResponse, error)
- func (c *Chat) NewChatText() ([]string, error)
- func (c *Chat) SetAuthorizationKey(key string)
- func (c *Chat) SetFrequencyPenalty(frequencyPenalty float64)
- func (c *Chat) SetLogitBias(logitBias map[string]int)
- func (c *Chat) SetMaxTokens(maxTokens int)
- func (c *Chat) SetN(n int)
- func (c *Chat) SetPresencePenalty(presencePenalty float64)
- func (c *Chat) SetStopArr(stop []string)
- func (c *Chat) SetStopStr(stop string)
- func (c *Chat) SetStream(stream bool)
- func (c *Chat) SetTemperature(temperature float64)
- func (c *Chat) SetTopP(topP float64)
- func (c *Chat) SetUser(user string)
- type ChatResponse
- type Choice
- type Message
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
Chat is the chat data
func (*Chat) AddMessageAsAssistant ¶
AddMessageAsAssistant is used to add message to the chat as assistant.
func (*Chat) AddMessageAsSystem ¶
AddMessageAsSystem is used to add message to the chat as system.
func (*Chat) AddMessageAsUser ¶
AddMessageAsUser is used to add message to the chat as user.
func (*Chat) GetHistoryMessages ¶
GetHistoryMessages is used to get the history messages.
func (*Chat) NewChat ¶
func (c *Chat) NewChat() (*ChatResponse, error)
NewChat GetOpenAIResponse is the function to get the response from the ChatGPT-3.5.
func (*Chat) NewChatText ¶
NewChatText Get the messages from the response.
func (*Chat) SetAuthorizationKey ¶
SetAuthorizationKey is used to set authorization key
func (*Chat) SetFrequencyPenalty ¶
SetFrequencyPenalty frequency_penalty number Optional Defaults to 0; Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
func (*Chat) SetLogitBias ¶
SetLogitBias logit_bias map Optional Defaults to null; Modify the likelihood of specified tokens appearing in the completion. Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
func (*Chat) SetMaxTokens ¶
SetMaxTokens max_tokens integer Optional Defaults to inf; The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will be (4096 - prompt tokens).
func (*Chat) SetPresencePenalty ¶
SetPresencePenalty presence_penalty number Optional Defaults to 0; Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
func (*Chat) SetStopArr ¶
SetStopArr stop string or array Optional Defaults to null; Up to 4 sequences where the API will stop generating further tokens.
func (*Chat) SetStopStr ¶
SetStopStr stop string or array Optional Defaults to null; Up to 4 sequences where the API will stop generating further tokens.
func (*Chat) SetStream ¶
SetStream stream boolean Optional Defaults to false. If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.
func (*Chat) SetTemperature ¶
SetTemperature temperature number Optional Defaults to 1; What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.
func (*Chat) SetTopP ¶
SetTopP top.p number Optional Defaults to 1; An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
type ChatResponse ¶
type ChatResponse struct { // ID is the ID of the chat completion. ID string `json:"id"` // Object is the object type of the chat completion. Object string `json:"object"` // Created is the timestamp of when the chat completion was created. Created int `json:"created"` // Model is the ID of the model used to generate the chat completion. Choices []Choice `json:"choices"` // Usage is the usage object is used to represent the usage of the API. Usages Usage `json:"usage"` }
ChatResponse is the chat completion object is used to represent a chat completion.
type Choice ¶
type Choice struct { // The index of the choice. Index int `json:"index"` // Msg is the message object is used to represent a message in a conversation. Msg Message `json:"message"` // FinishReason is the reason the chat completion stopped. FinishReason string `json:"finish_reason"` }
Choice is the choice object is used to represent a choice in a chat completion.
type Message ¶
type Message struct { // Role is the role of the message. Can be "user", "system" or "assistant". Role string `json:"role"` // Content is the content of the message. Content string `json:"content"` }
Message is the message struct.
type Usage ¶
type Usage struct { // PromptTokens is the number of tokens used for the prompt. PromptTokens int `json:"prompt_tokens"` // CompletionTokens is the number of tokens used for the completion. CompletionTokens int `json:"completion_tokens"` // TotalTokens is the total number of tokens used. TotalTokens int `json:"total_tokens"` }
Usage is the usage object is used to represent the usage of the API.