Tuesday, December 17, 2024

Delphi and AI [Intermission]: Introducing Chatterbox

t’s great that Embarcadero has added an AI Chat window to RAD Studio, but let’s be honest—the implementation is lacking. As one participant at a recent workshop noted: “It looks like someone wrote it two hours before the release.” Sadly, I have to agree. The AI Chat feature is practically useless if you intend to use AI for anything more than a quick demo.

That’s when I started considering better ways to interface with LLMs. Instead of searching for an alternative, I decided to build my own AI chat interface. It’s called Chatterbox, and it’s fully open source. You can find it on GitHub under a “do with it (almost) whatever you want” license.

To start using Chatterbox, you can either build it from source or download the precompiled EXE from GitHub (currently available only for Windows 32-bit). The app is written with FireMonkey, so—at least theoretically—it can also be built for macOS, iOS, Android, and Linux. However, I haven’t tested it on platforms other than Windows.

To build Chatterbox, you’ll need the following libraries: Spring4D, DCPCrypt2, and TAES. Links to these dependencies are included in the README file.

So, what is Chatterbox? is a simple application with a tabbed interface where each tab represents an active chat. Each chat tab is divided into three sections:

  • History Memo (top): Displays all questions and answers.
  • Question Memo (middle): Lets you type new questions.
  • Chat Toolbar (bottom): Provides controls specific to the current chat.

Here’s a quick rundown of the toolbars:

Main Toolbar

  • New Chat (Ctrl+N): Opens a new chat tab.
  • Settings: Opens the settings dialog.

Chat Toolbar

  • Engine Selector: A dropdown to choose the AI engine for the current tab.
  • Send (Ctrl+Enter): Sends the chat history and current question to the selected AI engine.
  • Send to All: Sends the current question to all open tabs, enabling you to compare results from different engines.
  • Save (Ctrl+S): Saves the chat history to a text file.
  • Open (Ctrl+O): Loads a chat history from a text file.
  • Copy (Ctrl+Shift+C): Copies the last AI response to the clipboard.
  • Clear: Clears the chat history.
  • Close (Ctrl+W): Closes the current tab.

Settings

In the Settings dialog, you can define multiple AI engines. Each engine is a combination of a provider (e.g., Claude, Ollama, OpenAI, Gemini) and a specific model. For most providers, you’ll need to supply an API key, which can be generated on their respective websites. The Get API Key button in the settings dialog opens the provider-specific page to retrieve the key.

To set defaults for currently selected engine type (set host URL and number of tokens), use the Defaults button at the bottom.



You can also provide a System prompt which can be used to instruct the AI engine. For example, you can set it to a "You are an experienced Delphi programmer" if you don't want to start each question with "In Delphi, how do I ...".

It’s possible to configure multiple engines using the same provider. For example, in my setup, I have two engines—o1-mini and o1 (general)—that both use OpenAI as the provider. The former is set up for Delphi-related queries, using the o1-mini model and the system prompt “You are an experienced Delphi programmer”. The latter uses the o1-preview model without a system prompt for general questions.

One engine is always marked as the Default Engine, which will be used when opening a new tab.

Security warning

API keys are stored encrypted to reduce the risk of accidental exposure. However, this protection is basic; anyone with access to your settings file could compile Chatterbox and extract the keys. For stronger security, you can define a Passkey in the settings. This will encrypt API keys using AES, providing a reasonable level of safety.

Feedback

Have questions or ideas for improving Chatterbox? Feel free to contact me via email (details are in the README), post a comment here, or use GitHub’s feedback mechanisms.

Happy chatting!

No comments:

Post a Comment