Skip to content
/ airistotle Public template

Airistotle is a basic implementation of the OpenAI Assistants API for making simple programmatic AI assistants.

License

Notifications You must be signed in to change notification settings

0xRy4n/airistotle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Airistotle

Basic implementation of the assistants API. Supports easy extensibility with function calls.

See https://platform.openai.com/assistants to setup an assistant.

Usage

First, copy the .env.template to .env and set any necessary variables. All Airistotle variables are required. Depending on what interfaces you use and what plugins you have enabled, you may need to set additional environment variables.

from airistotle import Assistant
from airsitotle import settings

assistant = Assistant(
    openai_api_key=settings.OPENAI_API_KEY,
    assistant_id=settings.ASSISTANT_ID
)

assistant.send_message("What is 2+2?")
response = assistant.get_response()

print(response)

>>> 2+2 equals 4.

For the CLI interface, simply import it from an interactive shell:

from airistotle.interfaces import cli

Plugins

Plugins are defined in airistotle.plugins.

Plugins can easily be added by extending the BasePlugin class in airistotle.plugins.base. The only expectation is that all plugin classes will implement a run() method will return a string (the result of the function call). Converting a more complex data structure like a dict or list into a string will work fine.

It is also expected your Plugin Class will have a class attribute called name which corresponds to the function name you defined in your assistants function definition.

The arguments of your run method do not matter as long as they match the parameters you specified in your assistant's function definition.

Here is an example of the function definition for the WebSearch plugin:

{
  "name": "web_search",
  "description": "Perform a web search and retrieve the contents from the top results. Use this when ever you are unsure of an answer and need more information. Use it to supplement your own knowledge, not replace it.",
  "parameters": {
    "type": "object",
    "properties": {
      "query": {
        "type": "string",
        "description": "The query you want to search for."
      }
    },
    "required": [
      "query"
    ]
  }
}

When called, the assistant class will unpack the keyword argument list generated by the OpenAI Assistant and pass it to the run argument. In the above example, it's expected that the run function would have a single parameter query which would except a str.

Enabling Plugins

You can enable plugins in the settings.py file.

from .plugins import YourPlugin

AVAILABLE_PLUGINS = {
    YourPlugin.name:YourPlugin(),
}

As long as there is a corresponding function definition in your assistant (see https://platform.openai.com/assistants), this will allow the Assistant class to process the action when the function call is requested. Keep in mind, it's up to the discretion of the OpenAI Assistant to determine when to call functions, and this is influenced both by system prompt and by function description.

Interfaces

Some pre-written interfaces, such as a Slack Interface, may be configured in the airistotle.interfaces directory.

Notes

Airistotle uses Haystack for a basic web_search function, which is incredibly overkill. You can remove this function if you'd like to avoid the Haystack dependency. Alternatively, you can use Haystack for additional extensibility via plugins.

About

Airistotle is a basic implementation of the OpenAI Assistants API for making simple programmatic AI assistants.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages