Documentation
¶
Index ¶
- Variables
- type CompletionParams
- type CompletionRequestMessage
- type CreateChatCompletionDeltaResponse
- type CreateChatCompletionRequest
- type CreateChatCompletionRequestStop
- type CreateChatCompletionResponse
- type CreateCompletionResponseUsage
- type FetchFn
- type GPTAPI
- type GPTAPIOptions
- type GetMessageByIdFunction
- type Message
- type OpenAIChatCompletionRequest
- type SendMessageOptions
- type UpsertMessageFunction
Constants ¶
This section is empty.
Variables ¶
View Source
var ( CHATGPT_MODEL = "gpt-3.5-turbo" USER_LABEL_DEFAULT = "User" ASSISTANT_LABEL_DEFAULT = "ChatGPT" )
View Source
var Seg gse.Segmenter
Functions ¶
This section is empty.
Types ¶
type CompletionParams ¶
type CompletionParams struct {
Prompt string `json:"prompt"`
MaxTokens int `json:"max_tokens,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
N int `json:"n,omitempty"`
Logprobs int `json:"logprobs,omitempty"`
Echo bool `json:"echo,omitempty"`
Stop []string `json:"stop,omitempty"`
PresencePenalty float64 `json:"presence_penalty,omitempty"`
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
BestOf int `json:"best_of,omitempty"`
Model string `json:"model,omitempty"`
ModelOwner string `json:"model_owner,omitempty"`
Stream bool `json:"stream,omitempty"`
State map[string]interface{} `json:"state,omitempty"`
StopSequences [][]string `json:"stop_sequences,omitempty"`
InjectOpenAIAnswers bool `json:"inject_openai_answers,omitempty"`
}
type CreateChatCompletionRequest ¶
type CreateChatCompletionRequest struct {
Model string `json:"model"`
Messages []CompletionRequestMessage `json:"messages"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
N int `json:"n,omitempty"`
Stream bool `json:"stream,omitempty"`
Stop *CreateChatCompletionRequestStop `json:"stop,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
PresencePenalty float64 `json:"presence_penalty,omitempty"`
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
LogitBias map[string]int `json:"logit_bias,omitempty"`
User string `json:"user,omitempty"`
}
type CreateChatCompletionRequestStop ¶
type CreateChatCompletionRequestStop interface{}
type CreateChatCompletionResponse ¶
type CreateChatCompletionResponse struct {
ID string `json:"id"`
Choices []struct {
Message struct {
Content string `json:"content"`
Role string `json:"role"`
} `json:"message"`
} `json:"choices"`
Detail struct {
Message string `json:"message"`
} `json:"detail"`
Usage CreateCompletionResponseUsage `json:"usage"`
}
type GPTAPI ¶
type GPTAPI struct {
// contains filtered or unexported fields
}
func NewChatGPTAPI ¶
func NewChatGPTAPI(opts *GPTAPIOptions) (*GPTAPI, error)
func (*GPTAPI) SendMessage ¶
type GPTAPIOptions ¶
type GPTAPIOptions struct {
ApiKey string
ApiBaseUrl string `default:"https://api.openai.com"`
Debug bool `default:"false"`
CompletionParams *CompletionParams
SystemMessage string
MaxModelTokens int `default:"4096"`
MaxResponseTokens int `default:"1000"`
MessageStore *leveldb.DB // 未指定默认值,需要在使用时手动初始化
GetMessageById GetMessageByIdFunction
UpsertMessage UpsertMessageFunction
Fetch func(req *http.Request) (*http.Response, error) // 未指定默认值,需要在使用时手动初始化
}
type GetMessageByIdFunction ¶
type Message ¶
type Message struct {
ID string `json:"id"`
Text string `json:"text"`
Role string `json:"role"`
Name string `json:"name,omitempty"`
Delta string `json:"delta,omitempty"`
Detail interface{} `json:"detail,omitempty"`
ParentMessageID string `json:"parentMessageId,omitempty"`
ConversationID string `json:"conversationId,omitempty"`
Usage CreateCompletionResponseUsage `json:"usage,omitempty"`
}
type OpenAIChatCompletionRequest ¶
type OpenAIChatCompletionRequest struct {
Model string `json:"model"`
Prompt string `json:"prompt"`
MaxTokens int `json:"max_tokens"`
Temperature float64 `json:"temperature,omitempty"`
TopP float64 `json:"top_p,omitempty"`
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
PresencePenalty float64 `json:"presence_penalty,omitempty"`
StopSequences []string `json:"stop,omitempty"`
N int `json:"n,omitempty"`
Logprobs int `json:"logprobs,omitempty"`
Echo bool `json:"echo,omitempty"`
User string `json:"user,omitempty"`
State map[string]map[string][]float32 `json:"state,omitempty"`
Messages []CompletionRequestMessage `json:"messages,omitempty"`
NumTokens int `json:"num_tokens,omitempty"`
ErrorHandler func(error) `json:"-"`
Debug bool `json:"-"`
Payload map[string]interface{} `json:"-"`
}
type SendMessageOptions ¶
type SendMessageOptions struct {
Name string `json:"name,omitempty"`
ParentMessageId string `json:"parentMessageId,omitempty"`
MessageId string `json:"messageId,omitempty"`
Stream bool `json:"stream,omitempty"`
SystemMessage string `json:"systemMessage,omitempty"`
TimeoutMs int `json:"timeoutMs,omitempty"`
OnProgress func(*Message) `json:"-"`
AbortSignal <-chan struct{} `json:"-"`
UpdateApiKey string `json:"-"` // 用于更新 api key 的场景 如果不为空则使用该 api key
}
type UpsertMessageFunction ¶
Click to show internal directories.
Click to hide internal directories.