A python package that simplifies and unifies the usage of multiple AI APIs
Project description
UnifiedAI
UnifiedAI is a Python package that simplifies the usage of multiple AI APIs by providing a single, unified API. Currently, it supports OpenAI, Anthropic, Google, and Ollama AI APIs.
Features
- Single API for multiple AI providers.
- Easy switching between different AI models.
- Simplified authentication and API key management.
Installation
pip install UnifiedAI
Usage
Creating an AI instance
API = AI(instance_name,api_provider,api_key,model_name)
Usage and methods of using one AI instance
from UnifiedAI import *
API = AI("gpt4","openai","OPENAI_API_KEY","gpt-4o")
#default is "You are a helpful assistant"
API.set_instructions("You are a sarcastically helpful assistant.")
#default is 512
API.set_max_tokens(100)
# add context without an api call
API.add_context("My Name is John.")
print(API.get_response("what is my name?"))
#history is a list object of all the user messages and assistant responses.
print(API.history)
#print the input token usage of the model
print(API.usage.input_tokens)
#print the output token usage of the model
print(API.usage.output_tokens)
Use multiple AI instances at once using a Batch instance.
from UnifiedAI import *
import json
gpt = AI("gpt","openai","OPENAI_API_KEY","gpt-4o")
claude = AI("claude","anthropic","ANTHROPIC_API_KEY","claude-3-5-sonnet-latest")
gemini = AI("gemini","google","GEMINI_API_KEY","gemini-1.5-pro")
llama = AI("llama","ollama",None,"llama3.2")
models = Batch([gpt, claude, gemini,llama])
models.set_instructions("You are a sarcastically helpful assistant.")
models.set_max_tokens(100)
models.add_context("My name is John.")
# get_response returns a dictionary object with
# the model names and their responses
print(json.dumps(models.get_response("what is my name?"),indent=4))
# print the output token usage of each model
print(models.usage["gpt"].output_tokens)
print(models.usage["claude"].output_tokens)
print(models.usage["gemini"].output_tokens)
print(models.usage["llama"].output_tokens)
Compare responses with different system instructions.
from UnifiedAI import *
import json
angry = AI("angry","openai","OPENAI_API_KEY","gpt-4o")
sarcastic = AI("sarcastic","openai","OPENAI_API_KEY","gpt-4o")
sad = AI("sad","openai","OPENAI_API_KEY","gpt-4o")
angry.set_instructions("Answer in a angry way.")
sarcastic.set_instructions("Answer in a sarcastic way.")
sad.set_instructions("Answer in a sad way.")
emotions = Batch([angry,sarcastic,sad])
emotions.set_max_tokens(100)
print(json.dumps(emotions.get_response("what is 1 + 1?"),indent=4))
print(emotions.usage["angry"].output_tokens)
print(emotions.usage["sarcastic"].output_tokens)
print(emotions.usage["sad"].output_tokens)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unifiedai-1.5.5.tar.gz.
File metadata
- Download URL: unifiedai-1.5.5.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78138981f26bbce9b3e42b7358d329663285d4feaa012176109ddee9feb231db
|
|
| MD5 |
e4b98936c7b8d46668d3b98503f49499
|
|
| BLAKE2b-256 |
b3b2aad5bc9619ede9f3ce81b262a7031484b85019b3c8fd54a7e54da0c0ff31
|
File details
Details for the file unifiedai-1.5.5-py3-none-any.whl.
File metadata
- Download URL: unifiedai-1.5.5-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cea59ddd451dc6c57bc5610671461b4887692044ea24b3fe56c0898ed57c1cf
|
|
| MD5 |
7483327e37008468cacb3400a7107edb
|
|
| BLAKE2b-256 |
fab19fc18451d48c007ee9475e5a94cac5238391d3851e7e64bbece36e400d8d
|