clai: command line artificial intelligence
clai
integrates AI models of multiple vendors via with the terminal.
You can generate images, text, summarize content and chat while using native terminal functionality, such as pipes and termination signals.
The multi-vendor aspect enables easy comparisons between different models, also removes the need for multiple subscriptions: most APIs are usage-based (some with expiration time).
Prerequisites
Note that only one of the vendors are required, but you can only access the models of the vendor you have an API key for.
Most text and photo based models within the respective vendors are supported, see model configurations for how to swap.
Installation
go install github.com/baalimago/clai@latest
Examples
Simple queries:
clai query My favorite color is blue, tell me some facts about it
clai -re `# Use the -re flag to use the previous query as context for some next query` \
q Write a poem about my favorite colour
Personally I have alias ask=clai q
and then alias rask=clai -re q
.
This way I can ask
-> rask
-> rask
for a temporary conversation.
Chatting:
clai chat new Lets have a conversation about Hegel
clai chat list `# List all your chats`
clai -chat-model claude-3-opus-20240229 ` # Using some other model (clai@v1.1+)` \
c continue 1 ` # Continue some previous chat`
Flag -chat-model
works for any text-based model, regardless of vendor.
Ditto, -photo-model
for any photo-based models.
Glob queries:
clai -raw ` # Don't format output as markdown` \
-chat-model gpt-3.5-turbo `# Use some other model` \
glob '*.go' Generate a README for this project > README.md
Photos:
printf "flowers" | clai -i --photo-prefix=flowercat --photo-dir=/tmp photo "A cat made out of {}"
Since -N alternatives are disabled for many newer OpenAI models, you can use repeater to generate several responses from the same prompt:
NO_COLOR=true repeater -n 10 -w 3 -increment -file out.txt -output BOTH \
clai -pp flower_INC p A cat made of flowers
clai help `# For more info about the available commands (and shorthands)`
Configuration
clai
will create configuration files at os.GetConfigDir()/.clai/
.
Two default command-related ones textConfig.json
and photoConfig.json
, then one for each specific model.
The configuration system is as follows:
- Default configurations from
textConfig.json
or photoConfig.json
, here you can set your default model (which implies vendor)
- Override the configurations using flags
The text/photo-Config.json
files configures what you want done, not how the models should perform it.
This way it scales for any vendor + model.
Models
There's two ways to configure the models:
- Set flag
-chat-model
or -photo-model
- Set the
model
field in the textConfig.json
or photoConfig.json
file. This will make it default, if not overwritten by flags.
Then, for each model, a new configuration file will be created.
Since each vendor's model supports quite different configurations, the model configurations aren't exposed as flags.
Example .../.clai/openai_gpt_gpt-4-turbo-preview.json
which the contains configurations specific for this model, such as temperature.
Conversations
Within os.GetConfigDir()/.clai/conversations
you'll find all the conversations.
You can also modify the chats here as a way to prompt, or create entirely new ones as you see fit.
Honorable mentions
This project is heavily inspired by: https://github.com/Licheam/zsh-ask, many thanks to Licheam for the inspiration.