openai

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package openai is used to call the api of ChatGPT-3.5

Index

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

func (c *Chat) AddMessageAsAssistant(content string)

AddMessageAsAssistant is used to add message to the chat as assistant.

func (*Chat) AddMessageAsSystem

func (c *Chat) AddMessageAsSystem(content string)

AddMessageAsSystem is used to add message to the chat as system.

func (*Chat) AddMessageAsUser

func (c *Chat) AddMessageAsUser(content string)

AddMessageAsUser is used to add message to the chat as user.

func (*Chat) GetHistoryMessages

func (c *Chat) GetHistoryMessages() []map[string]string

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

func (c *Chat) NewChatText() ([]string, error)

NewChatText Get the messages from the response.

func (*Chat) SetAuthorizationKey

func (c *Chat) SetAuthorizationKey(key string)

SetAuthorizationKey is used to set authorization key

func (*Chat) SetFrequencyPenalty

func (c *Chat) SetFrequencyPenalty(frequencyPenalty float64)

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

func (c *Chat) SetLogitBias(logitBias map[string]int)

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

func (c *Chat) SetMaxTokens(maxTokens int)

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) SetN

func (c *Chat) SetN(n int)

SetN How many chat completion choices to generate for each input message.

func (*Chat) SetPresencePenalty

func (c *Chat) SetPresencePenalty(presencePenalty float64)

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

func (c *Chat) SetStopArr(stop []string)

SetStopArr stop string or array Optional Defaults to null; Up to 4 sequences where the API will stop generating further tokens.

func (*Chat) SetStopStr

func (c *Chat) SetStopStr(stop string)

SetStopStr stop string or array Optional Defaults to null; Up to 4 sequences where the API will stop generating further tokens.

func (*Chat) SetStream

func (c *Chat) SetStream(stream bool)

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

func (c *Chat) SetTemperature(temperature float64)

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

func (c *Chat) SetTopP(topP float64)

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.

func (*Chat) SetUser

func (c *Chat) SetUser(user string)

SetUser user string Optional; A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL