clai

command module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 8 Imported by: 0

README

clai: command line artificial intelligence

Go Report Card

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).

clai_in_action_example

Prerequisites

  • Go: Install Go from here.
  • OpenAI API Key: Set the OPENAI_API_KEY environment variable to your OpenAI API key. See here.
  • Anthropic API Key: Set the ANTHROPIC_API_KEY environment variable to your Anthropic API key. See here.
  • Glow (Optional): Install Glow for formatted markdown output when querying text responses.

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

For stable version supporting only openai:

go install github.com/baalimago/clai@v1.0

For the latest version supporting multiple vendors (anthropic textmodels + openai). Note that this is less stable as of 2024-04-01:

go install github.com/baalimago/clai@v1.1
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:

  1. Default configurations from textConfig.json or photoConfig.json, here you can set your default model (which implies vendor)
  2. 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:

  1. Set flag -chat-model or -photo-model
  2. 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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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