/chatbot

A terminal-based client for talking to OpenAI's GPT models

Primary LanguageRust

Chatbot

A terminal-based client for talking to OpenAI's GPT models.

Getting Started

An Open AI account is necessary to talk to the bot. Once you have that, you'll need to set some configuration. Either set these in environment variables or create a .env file containing them:

OPENAI_API_KEY=<your api key>
OPENAI_ORGANIZATION_ID=<your org id>
  • You can find your organization ID here.
  • You can find your API key(s) here.

Once those are set, run the app and start chatting:

cargo run

To exit the app when you're done talking, hit ESC. Your conversation will be saved to a SQLite database in the app directory. Next time you start the app you can pick up where you left off.

Costs

Using this app will cost a small amount of money, based on your usage of the OpenAI API. Specifically, you'll be paying for a language model, the prices of which are found here.

Prices are per 1,000 tokens. You can think of tokens as pieces of words, where 1, 000 tokens is about 750 words.

The default model used by this app, Davinci, costs 2¢ per 1000 tokens. There are cheaper models, but I find their capability to be lacking and I don't recommend them. The total number of tokens used whenever you press ENTER varies.

Completions requests are billed based on the number of tokens sent in your prompt plus the number of tokens in the completion(s) returned by the API.

Each request includes a customizable prompt and several of the last messages between you and the bot. During testing, my conversations used, on average:

  • 250 tokens for prompts
  • 70 tokens for bot responses

With a combined average of 320 tokens, that's a cost of 0.64¢ per ENTER press.

You can read more on Completions pricing here.

Advanced Configuration

This app supports configuration of lots of stuff through environment variables.

Environment Variable Default Description
DATABASE_FILE_PATH "chatbot.db" The file comprising your chat log database. A new one will be created if none exists.
EXPECTED_RESPONSE_TIME 5 seconds The amount of time to wait before considering the bot's response late. This only affects the the status update in the lower right.
OPENAI_API_KEY (required) An OpenAI API key. Find your key(s) [here](API-key).
OPENAI_MODEL_NAME "text-davinci-003" The GPT model to use for txt completions. Find more models [here](models).
OPENAI_ORGANIZATION_ID (required) An OpenAI Organization ID. Find yours [here](organization-id).
PROMPT_CONTEXT_LENGTH 5 The number of chat messages to send as part of the prompt. Longer lengths will give the bot more context but will cost more money.
RESPONSE_TOKEN_LIMIT 100 The maximum number of tokens to generate for the bot's response. *[OpenAI docs](max-tokens)*
STARTING_PROMPT "The following is a conversation that 'User' is having with an AI assistant named 'Bot'. The assistant is helpful, creative, clever, and very friendly." The prompt that will be prepended to the last few chat messages to fetch the bot's response. See [here](prompt-design) for prompt design tips.
THEIR_NAME "Bot" A name representing the bot that you're talking to in chat logs.
USER_INPUT_POLL_DURATION 10 milliseconds How long to wait when polling for user input. The longer this is, the less resources it takes to run the app, but the more laggy typing feels.
YOUR_NAME "User" A name representing you, the user, in chat logs.

If you have issues and want to debug them

This app uses tracing to record logs. If you run the app with RUST_LOG=trace then it'll write logs to a file called 'debug.log'. You can tail that log to see live updates.