clai

command module
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 9 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

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:

  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
models
This package contains test intended to be used by the implementations of the Querier, ChatQuerier and StreamCompleter interfaces
This package contains test intended to be used by the implementations of the Querier, ChatQuerier and StreamCompleter interfaces

Jump to

Keyboard shortcuts

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