Skip to main content

Small OpenAI/Anthropic library to support chat templates, and function calls

Project description

AutoChat

AutoChat is an assistant library, that supports OpenAI/Anthropic, to simplify the process of creating interactive agents.

  • Autochat Class: Conversation wrapper to store instruction, context and messages histories.
  • Message Class: Message wrapper to handle format/parsing automatically.
  • Function Calls: Capability to handle function calls within the conversation, allowing complex interactions and responses.
  • Template System: A straightforward text-based template system for defining the behavior of the chatbot, making it easy to customize its responses and actions.

Installation

To install the package, you can use pip:

pip install autochat

Please note that this package requires Python 3.6 or later.

Simple Example

> from autochat import Autochat
> chat = Autochat(instruction="You are a parot")
> chat.ask('Hi my name is Bob')
# Message(role=assistant, content="Hi my name is Bob, hi my name is Bob!")
> chat.ask('Can you tell me my name?')
# Message(role=assistant, content="Your name is Bob, your name is Bob!")

Function Calls Handling

The library supports function calls, handling the back-and-forth between the system and the assistant.

from autochat import Autochat, Message
import json

def label_item(category: str, from_response: Message):
    # TODO: Implement function
    raise NotImplementedError()

with open("./examples/function_label.json") as f:
    FUNCTION_LABEL_ITEM = json.load(f)

classifierGPT = Autochat.from_template("./examples/classify_template.txt")
classifierGPT.add_function(label_item, FUNCTION_LABEL_ITEM)

text = "The new iPhone is out"
for message in classifierGPT.run_conversation(text):
    print(message.to_markdown())

# > ## assistant
# > It's about \"Technology\" since it's about a new iPhone.
# > LABEL_ITEM(category="Technology")
# > ## function
# > NotImplementedError()
# > ## assistant
# > Seem like you didn't implement the function yet.

Template System

We provide a simple template system for defining the behavior of the chatbot, using markdown-like syntax.

## system
You are a parrot

## user
Hi my name is Bob

## assistant
Hi my name is Bob, hi my name is Bob!

## user
Can you tell me my name?

## assistant
Your name is Bob, your name is Bob!

You can then load the template file using the from_template method:

parrotGPT = Autochat.from_template("./parrot_template.txt")

The template system also supports function calls. Check out the examples/demo_label.py for a complete example.

Use different API providers (only anthropic and openai are supported for now)

Default provider is openai.

Anthropic:

chat = Autochat(provider="anthropic")

Environment Variables

The AUTOCHAT_MODEL environment variable specifies the model to use. If not set, it defaults to "gpt-4-turbo".

export AUTOCHAT_MODEL="gpt-4-turbo"
export OPENAI_API_KEY=<your-key>

or with anthropic

export AUTOCHAT_MODEL="claude-3-opus"
export ANTHROPIC_API_KEY=<your-key>

Use AUTOCHAT_HOST to use alternative provider (openai, anthropic, openpipe, llama_cpp, ...)

Support

If you encounter any issues or have questions, please file an issue on the GitHub project page.

License

This project is licensed under the terms of the MIT license.

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

autochat-0.3.7.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

autochat-0.3.7-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file autochat-0.3.7.tar.gz.

File metadata

  • Download URL: autochat-0.3.7.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for autochat-0.3.7.tar.gz
Algorithm Hash digest
SHA256 68a9edda437f97c1601cd3cdc64b7b093ab6c9285da4413030a4d4ed26707376
MD5 0e49beadee7196765726f9faab1abbfe
BLAKE2b-256 11c9f20412e8c3bdfa0bf7fdf1b295aca76a3f2036cc6693e7d503cdc6cf8b48

See more details on using hashes here.

File details

Details for the file autochat-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: autochat-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for autochat-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b3130e9db17791310e0434680d1b7962840f90b200451ec36dc4c73e4e9c672d
MD5 ca39586c97c2df73fa7c4b8857e3f11c
BLAKE2b-256 c7b078f63e7f8e88f7ac0681f466b1e98031405fcea233833e64f7568ee2a1f1

See more details on using hashes here.

Supported by

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