Documentation
¶
Index ¶
- Constants
- Variables
- func NewApp(r *Repository) *cli.App
- func NewSimpleTableWriter(out io.Writer) table.Writer
- func Run(args []string) error
- type Cache
- type CacheItemNotFoundError
- type CacheManager
- type ChatService
- type Config
- type Conversation
- type ConversationInvalidNameError
- type ConversationKey
- type ConversationList
- type ConversationNameDuplicatedError
- type ConversationNotFoundError
- type HomeDirNotFoundError
- type Hook
- type HookFactory
- type ListConversationsQuery
- type OutputWriter
- type PathResolver
- type Repository
- type SimpleTableWriter
- type Store
- func (s *Store) Close() error
- func (s *Store) CreateConversation(co *Conversation) error
- func (s *Store) DeleteConversationById(id uint64) error
- func (s *Store) GetConversationById(id uint64) (*Conversation, error)
- func (s *Store) GetConversationByKey(key *ConversationKey) (*Conversation, error)
- func (s *Store) GetConversationByName(name string) (*Conversation, error)
- func (s *Store) Init() error
- func (s *Store) ListConversations(query *ListConversationsQuery) (*ConversationList, error)
- func (s *Store) RenameConversationByKey(key *ConversationKey, name string) error
- func (s *Store) UpdateConversation(co *Conversation) error
- type StoreManager
Constants ¶
View Source
const ( CacheBucketCaches = "caches" CacheBucketOrder = "order" )
View Source
const ( HookTypePreMessage = "pre-message" HookTypePostMessage = "post-message" HookTypeFinish = "finish" )
View Source
const ( BucketConversations = "conversations" BucketNameIndex = "names" )
View Source
const AppHomeEnvKey = "GPTX_HOME"
Variables ¶
View Source
var ( // Version is the version of this software. // This value is overwritten by the build script. Version = "0.0.0" // CommitHash is the git commit hash of this software. // This value is overwritten by the build script. CommitHash = "unknown" )
View Source
var ChatCommand = &cli.Command{ Name: "chat", Aliases: []string{"c"}, Usage: "Chat with GPT", ArgsUsage: "[prompt...]", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "no-loading", Usage: "Disable loading animation", DisableDefaultText: true, }, &cli.BoolFlag{ Name: "no-animation", Usage: "Disable typing animation", DisableDefaultText: true, }, &cli.StringFlag{ Name: "name", Aliases: []string{"n"}, Usage: "Specify a `name` for the conversation", }, &cli.StringFlag{ Name: "label", Aliases: []string{"l"}, Usage: "Specify a `label` for the conversation", }, &cli.StringFlag{ Name: "resume", Aliases: []string{"r"}, Usage: "Resume a `conversation`. You can specify a conversation id or name", }, &cli.BoolFlag{ Name: "editor", Aliases: []string{"e"}, Usage: "Open $EDITOR to make a prompt.", DisableDefaultText: true, }, &cli.StringFlag{ Name: "model", Usage: "Specify a `model` working with ChatGPT", }, &cli.Float64Flag{ Name: "temperature", Usage: "Specify a temperature", Value: 1, }, &cli.Float64Flag{ Name: "top-p", Usage: "Specify a top_p", Value: 1, }, &cli.StringSliceFlag{ Name: "hook", Aliases: []string{"H"}, Usage: "Specify a `hook`s", }, &cli.StringSliceFlag{ Name: "env", Aliases: []string{"E"}, Usage: "Specify a environment variable for hooks. For example: -E FOO=BAR -E BAZ=QUX", }, &cli.BoolFlag{ Name: "interactive", Aliases: []string{"i"}, Usage: "Run in interactive mode", DisableDefaultText: true, }, &cli.BoolFlag{ Name: "no-cache", Usage: "Disable cache", DisableDefaultText: true, }, &cli.BoolFlag{ Name: "on-memory", Aliases: []string{"m"}, Usage: "Disable the ability to save or load the conversation to and from the disk, which also includes the behavior of the --no-cache option.", DisableDefaultText: true, }, }, Action: chatAction, }
View Source
var CleanCommand = &cli.Command{
Name: "clean",
Usage: "Clean up the cache",
Action: cleanAction,
}
View Source
var ConfigCommand = &cli.Command{ Name: "config", Usage: "Display configuration", Flags: []cli.Flag{ &cli.BoolFlag{ Name: "pretty", Aliases: []string{"p"}, Usage: "Pretty print", DisableDefaultText: true, }, }, Action: configAction, }
View Source
var DeleteCommand = &cli.Command{ Name: "remove", Aliases: []string{"rm"}, Usage: "Remove one or more conversations", ArgsUsage: `[conversation_id...]`, Action: deleteAction, }
View Source
var InitCommand = &cli.Command{ Name: "init", Usage: "Init a gptx home directory", Flags: []cli.Flag{ &cli.StringFlag{ Name: "directory", Aliases: []string{"d"}, Usage: "Specify a `directory` to init", }, }, Action: initAction, }
View Source
var InspectCommand = &cli.Command{ Name: "inspect", Aliases: []string{"i"}, Usage: "Display details information on one or more conversations", ArgsUsage: `[conversation...]`, Flags: []cli.Flag{ &cli.BoolFlag{ Name: "pretty", Aliases: []string{"p"}, Usage: "Pretty print", DisableDefaultText: true, }, }, Action: inspectAction, }
View Source
var ListCommand = &cli.Command{ Name: "list", Aliases: []string{"ls"}, Usage: "List conversations", Flags: []cli.Flag{ &cli.StringFlag{ Name: "begin", Aliases: []string{"b"}, Usage: "Load the conversations starting from the given conversation `id`", }, &cli.BoolFlag{ Name: "reverse", Aliases: []string{"r"}, Usage: "Sort the conversations in descending id order", DisableDefaultText: true, }, &cli.IntFlag{ Name: "limit", Aliases: []string{"L"}, Usage: "Limit the `number` of displayed conversations", DefaultText: "0 (no limit)", }, &cli.StringFlag{ Name: "label", Aliases: []string{"l"}, Usage: "Filter the conversations by `label`", }, &cli.BoolFlag{ Name: "quiet", Aliases: []string{"q"}, Usage: "Only display the conversation ids", DisableDefaultText: true, }, }, Action: listAction, }
View Source
var RenameCommand = &cli.Command{
Name: "rename",
Usage: "Rename a conversation",
ArgsUsage: `[conversation] [new name]`,
Action: renameAction,
}
View Source
var VersionCommand = &cli.Command{
Name: "version",
Usage: "Print the version information",
Action: versionAction,
}
Functions ¶
func NewApp ¶
func NewApp(r *Repository) *cli.App
Types ¶
type CacheItemNotFoundError ¶
type CacheItemNotFoundError struct { // Key is sha256 hash Key []byte }
CacheItemNotFoundError is an error that is returned when the cache is not found.
func (*CacheItemNotFoundError) Error ¶
func (e *CacheItemNotFoundError) Error() string
Error returns the error message.
type CacheManager ¶
func (*CacheManager) Close ¶
func (m *CacheManager) Close() error
func (*CacheManager) Open ¶
func (m *CacheManager) Open() (*Cache, error)
func (*CacheManager) Refresh ¶
func (m *CacheManager) Refresh() error
type ChatService ¶
type ChatService struct { ClientConfig openai.ClientConfig PathResolver *PathResolver StoreManager *StoreManager CacheManager *CacheManager HookFactory *HookFactory Writer *OutputWriter Spinner *spinner.Spinner Conversation *Conversation Hooks []*Hook NoLoading bool NoCache bool OnMemory bool Model string Temperature float32 TopP float32 HooksEnv []string }
func (*ChatService) Chat ¶
func (c *ChatService) Chat(prompt string) error
func (*ChatService) DisableOutputAnimation ¶
func (c *ChatService) DisableOutputAnimation()
func (*ChatService) InitConversation ¶
func (c *ChatService) InitConversation(resume string, name string, label string) error
InitConversation resolves the conversation to use. If "resume" is specified, it loads the conversation from the store.
func (*ChatService) LoadHooks ¶
func (c *ChatService) LoadHooks(hookNames []string) error
type Config ¶
type Config struct { OpenAIAPIKey string `toml:"openai_api_key"` // OpenAI API Key Model string `toml:"model"` // Default setting for https://platform.openai.com/docs/api-reference/chat/create#chat/create-model MaxCacheLength int `toml:"max_cache_length"` // The maximum number of cached responses. // contains filtered or unexported fields }
func (*Config) LoadFromFile ¶
func (*Config) MarshalJSON ¶
type Conversation ¶
type Conversation struct { Id uint64 `json:"id"` // Conversation ID Prompt string `json:"prompt"` // The initial input text that starts the conversation Name string `json:"name,omitempty"` // The unique name of the conversation Label string `json:"label,omitempty"` // A label for categorizing the conversation CreatedAt time.Time `json:"created_at"` // When the conversation was created Messages []openai.ChatCompletionMessage `json:"messages"` // Messages in the conversation Hooks []string `json:"hooks,omitempty"` // Registered Hooks for the conversation }
func NewConversation ¶
func NewConversation() *Conversation
func (*Conversation) AddMessage ¶
func (c *Conversation) AddMessage(msg openai.ChatCompletionMessage)
func (*Conversation) IsNew ¶
func (c *Conversation) IsNew() bool
type ConversationInvalidNameError ¶
type ConversationInvalidNameError struct {
Name string
}
func (*ConversationInvalidNameError) Error ¶
func (e *ConversationInvalidNameError) Error() string
type ConversationKey ¶
func NewConversationKey ¶
func NewConversationKey(value string) *ConversationKey
type ConversationList ¶
type ConversationList struct { Conversations []*Conversation `json:"conversations"` HasNext bool `json:"has_next"` Next *uint64 `json:"next,string,omitempty"` Count int `json:"count"` // contains filtered or unexported fields }
func (*ConversationList) IsLimitReached ¶
func (l *ConversationList) IsLimitReached() bool
func (*ConversationList) TryAppendConversation ¶
func (l *ConversationList) TryAppendConversation(c *Conversation)
type ConversationNameDuplicatedError ¶
func (*ConversationNameDuplicatedError) Error ¶
func (e *ConversationNameDuplicatedError) Error() string
type ConversationNotFoundError ¶
type ConversationNotFoundError struct {
Key interface{}
}
func (*ConversationNotFoundError) Error ¶
func (e *ConversationNotFoundError) Error() string
type HomeDirNotFoundError ¶
type HomeDirNotFoundError struct {
Dir string
}
func (*HomeDirNotFoundError) Error ¶
func (e *HomeDirNotFoundError) Error() string
type HookFactory ¶
type HookFactory struct{}
type ListConversationsQuery ¶
type OutputWriter ¶
type OutputWriter struct { Writer io.Writer UseAnimation bool AnimationSpeed time.Duration Color *color.Color }
OutputWriter is an io.Writer wrapper that enables printing text with a typewriter-style animation.
func (*OutputWriter) Println ¶
func (w *OutputWriter) Println(text string)
type PathResolver ¶
type PathResolver struct { Dir string // contains filtered or unexported fields }
func NewPathResolver ¶
func NewPathResolver(dir string) *PathResolver
func (*PathResolver) CacheDBFilePath ¶
func (r *PathResolver) CacheDBFilePath() string
func (*PathResolver) ConfigFilePath ¶
func (r *PathResolver) ConfigFilePath() string
func (*PathResolver) DBFilePath ¶
func (r *PathResolver) DBFilePath() string
func (*PathResolver) HistoryFilePath ¶
func (r *PathResolver) HistoryFilePath() string
func (*PathResolver) LibExecDir ¶
func (r *PathResolver) LibExecDir() string
func (*PathResolver) LibExecFilePath ¶
func (r *PathResolver) LibExecFilePath(name string) string
type Repository ¶
type Repository struct { PathResolver *PathResolver Config *Config ClientConfig openai.ClientConfig CacheManager *CacheManager StoreManager *StoreManager // contains filtered or unexported fields }
Repository holds the application context data.
func NewRepository ¶
func NewRepository(pr *PathResolver) *Repository
func (*Repository) Close ¶
func (r *Repository) Close() error
func (*Repository) Init ¶
func (r *Repository) Init() error
func (*Repository) NewChatService ¶
func (r *Repository) NewChatService(w io.Writer) (*ChatService, error)
type SimpleTableWriter ¶
SimpleTableWriter is a simple table Writer that does not draw borders.
func (*SimpleTableWriter) Render ¶
func (t *SimpleTableWriter) Render() string
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) CreateConversation ¶
func (s *Store) CreateConversation(co *Conversation) error
func (*Store) DeleteConversationById ¶
func (*Store) GetConversationById ¶
func (s *Store) GetConversationById(id uint64) (*Conversation, error)
func (*Store) GetConversationByKey ¶
func (s *Store) GetConversationByKey(key *ConversationKey) (*Conversation, error)
func (*Store) GetConversationByName ¶
func (s *Store) GetConversationByName(name string) (*Conversation, error)
func (*Store) ListConversations ¶
func (s *Store) ListConversations(query *ListConversationsQuery) (*ConversationList, error)
func (*Store) RenameConversationByKey ¶
func (s *Store) RenameConversationByKey(key *ConversationKey, name string) error
func (*Store) UpdateConversation ¶
func (s *Store) UpdateConversation(co *Conversation) error
type StoreManager ¶
type StoreManager struct { DBPath string // contains filtered or unexported fields }
func (*StoreManager) Close ¶
func (m *StoreManager) Close() error
func (*StoreManager) Open ¶
func (m *StoreManager) Open() (*Store, error)
Source Files
¶
- app.go
- bytesutil.go
- cache.go
- chat.go
- chatcommand.go
- cleancommand.go
- config.go
- configcommand.go
- conversation.go
- customsubcommands.go
- editor.go
- hook.go
- initcommand.go
- inspectcommand.go
- listcommand.go
- path.go
- removecommand.go
- renamecommand.go
- repository.go
- store.go
- table.go
- utils.go
- version.go
- versioncommand.go
- writer.go
Click to show internal directories.
Click to hide internal directories.