Documentation
¶
Index ¶
- Constants
- Variables
- type ChatCompletionChoice
- type ChatCompletionMessage
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionStreamChoice
- type ChatCompletionStreamChoiceDelta
- type ChatCompletionStreamResponse
- type ContentFilterResults
- type Conversation
- type Dao
- type FinishReason
- type FunctionCall
- type FunctionDefinedeprecated
- type FunctionDefinition
- type Hate
- type LLM
- func (l *LLM) CreateConversation(ctx context.Context, name string) (Conversation, error)
- func (l *LLM) CreateMessage(ctx context.Context, conversationId string, req ChatCompletionRequest) (Message, error)
- func (l *LLM) CreateMessageStream(ctx context.Context, conversationId string, req ChatCompletionRequest, ...)
- func (l *LLM) DeleteConversation(ctx context.Context, id string) error
- func (l *LLM) DeleteMessage(ctx context.Context, id string) error
- func (l *LLM) GetConversation(ctx context.Context, id string) (Conversation, error)
- func (l *LLM) GetMessage(ctx context.Context, id string) (Message, error)
- func (l *LLM) ListConversations(ctx context.Context) ([]Conversation, error)
- func (l *LLM) ListMessages(ctx context.Context, conversationId string) ([]Message, error)
- type MemoryDao
- func (d *MemoryDao) DeleteConversation(ctx context.Context, id string) error
- func (d *MemoryDao) DeleteMessage(ctx context.Context, id string) error
- func (d *MemoryDao) GetConversation(ctx context.Context, id string) (Conversation, error)
- func (d *MemoryDao) GetConversationLastMessage(ctx context.Context, id string) (Message, error)
- func (d *MemoryDao) GetMessage(ctx context.Context, id string) (Message, error)
- func (d *MemoryDao) ListConversations(ctx context.Context) ([]Conversation, error)
- func (d *MemoryDao) ListMessages(ctx context.Context, conversationId string) ([]Message, error)
- func (d *MemoryDao) SaveConversation(ctx context.Context, conversation Conversation) (Conversation, error)
- func (d *MemoryDao) SaveMessage(ctx context.Context, message Message) (Message, error)
- type Message
- type PromptAnnotation
- type SelfHarm
- type Sexual
- type Usage
- type Violence
Constants ¶
View Source
const ( ChatMessageRoleSystem = "system" ChatMessageRoleUser = "user" ChatMessageRoleAssistant = "assistant" ChatMessageRoleFunction = "function" )
Chat message role defined by the OpenAI API.
Variables ¶
View Source
var DefaultDao = NewMemoryDao()
View Source
var NotImplementError = errors.New("the method not implement")
Functions ¶
This section is empty.
Types ¶
type ChatCompletionChoice ¶
type ChatCompletionChoice struct {
Index int `json:"index"`
Message ChatCompletionMessage `json:"message"`
// FinishReason
// stop: API returned complete message,
// or a message terminated by one of the stop sequences provided via the stop parameter
// length: Incomplete model output due to max_tokens parameter or token limit
// function_call: The model decided to call a function
// content_filter: Omitted content due to a flag from our content filters
// null: API response still in progress or incomplete
FinishReason FinishReason `json:"finish_reason"`
}
type ChatCompletionMessage ¶
type ChatCompletionMessage struct {
Role string `json:"role"`
Content string `json:"content"`
// This property isn't in the official documentation, but it's in
// the documentation for the official library for python:
// - https://github.com/openai/openai-python/blob/main/chatml.md
// - https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
Name string `json:"name,omitempty"`
FunctionCall *FunctionCall `json:"function_call,omitempty"`
}
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []ChatCompletionMessage `json:"messages"`
MaxTokens int `json:"max_tokens,omitempty"`
Temperature float32 `json:"temperature,omitempty"`
TopP float32 `json:"top_p,omitempty"`
N int `json:"n,omitempty"`
Stream bool `json:"stream,omitempty"`
Stop []string `json:"stop,omitempty"`
PresencePenalty float32 `json:"presence_penalty,omitempty"`
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"`
// LogitBias is must be a token id string (specified by their token ID in the tokenizer), not a word string.
// incorrect: `"logit_bias":{"You": 6}`, correct: `"logit_bias":{"1639": 6}`
// refs: https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias
LogitBias map[string]int `json:"logit_bias,omitempty"`
User string `json:"user,omitempty"`
Functions []FunctionDefinition `json:"functions,omitempty"`
FunctionCall any `json:"function_call,omitempty"`
}
ChatCompletionRequest represents a request structure for chat completion API.
func (*ChatCompletionRequest) FromPrompt ¶
func (r *ChatCompletionRequest) FromPrompt(model, prompt string)
func (*ChatCompletionRequest) ToPrompt ¶
func (r *ChatCompletionRequest) ToPrompt() string
func (*ChatCompletionRequest) ToPromptWithoutRole ¶
func (r *ChatCompletionRequest) ToPromptWithoutRole() string
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []ChatCompletionChoice `json:"choices"`
Usage Usage `json:"usage"`
}
ChatCompletionResponse represents a response structure for chat completion API.
type ChatCompletionStreamChoice ¶
type ChatCompletionStreamChoice struct {
Index int `json:"index"`
Delta ChatCompletionStreamChoiceDelta `json:"delta"`
FinishReason FinishReason `json:"finish_reason"`
ContentFilterResults ContentFilterResults `json:"content_filter_results,omitempty"`
}
type ChatCompletionStreamChoiceDelta ¶
type ChatCompletionStreamChoiceDelta struct {
Content string `json:"content,omitempty"`
Role string `json:"role,omitempty"`
FunctionCall *FunctionCall `json:"function_call,omitempty"`
}
type ChatCompletionStreamResponse ¶
type ChatCompletionStreamResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []ChatCompletionStreamChoice `json:"choices"`
PromptAnnotations []PromptAnnotation `json:"prompt_annotations,omitempty"`
}
func (*ChatCompletionStreamResponse) ToChatCompletionResponse ¶
func (r *ChatCompletionStreamResponse) ToChatCompletionResponse() ChatCompletionResponse
type ContentFilterResults ¶
type Conversation ¶
type Conversation struct {
Id string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Deleted bool `json:"deleted"`
UserId string `json:"user_id"`
Name string `json:"name"`
Model string `json:"model"`
Summary string `json:"summary"`
ExtraInfo string `json:"extra_info"`
}
type Dao ¶
type Dao interface {
SaveConversation(ctx context.Context, conversation Conversation) (Conversation, error)
GetConversation(ctx context.Context, id string) (Conversation, error)
ListConversations(ctx context.Context) ([]Conversation, error)
DeleteConversation(ctx context.Context, id string) error
SaveMessage(ctx context.Context, message Message) (Message, error)
GetMessage(ctx context.Context, id string) (Message, error)
ListMessages(ctx context.Context, conversationId string) ([]Message, error)
DeleteMessage(ctx context.Context, id string) error
GetConversationLastMessage(ctx context.Context, id string) (Message, error)
}
type FinishReason ¶
type FinishReason string
const ( FinishReasonStop FinishReason = "stop" FinishReasonLength FinishReason = "length" FinishReasonFunctionCall FinishReason = "function_call" FinishReasonContentFilter FinishReason = "content_filter" FinishReasonNull FinishReason = "null" )
func (FinishReason) MarshalJSON ¶
func (r FinishReason) MarshalJSON() ([]byte, error)
type FunctionCall ¶
type FunctionDefine
deprecated
type FunctionDefine = FunctionDefinition
Deprecated: use FunctionDefinition instead.
type FunctionDefinition ¶
type FunctionDefinition struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
// Parameters is an object describing the function.
// You can pass json.RawMessage to describe the schema,
// or you can pass in a struct which serializes to the proper JSON schema.
// The jsonschema package is provided for convenience, but you should
// consider another specialized library if you require more complex schemas.
Parameters any `json:"parameters"`
}
type LLM ¶
type LLM struct {
// contains filtered or unexported fields
}
func (*LLM) CreateConversation ¶
func (*LLM) CreateMessage ¶
func (*LLM) CreateMessageStream ¶
func (l *LLM) CreateMessageStream(ctx context.Context, conversationId string, req ChatCompletionRequest, respChan chan ChatCompletionStreamResponse, errChan chan error)
func (*LLM) DeleteConversation ¶
func (*LLM) GetConversation ¶
func (*LLM) ListConversations ¶
func (l *LLM) ListConversations(ctx context.Context) ([]Conversation, error)
type MemoryDao ¶
type MemoryDao struct {
// contains filtered or unexported fields
}
func NewMemoryDao ¶
func NewMemoryDao() *MemoryDao
func (*MemoryDao) DeleteConversation ¶
func (*MemoryDao) DeleteMessage ¶
func (*MemoryDao) GetConversation ¶
func (*MemoryDao) GetConversationLastMessage ¶
func (*MemoryDao) GetMessage ¶
func (*MemoryDao) ListConversations ¶
func (d *MemoryDao) ListConversations(ctx context.Context) ([]Conversation, error)
func (*MemoryDao) ListMessages ¶
func (*MemoryDao) SaveConversation ¶
func (d *MemoryDao) SaveConversation(ctx context.Context, conversation Conversation) (Conversation, error)
type Message ¶
type Message struct {
Id string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Deleted bool `json:"deleted"`
UserId string `json:"user_id"`
ConversationId string `json:"conversation_id"`
Model string `json:"model"`
PromptToken int `json:"prompt_token"`
CompletionToken int `json:"completion_token"`
Description string `json:"description"`
Request ChatCompletionRequest `json:"request"`
Response ChatCompletionResponse `json:"response"`
RawResponse []byte `json:"raw_response"`
}
type PromptAnnotation ¶
type PromptAnnotation struct {
PromptIndex int `json:"prompt_index,omitempty"`
ContentFilterResults ContentFilterResults `json:"content_filter_results,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.