Documentation
¶
Overview ¶
Package chatgpt provides a client for the OpenAI chat GPT API.
Index ¶
- Constants
- type Client
- func (c *Client) ListContextMessages() []*ContextMessage
- func (c *Client) ListModelNames(ctx context.Context) ([]string, error)
- func (c *Client) ModifyInitialRole(roleDesc string)
- func (c *Client) RefreshContext()
- func (c *Client) Send(ctx context.Context, prompt string, files ...string) (string, error)
- func (c *Client) SendStream(ctx context.Context, prompt string, files ...string) *aicli.StreamReply
- type ClientOption
- func WithEnableContext() ClientOption
- func WithInitialContextMessages(messages ...*ContextMessage) ClientOption
- func WithInitialRole(roleDesc string) ClientOption
- func WithMaxTokens(maxTokens int) ClientOption
- func WithModel(name string) ClientOption
- func WithTemperature(temperature float32) ClientOption
- type ContextMessage
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
ModelName string
Cli *openai.Client
// contains filtered or unexported fields
}
Client is a chat GPT client.
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) (*Client, error)
NewClient creates a new chat client.
func (*Client) ListContextMessages ¶ added in v1.13.0
func (c *Client) ListContextMessages() []*ContextMessage
ListContextMessages list assistant context messages
func (*Client) ListModelNames ¶
ListModelNames lists all available model names.
func (*Client) ModifyInitialRole ¶ added in v1.13.0
ModifyInitialRole modifies the initial role description.
func (*Client) RefreshContext ¶
func (c *Client) RefreshContext()
RefreshContext refreshes assistant context
func (*Client) SendStream ¶
SendStream sends a prompt to the chat gpt and returns a channel of responses.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a function that sets a Client option.
func WithEnableContext ¶ added in v1.13.0
func WithEnableContext() ClientOption
WithEnableContext sets assistant context
func WithInitialContextMessages ¶ added in v1.13.0
func WithInitialContextMessages(messages ...*ContextMessage) ClientOption
WithInitialContextMessages sets initial context messages, automatically set enableContext to true
func WithInitialRole ¶ added in v1.13.0
func WithInitialRole(roleDesc string) ClientOption
WithInitialRole sets the initial role type
func WithMaxTokens ¶
func WithMaxTokens(maxTokens int) ClientOption
WithMaxTokens sets the maximum number of tokens
func WithTemperature ¶
func WithTemperature(temperature float32) ClientOption
WithTemperature sets the temperature
type ContextMessage ¶ added in v1.13.0
type ContextMessage struct {
Role string `json:"role"` // system, user, assistant, etc.
Content string `json:"content"`
}
ContextMessage chat history message