Skip to main content

Adapters for Large Language Models and Generative Pre-trained Transformers APIs

Project description

aigents

Adapters for Large Language Models and Generative Pre-trained Transformers APIs

Installation

Using pip

python -m pip install aigents

Usage

The aigents package intention is to tackle the issue of out there having a wide variety of different AI models APIs, even though most of them keep similar standards, it might be confusing or challeging for developers to merge, scale and write conssitent solutions that englobes them.

Chat

The main classes for completions or chat have Chatters on their name. For instance, aigents.GoogleChatter uses Google's AI completion models to generate chat responses. The method for calling responses is answer.

The constructors for Chatters differs a little, but on thing in common on them is the setup (str) argument: a text instructing the AI model to play some role. For example:

from aigents import GoogleChatter

setup = "You are a very experienced and successful fantasy novel writer. "
## generate your API key: https://makersuite.google.com/app/apikey
api_key = "YOUR_GOOGLE_AI_API_KEY"
temperature = 0.5  # for creativity
chatter = GoogleChatter(setup=setup, api_key=api_key)

response = chatter.answer(
    "What are the difference between soft magic system "
    "and hard magic system?"
)

The returned value is a string corresponding on the first candidate response from Gemini API, which you can access using the attribute chatter.last_response.

For OpenAI and Google chatters you can the the API key using .env file. Use the .sample.env: paste your API keys and save it as .env

Conversation

By default, chatter.answer has conversation=True for every Chatter. This means that the object keeps a record of the messages (conversation), which you can access using the attribute chatter.messages.

If the messages exceeds the token window allowed for the corresponding model, the instance will try to reduce the size of the messages. If the default values of use_agent=True is set for chatter.answer, the Chatter will use another instance to summarize messages, in order to preserve most of the history and meaning of the conversation. Otherwise it will remove the oldest (but the chatter.setup, if provided) messages.

This section provides a brief overview of the classes in core.py and their usage.

Async version:

Every chatter have an async version. For instance, the previous code can be written using async version of the OpenAI's chatter:

from aigents import AsyncOpenAIChatter

setup = "You are a very experienced and successful fantasy novel writer. "
## generate your API key: https://platform.openai.com/api-keys
api_key = "YOUR_OPEN_AI_API_KEY"
temperature = 0.5  # for creativity
chatter = AsyncOpenAIChatter(setup=setup, api_key=api_key)

response = await chatter.answer(
    "What are the difference between soft magic system "
    "and hard magic system?"
)

Other Chatters:

  • AsyncGoogleChatter: async version of GoogleChatter;
  • GoogleVision: agent for image chat (Important: gemini-pro-vision does not generate images as for this date);
  • AsyncGoogleVision: async version of GoogleVision
  • OpenAIChatter: chatter that uses OpenAI's API;
  • BingChatter: uses the uses g4f adpter, with Bing provider;
  • AsyncBingChatter: async version of BingChatter.

Models

You can check different AI models used by aigents in module constants. For instance, for changing OpenAI chatter's model from gpt-3.5-turbo-0125 to gpt-4-0125-preview:

from aigents import OpenAIChatter
from aigents.constants import MODELS

api_key = "YOUR_OPEN_AI_API_KEY"
chatter = OpenAIChatter(setup=setup, api_key=api_key)
chatter.change_model(MODELS[3])
# always checked if it is the intended model
print(chatter.model)

Contributing

Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.

License

This project is licensed under GNU_GPL_v3.0

Credits

aigents was created with cookiecutter and the py-pkgs-cookiecutter template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aigents-0.6.0.tar.gz (43.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aigents-0.6.0-py3-none-any.whl (47.6 kB view details)

Uploaded Python 3

File details

Details for the file aigents-0.6.0.tar.gz.

File metadata

  • Download URL: aigents-0.6.0.tar.gz
  • Upload date:
  • Size: 43.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-28-generic

File hashes

Hashes for aigents-0.6.0.tar.gz
Algorithm Hash digest
SHA256 822da01ca863240e61b7d51ea0c4596939a73f6261d5cdcdaaa77755e0d5695f
MD5 fcd98fdcec10e211fedd29166864fce3
BLAKE2b-256 ffe322b63e9b85d461a817efa81ecba5744742caed449b0747e7cefa01eb4446

See more details on using hashes here.

File details

Details for the file aigents-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: aigents-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 47.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.5.0-28-generic

File hashes

Hashes for aigents-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5194a5da997c8426f77f5958ea1785f8412b35d4d70ee6832516847348cd4f0
MD5 8085537c75a0cbc998dd419e75514dbe
BLAKE2b-256 166ac75c02c944266831a65cabfde36d7dd1013a4182d57e8656d1fb8ed060b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page