Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultCachePath = cmp.Or(os.Getenv("HOME"), os.Getenv("USERPROFILE")) + "/.openai-cli-chat-pebble-storage-cache"
DefaultCachePath defines the default location for the chat session cache, which is used to store conversation history as a pebble-backed database.
On Unix-like systems, it is set to ~/.openai-cli-chat-cache, and on Windows, it is set to %USERPROFILE%/.openai-cli-chat-cache, which are the common locations for user-specific configuration files.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct { // Name of the command. // // If Matches is nil, the command is executed when the input matches the name. Name string // Description of the command. Description string // Matches is a function that checks if the command matches the input. // // If Matches is nil, the command is executed when the input matches the name. // If Matches is not nil, the command is executed when Matches returns true. Matches func(input string) bool // Run is the function that executes the command. Run CommandFunc }
Command represents an abstract command with a name, a matching function, and an execution function.
type CommandFunc ¶
CommandFunc defines the function signature for executing a command.
type ReqRespPair ¶
type ReqRespPair struct { Model string `json:"model,omitzero"` Req openai.ChatCompletionMessage `json:"req,omitzero"` ReqTokens int64 `json:"req_tokens,omitzero"` Resp openai.ChatCompletionMessage `json:"resp,omitzero"` RespTokens int64 `json:"resp_tokens,omitzero"` EmbeddingModel string `json:"embedding_model,omitzero"` Embeddings [][]float64 `json:"embedding,omitzero"` }
ReqRespPair represents a request-response pair in the chat session, used for storing conversation history in the backend.
type Session ¶
type Session struct { Client *openai.Client ChatModel string EmbeddingModel string StorageBackend storage.Backend[string, ReqRespPair] Messages []openai.ChatCompletionMessage CurrentTokensUsed int64 SummarizeContextWindowSize int64 Terminal *term.Terminal OutWriter *bufio.Writer TermWidth int TermHeight int Commands []Command }
Session encapsulates the state and behavior of a CLI chat session. It manages terminal I/O, conversation history, caching, and command processing.
func NewSession ¶
func NewSession(ctx context.Context, client *openai.Client, chatModel, embeddingModel string, r io.Reader, w io.Writer, b storage.Backend[string, ReqRespPair]) (*Session, func(), error)
NewSession creates and initializes a new chat session.
It sets the terminal to raw mode, loads any existing chat history, and registers the default commands.
A restoration function is returned to restore the terminal state on exit.