oax

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2023 License: MIT Imports: 15 Imported by: 0

README

oax(OpenAI eXecutor)

💥 CLI for OpenAI's ChatGPT.

For basic use cases. gif

Resuming chat sessions from a previous point. gif

Installation

brew tap shuntaka9576/tap
brew install shuntaka9576/tap/oax

Requirements

Command-line text editor tools (Vim/Neovim/Nano, etc.).

Quick Start

Open profile (~/.config/oax/profiles.toml).

oax config --profiles

Specify the OpenAI API API key in the apiKey field (replace sk-xxxx).

[[profiles]]
name = "personal"
apiKey = "sk-xxxx" # <--
default = true

Open setting (~/.config/oax/settings.toml).

oax config --settings

Specify edit to lunch editor. vim or nvim.

[setting]
  editor = "vim" # <--

Start ChatGPT. Default model gpt-3.5-turbo. Open ChatGPT request file (~/.config/oax/chat-log/2006-01-02_15-04-05.toml).

oax chat

Specify sent content to ChatGPT. exit with wq.

[[messages]]
  role = "user"
  content = '''
# Remove this comment and specify content to send to OpenAI API; otherwise, nothing is sent.
'''

Streaming response is returned from ChatGPT.

$ oax chat
Hello! How can I assist you today?

continue (y/n)?: n
saved: ~/.config/oax/chat-log/2023-03-26_17-01-54.toml

When resuming, you can perform fuzzy search on chat history files by their titles.

oax chat -c

Files can be resumed from the middle of the process by specifying the full path of the file.

oax chat -m "gpt-3.5-turbo" -f "~/.config/oax/chat-log/2023-03-26_15-11-04.toml"

Configuration

File Path Description Open Command
~/.config/oax/settings.toml Specify command assist information for oax. oax config --settings
~/.config/oax/profiles.toml Specify information required for API connection. oax config --profiles
Settings
setting
Option Description Required Default
editor Integrated editor true vim
chatLogDir Directory for saving chat logs false ~/.config/oax/chat-log

e.g.

[setting]
  editor = "nvim"
  chatLogDir = "~/.config/oax/chat-log"
chat
Option Description Required Default
model ChatGPT model false gpt-3.5-turbo
fileNameFormat Providing ${title} placeholder false %Y-%m-%d_%H-%M-%S
chat.templates Chat template false
[chat]
  model = "gpt-3.5-turbo"
  fileNameFormat = "%Y-%m-%d_%H-%M-%S"

  [[chat.templates]]
    name = "friends"

    [[chat.templates.messages]]
      role = "system"
      content = "You are ChatGPT, a large language model trained by OpenAI. You are a friendly assistant that can provide help, advice, and engage in casual conversations."

Specify a model.

oax chat -m "gpt-4"

Specify a chat template

oax chat -t "friends"
Profiles
Option Description Required Default
name Profile name true vim
apiKey OpenAI API key true ~/.config/oax/chat-log
default Set the default profile configuration (API key) to be used. false. Please ensure that the "default" option is set for at least one Profile. true
organizationId OpenAI Organization ID false

e.g.

[[profiles]]
  name = "me"
  apiKey= "sk-xxxx"
  default = true

[[profiles]]
  name = "org"
  organizationId = ""

Troubleshooting

Reset
rm -rf ~/.config/oax

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmdConfig

func CmdConfig(editor string, setting bool, profile bool) error

Types

type CMDEditor

type CMDEditor struct {
	// contains filtered or unexported fields
}

func (CMDEditor) Open

func (ce CMDEditor) Open(filePath string) error

type Chat

type Chat struct {
	Model          string         `toml:"model"`
	Templates      []ChatTemplate `toml:"templates"`
	FileNameFormat string         `toml:"fileNameFormat"`
}

type ChatLog

type ChatLog struct {
	ConfigDir   string
	ChatLogToml ChatLogToml
	FilePath    *string
}

func (*ChatLog) AddChatMessage

func (c *ChatLog) AddChatMessage(chatMessage ChatMessage) *ChatLog

func (*ChatLog) CreateOpenAIMessages

func (c *ChatLog) CreateOpenAIMessages() (messages []openai.Message)

func (*ChatLog) DeleteFile

func (c *ChatLog) DeleteFile() error

func (*ChatLog) FilePathForUser

func (c *ChatLog) FilePathForUser() (string, error)

func (*ChatLog) FlushFile

func (c *ChatLog) FlushFile() error

func (*ChatLog) InitLogFile

func (c *ChatLog) InitLogFile(title string, fileNameFormat string)

func (*ChatLog) LoadFile

func (c *ChatLog) LoadFile(filePath string) error

func (*ChatLog) LoadLogMessage

func (c *ChatLog) LoadLogMessage() error

type ChatLogToml

type ChatLogToml struct {
	Messages []ChatMessage `toml:"messages"`
}

type ChatMessage

type ChatMessage struct {
	Role    string `toml:"role"`
	Content string `toml:"content"`
}

type ChatTemplate

type ChatTemplate struct {
	Name     string    `toml:"name"`
	Messages []Message `toml:"messages"`
}

type Config

type Config struct {
	Profiles []Profile
	Settings Settings
}

func GetConfig

func GetConfig() (*Config, error)

type Editor

type Editor interface {
	Open(filename string) error
}

func InitEditor

func InitEditor(cmdName string) Editor

type FileInfo added in v0.3.0

type FileInfo struct {
	FileFullPath string
	FileName     string
}

func ListFiles added in v0.3.0

func ListFiles(dir string) (fileInfos []FileInfo, err error)

type Message

type Message struct {
	Role    string `toml:"role"`
	Content string `toml:"content"`
}

type Profile

type Profile struct {
	Name           string `toml:"name"`
	Description    string `toml:"description"`
	ApiKey         string `toml:"apiKey"`
	OrganizationID string `toml:"organizationId"`
	Default        bool   `toml:"default"`
}

type ProfileToml

type ProfileToml struct {
	Profiles []Profile `toml:"profiles"`
}

type Setting

type Setting struct {
	Editor     string `toml:"editor"`
	ChatLogDir string `toml:"chatLogDir"`
}

type Settings

type Settings struct {
	Setting Setting `toml:"setting"`
	Chat    Chat    `toml:"chat"`
}

Directories

Path Synopsis
cmd
oax

Jump to

Keyboard shortcuts

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