Documentation ¶
Overview ¶
Package chatgo is a chatbot based on openai api
Index ¶
- Constants
- type ChatRequest
- type ChatResponse
- type ChatStreamResponse
- type Robot
- func (r *Robot) GetModel() string
- func (r *Robot) Init()
- func (r *Robot) Name() string
- func (r *Robot) Replay()
- func (r *Robot) Save(path string) error
- func (r *Robot) SetMessagesFromFile(path string) *Robot
- func (r *Robot) SetModel(model string) *Robot
- func (r *Robot) SetName(name string) *Robot
- func (r *Robot) SetToken(token string) *Robot
- func (r *Robot) Tell(sentence string) []string
- func (r *Robot) TellStream(sentence string) (<-chan string, error)
Constants ¶
View Source
const ( // RoleAssistant is the assistant role RoleAssistant = "assistant" // RoleUser is the user role RoleUser = "user" // RoleSystem is the system role RoleSystem = "system" )
View Source
const HistoryPath = "~/.chatgo/%s.%s.history"
HistoryPath is the path of history
View Source
const TokenPath = "~/.chatgo/token"
TokenPath is the path of token
View Source
const Version = "v0.2.0-alpha"
Version is the version of chatgo
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatRequest ¶
type ChatRequest struct { Token string `json:"token"` Model string `json:"model"` Role string `json:"role"` Content string `json:"content"` }
ChatRequest is the request body for chatgpt
type ChatResponse ¶
type ChatResponse struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` Model string `json:"model"` Usage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` } `json:"usage"` Choices []struct { Message struct { Role string `json:"role"` Content string `json:"content"` } `json:"message"` FinishReason string `json:"finish_reason"` Index int `json:"index"` } `json:"choices"` }
ChatResponse is the response body for chatgpt
type ChatStreamResponse ¶
type ChatStreamResponse struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` Model string `json:"model"` Choices []struct { Delta struct { Role string `json:"role"` Content string `json:"content"` } `json:"delta"` Index int `json:"index"` FinishReason any `json:"finish_reason"` } `json:"choices"` }
ChatStreamResponse is the response body for chatgpt stream
type Robot ¶
type Robot struct { CreateAt time.Time `json:"create_at"` // contains filtered or unexported fields }
Robot is a chatgpt robot
func (*Robot) SetMessagesFromFile ¶
SetMessagesFromFile sets the robot messages
Click to show internal directories.
Click to hide internal directories.