Documentation ¶
Index ¶
- Constants
- Variables
- func Ask(args []string) int
- func BotField(args []string) int
- func Card(args []string) int
- func Chat() int
- func Commit() int
- func CreateAuditLog() (*os.File, error)
- func MessageFromFile(path string) (message string, tokenLen int, err error)
- func MessageToFile(content string, path string) error
- func TLDR(args []string) int
- type ChatGPTClient
- func (c *ChatGPTClient) Ask(question string) (answer string, err error)
- func (c *ChatGPTClient) Card(path string) (cards []string, err error)
- func (c *ChatGPTClient) Chat()
- func (c *ChatGPTClient) Chunk(contents io.Reader, chunkSize int) []string
- func (c *ChatGPTClient) Commit() (summary string, err error)
- func (c *ChatGPTClient) CreateEmbeddings(origin string, contents io.Reader)
- func (c *ChatGPTClient) Fprint(a ...interface{})
- func (c *ChatGPTClient) GetCompletion(opts ...CompletionOption) (string, error)
- func (c *ChatGPTClient) GetContent(path string) (msg string, err error)
- func (c *ChatGPTClient) GetStrategy(input string) Strategy
- func (c *ChatGPTClient) Log(role string, message string)
- func (c *ChatGPTClient) LogErr(err error)
- func (c *ChatGPTClient) LogOut(message ...any)
- func (c *ChatGPTClient) MessageFromFiles(path string) (string, error)
- func (c *ChatGPTClient) Prompt(prompts ...string)
- func (c *ChatGPTClient) RecordMessage(role string, message string)
- func (c *ChatGPTClient) Relevant(query string) (Similarities, error)
- func (c *ChatGPTClient) RollbackLastMessage() []ChatMessage
- func (c *ChatGPTClient) SetPurpose(prompt string)
- func (c *ChatGPTClient) TLDR(path string) (summary string, err error)
- func (c *ChatGPTClient) TranscriptPath() string
- func (c *ChatGPTClient) Vectorize(origin string, s []string) ([]Embedding, error)
- type ChatMessage
- type ClientOption
- type CompletionOption
- type Default
- type Embedding
- type Exit
- type FileLoad
- type FileWrite
- type Similarities
- type Similarity
- type Strategy
Constants ¶
const ( RoleUser = "user" RoleBot = "assistant" RoleSystem = "system" )
Role constants that represent the role of the message sender
const (
QuestionPrompt = `` /* 657-byte string literal not displayed */
)
Variables ¶
var NewChatGPTClient = DefaultGPTClient
Functions ¶
func Ask ¶
Ask sends a question to the GPT-4 API, aiming to receive a relevant and informed answer. It facilitates user interaction with GPT-4 for knowledge retrieval or problem-solving.
func Card ¶
Card generates a set of flashcards from a given file or URL, aiming to enhance learning by summarizing important concepts. It uses GPT-4 for extracting key information in a compact and easy-to-review format.
func Chat ¶
func Chat() int
Chat function initiates the chat with the user and enables interaction between user and the chat proxy. It orchestrates the entire conversational experience with the purpose of assisting the user in various tasks.
func Commit ¶
func Commit() int
Commit analyzes staged Git files, parsing the diff, and generates a meaningful commit message. It aims to streamline the process of creating accurate and informative commit descriptions for better version control.
func CreateAuditLog ¶
CreateAuditLog creates a new file for recording the conversation's audit log with a timestamped filename. This function helps ensure conversation logs are saved and timestamped, allowing the users to review their chat history later.
func MessageFromFile ¶
MessageFromFile reads the contents of a file, and returns a formatted message with the file name and content, as well as an estimation of the token count. This function enables the bot to include file contents when sending messages to the user.
func MessageToFile ¶
MessageToFile writes the given content string to a file with the specified path. This function enables the bot to save conversation logs in a file or write user-generated content to a file.
Types ¶
type ChatGPTClient ¶
type ChatGPTClient struct {
// contains filtered or unexported fields
}
ChatGPTClient manages interactions with a GPT-based chatbot, providing a way to organize the conversation, handle input/output, and maintain an audit trail.
func DefaultGPTClient ¶
func DefaultGPTClient(opts ...ClientOption) (*ChatGPTClient, error)
NewChatGPTClient initializes the ChatGPTClient with the desired options, allowing customization through functional options so the client can be tailored to specific needs or requirements.
func (*ChatGPTClient) Ask ¶
func (c *ChatGPTClient) Ask(question string) (answer string, err error)
Ask sends a user question to the GPT-4 API, and expects an informed response. This method is part of the ChatGPTClient and allows users to leverage the GPT-4 model for answering queries.
func (*ChatGPTClient) Card ¶
func (c *ChatGPTClient) Card(path string) (cards []string, err error)
Card creates flashcards using the content from a given file or URL. This method, part of the ChatGPTClient, uses the GPT-4 API to break down and condense information into manageable flashcards.
func (*ChatGPTClient) Chat ¶
func (c *ChatGPTClient) Chat()
Chat method handles the conversational flow for the ChatGPTClient, aiming to provide a seamless user experience by managing prompts and strategies.
func (*ChatGPTClient) Chunk ¶
func (c *ChatGPTClient) Chunk(contents io.Reader, chunkSize int) []string
func (*ChatGPTClient) Commit ¶
func (c *ChatGPTClient) Commit() (summary string, err error)
Commit parses the diff of staged Git files and generates an appropriate commit message. This method, part of the ChatGPTClient, helps users maintain clear commit history and conveys changes in a concise and descriptive manner.
func (*ChatGPTClient) CreateEmbeddings ¶
func (c *ChatGPTClient) CreateEmbeddings(origin string, contents io.Reader)
func (*ChatGPTClient) Fprint ¶
func (c *ChatGPTClient) Fprint(a ...interface{})
func (*ChatGPTClient) GetCompletion ¶
func (c *ChatGPTClient) GetCompletion(opts ...CompletionOption) (string, error)
GetCompletion retrieves a response from the chatbot based on the conversation history and any additional options applied.
func (*ChatGPTClient) GetContent ¶
func (c *ChatGPTClient) GetContent(path string) (msg string, err error)
GetContent takes a path, checks if it is a file or URL, and returns the contents of the file or the text of the URL.
func (*ChatGPTClient) GetStrategy ¶
func (c *ChatGPTClient) GetStrategy(input string) Strategy
GetStrategy method selects the appropriate strategy based on the user input, ensuring the correct action is taken to achieve the user's desired outcome.
func (*ChatGPTClient) Log ¶
func (c *ChatGPTClient) Log(role string, message string)
Log logs a chat message with the given role and message. It helps maintain a comprehensive log of interactions in the ChatGPTClient. The primary purpose of this function is to clearly show which role (e.g., user, bot, system) is responsible for a particular message in the conversation.
func (*ChatGPTClient) LogErr ¶
func (c *ChatGPTClient) LogErr(err error)
LogErr logs errors in the ChatGPTClient's errorStream. This makes it possible to capture and handle errors in a standardized manner, enabling efficient debugging and error handling.
func (*ChatGPTClient) LogOut ¶
func (c *ChatGPTClient) LogOut(message ...any)
LogOut logs a message to the ChatGPTClient's output stream. This is useful for logging messages that are not part of the conversation, such as instructions or system status updates.
func (*ChatGPTClient) MessageFromFiles ¶
func (c *ChatGPTClient) MessageFromFiles(path string) (string, error)
MessageFromFiles reads the contents of multiple files in a directory, and returns a combined formatted message with file names and contents. This function allows the bot to send messages with content from multiple files at once to the user without making multiple calls.
func (*ChatGPTClient) Prompt ¶
func (c *ChatGPTClient) Prompt(prompts ...string)
Prompt formats and prints system prompts to the output. It uses yellow color to differentiate system messages from user and bot messages for better visibility. The main purpose of this function is to guide user interactions and ensure clear communication of instructions or system status updates.
func (*ChatGPTClient) RecordMessage ¶
func (c *ChatGPTClient) RecordMessage(role string, message string)
RecordMessage adds a new message in the conversation context, allowing the chatbot to maintain a conversation context. The role parameter provides a mechanism for inserting bot or system responses in addition to user messages.
func (*ChatGPTClient) Relevant ¶
func (c *ChatGPTClient) Relevant(query string) (Similarities, error)
func (*ChatGPTClient) RollbackLastMessage ¶
func (c *ChatGPTClient) RollbackLastMessage() []ChatMessage
RollbackLastMessage serves as an undo functionality, removing the last message from the conversation, and providing a way to recover from erroneous input or chatbot responses.
func (*ChatGPTClient) SetPurpose ¶
func (c *ChatGPTClient) SetPurpose(prompt string)
SetPurpose defines the purpose of the conversation, providing contextual guidance for the chatbot to follow, and aligning the conversation towards a specific topic or goal.
func (*ChatGPTClient) TLDR ¶
func (c *ChatGPTClient) TLDR(path string) (summary string, err error)
TLDR generates a brief summary of the content from a file or URL. This method is part of the ChatGPTClient and leverages the GPT-4 API to present an abstract of the main text, providing a quick overview.
func (*ChatGPTClient) TranscriptPath ¶
func (c *ChatGPTClient) TranscriptPath() string
type ChatMessage ¶
ChatMessage represents a message in the chat, providing context and a way to model conversation between different participant roles (e.g., user, bot, system).
type ClientOption ¶
type ClientOption func(*ChatGPTClient) *ChatGPTClient
ClientOption is used to flexibly configure the ChatGPTClient to meet various requirements and use cases, such as custom input/output handling or error reporting.
func WithFixedResponse ¶
func WithFixedResponse(response string) ClientOption
WithFixedResponse configures the ChatGPTClient to return a predetermined response, offering quicker or consistent replies, or simulating specific behavior for test cases.
func WithInput ¶
func WithInput(input io.Reader) ClientOption
WithInput assigns a custom input reader for ChatGPTClient, allowing the client to read input from any source, offering improved flexibility and adaptability.
func WithOutput ¶
func WithOutput(output, err io.Writer) ClientOption
WithOutput allows customizing the output/error handling in the ChatGPTClient, making the client more adaptable to different environments or reporting workflows.
func WithStreaming ¶
func WithStreaming(streaming bool) ClientOption
WithStreaming controls the streaming mode of the ChatGPTClient, giving the user the choice between streamed responses for real-time interactions or buffered responses for complete replies.
func WithToken ¶
func WithToken(token string) ClientOption
WithToken uses the provided token for authentication when creating a new ChatGPTClient.
func WithTranscript ¶
func WithTranscript(audit io.Writer) ClientOption
WithTranscript enables keeping a log of all conversation messages, ensuring a persistent record that can be useful for auditing, debugging, or further analysis.
type CompletionOption ¶
type CompletionOption func(*openai.ChatCompletionRequest) *openai.ChatCompletionRequest
CompletionOption is used to customize the behavior of the openai.ChatCompletionRequest to suit different use cases, such as setting stop words or modifying token limits.
func WithFixedResponseAPIValidate ¶
func WithFixedResponseAPIValidate(response string) CompletionOption
WithFixedResponseAPIValidate still makes an API call (ensuring request and token length validation) but enforces a specific response from the chatbot, ensuring a known output and avoiding unpredictable or unnecessary responses during validation.
type Default ¶
type Default struct {
// contains filtered or unexported fields
}
func (Default) Execute ¶
func (s Default) Execute(c *ChatGPTClient) error
Execute method for Default strategy is responsible for managing a typical chat interaction by sending user input to the OpenAI API and receiving a response.
type Exit ¶
type Exit struct{}
func (Exit) Execute ¶
func (s Exit) Execute(c *ChatGPTClient) error
Execute method for Exit strategy gracefully manages the termination of the chat session when the user decides to exit.
type FileLoad ¶
type FileLoad struct {
// contains filtered or unexported fields
}
func (FileLoad) Execute ¶
func (s FileLoad) Execute(c *ChatGPTClient) error
Execute method for FileLoad strategy handles loading file contents to be processed by ChatGPTClient, which enables users to provide input via files instead of just through the chat interface.
type FileWrite ¶
type FileWrite struct {
// contains filtered or unexported fields
}
func (FileWrite) Execute ¶
func (s FileWrite) Execute(c *ChatGPTClient) error
Execute method for FileWrite strategy allows writing output from the chat interaction to a file, offering an organized and convenient way to store results.
type Similarities ¶
type Similarities struct { Query string RelevantVectors []Similarity }
func (Similarities) Top ¶
func (s Similarities) Top(n int) []string
type Similarity ¶
type Strategy ¶
type Strategy interface {
Execute(*ChatGPTClient) error
}