Augmenting an AI Model with RAG and External Tools has been challenging with the most active development around Retrieval Augmented Generation (RAG) and very little attention given to external tools.
This is starting to change as ChatGPT Plus has (had?) plugins and now “GPTs” which provides augmentation in the form of RAG, two powerful built-in tools (a code interpreter and a web browser) as well as one “Action” or what they used to call a plugin. This is a “function call” under the hood in OpenAI parlance and enables the model to access an external tool (API) for additional information or skills.
For those looking to leverage AI models in their own applications OpenAI created it’s Assistant API which includes RAG and it’s own proprietary tools. While the Assistant API has made many things easier it’s still challenging for many to use and many have found it’s easy to run up large bills.
For those looking for an easier tool and would like the flexibilty of using other models (e.g. LLama based models) and have transparency and control over all interactions with the model there are now other options.
AIAPI - What is it?
AIAPI is a baby step to provide an out-of-the-box library and chat client that provides everything necessary to augment your AI model with external tools and is not tied to any AI model or service. It’s built on top of the vand-python library and the excellent simplaichat library where in inherits several key features including:
- Easy to use sessions that string together all messages (assistant, user, and function).
- Save and reload sessions
- Include your own functions / tools in your application to augment the AI model’s capabilities.
- Simple access to thousands of tools found on https://vand.io.
Together these are similar to OpenAI’s Assistant API but with several advantages. Here’s a quick look at how these tools compare.
|Model Object (define a model, parameters, etc.)
|Log of Chat messages
|Executing a model call
|Included OpenAI tools or write your own
|Included Vand tools or write your own
Here’s a side-by-side look at how you might use AIAPI or OpenAI’s Assistant API. See a complete example of AIAPI usage on GitHub. See a [cookbook(https://cookbook.openai.com/examples/assistants_api_overview_python)] on using the Assistant API.
Create an Assistant
Create a Thread
|NA. A session (thread) is automatically created.
|Add a Message to a Thread
|Run the Thread
NA. The session is automaticaly “run” when the new message is added in the step above.
|Display the Assistant's Response
The latest response (assistant message) would be in the
message variable if you invoked with
message = assistant("New User Message"). To get the entier session (thread) use
|Save the Thread
NA. Thread is automatically saved with it's
Save to local file with:
|Load a Thread
Need to know the `ThreadID`.
Load from local file with:
Learn more about AIAPI and download it and try it out yourself on GitHub.