chatgpt

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package chatgpt provides a client for the OpenAI chat GPT API.

Index

Constants

View Source
const (
	ModelGPT3Dot5Turbo = openai.GPT3Dot5Turbo
	ModelGPT4          = openai.GPT4
	ModelGPT4Turbo     = openai.GPT4Turbo
	ModelGPT4o         = openai.GPT4o // default
	ModelGPT4oMini     = openai.GPT4oMini
	ModelO1Mini        = openai.O1Mini
	ModelO1Preview     = openai.O1Preview

	DefaultModel = ModelGPT4o
)

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

func (c *Client) ListModelNames(ctx context.Context) ([]string, error)

ListModelNames lists all available model names.

func (*Client) ModifyInitialRole added in v1.13.0

func (c *Client) ModifyInitialRole(roleDesc string)

ModifyInitialRole modifies the initial role description.

func (*Client) RefreshContext

func (c *Client) RefreshContext()

RefreshContext refreshes assistant context

func (*Client) Send

func (c *Client) Send(ctx context.Context, prompt string, files ...string) (string, error)

Send sends a prompt to the chat gpt and returns the response.

func (*Client) SendStream

func (c *Client) SendStream(ctx context.Context, prompt string, files ...string) *aicli.StreamReply

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 WithModel

func WithModel(name string) ClientOption

WithModel sets the model name

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

Jump to

Keyboard shortcuts

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