Skip to main content

A more intuitive and consistent interface on top of existing chatbot APIs

Project description

Colloquy

A more intuitive and consistent interface on top of existing chatbot APIs.

Installation

pip install colloquy_chatbot

Quick Start

from colloquy_chatbot import OpenAIBot, ClaudeBot, PromptFunction

# Create a basic OpenAI chatbot
openai_bot = OpenAIBot(instructions="You are a helpful assistant.")

# Or use Claude
claude_bot = ClaudeBot(instructions="You are a helpful assistant.")

# Send a message and get a response
response = openai_bot.prompt("Hello, can you help me?")
print(response)  # Bot's response

# Create a chatbot with function calling
def get_weather(location="New York"):
    return f"It's sunny in {location}"

weather_bot = OpenAIBot(
    instructions="You can check the weather.",
    functions=[
        PromptFunction(get_weather, 
                       description="Get the current weather for a location")
    ]
)

weather_response = weather_bot.prompt("What's the weather like in Tokyo?")
print(weather_response)

Chatbot Types

OpenAIBot

The main chatbot implementation that uses OpenAI's API:

from colloquy_chatbot import OpenAIBot

bot = OpenAIBot(instructions="You are a helpful assistant.")  # Optional system message

response = bot.prompt("Hello!")
print(response)

# Access conversation history
print(bot.history)

ClaudeBot

The chatbot implementation that uses Anthropic's Claude API:

from colloquy_chatbot import ClaudeBot

bot = ClaudeBot(instructions="You are a helpful assistant.")  # Optional system message

response = bot.prompt("Hello!")
print(response)

# Access conversation history
print(bot.history)

EchoBot

A simple bot for testing that echoes back the input:

from colloquy_chatbot import EchoBot

bot = EchoBot()
response = bot.prompt("Hello!")
print(response)  # "Hello!"

Custom Bots

Create your own bot by extending the ChatBot class:

from colloquy_chatbot import ChatBot, BotMessage

class ReverseBot(ChatBot):
    async def send_prompt(self):
        last_message = self.history[-1]
        reversed = last_message.text[::-1]
        return BotMessage(reversed)

bot = ReverseBot()
print(await bot.prompt("Hello"))  # "olleH"

Function Calling

Colloquy makes it easy to enable function calling with both OpenAI and Claude:

With OpenAI

from colloquy_chatbot import OpenAIBot, prompt_function

# Define a function
@prompt_function(description="Calculate the area of a rectangle",
                parameter_descriptions={
                    "length": "The length of the rectangle",
                    "width": "The width of the rectangle"
                })
def calculate_area(length=1, width=1):
    return length * width

# Create a bot with the function
bot = OpenAIBot(
    functions=[calculate_area]
)

# The AI can now use the function when appropriate
response = bot.prompt("What's the area of a 5x3 rectangle?")
print(response)

With Claude

from colloquy_chatbot import ClaudeBot, prompt_function

# Define a function
@prompt_function(description="Calculate the area of a rectangle",
                parameter_descriptions={
                    "length": "The length of the rectangle",
                    "width": "The width of the rectangle"
                })
def calculate_area(length=1, width=1):
    return length * width

# Create a bot with the function
bot = ClaudeBot(
    functions=[calculate_area]
)

# Claude can now use the function when appropriate
response = bot.prompt("What's the area of a 5x3 rectangle?")
print(response)

It can infer a lot from the function definition itself:

  • It can determine the name from the name of the function
    • It understands both lambda: "foo" and def test(): return "foo", but only the latter has a name attached
  • Default parameters are used to infer the type when they are specified
    • Type hints are helpful at development time, but default parameters are used at runtime

These inferences are there to make your life easier, but you can always override everything but parameter names like this:

@prompt_function(
    name="some-other-name",
    description="Calculate the area of a rectangle",
    parameter_descriptions={
        "length": "The length of the rectangle",
        "width": "The width of the rectangle"
    }
)
def calculate_area(length=1, width=1):
    return length * width

Positional arguments get translated into an object before being sent to OpenAI, so feel free to use them in your functions. The goal is to allow you to define functions in a way that is intuitive, while still translating into a form supported by the API.

Environment Variables

  • OPENAI_API_KEY: Required for using OpenAIBot
  • ANTHROPIC_API_KEY: Required for using ClaudeBot

License

MIT

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

colloquy_chatbot-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

colloquy_chatbot-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file colloquy_chatbot-0.1.0.tar.gz.

File metadata

  • Download URL: colloquy_chatbot-0.1.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for colloquy_chatbot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 56ce0dc02252f059b56648a4847175531305c3adadf90d82857cff4e81b297aa
MD5 70ecbf90aa542d58cb1811d172095410
BLAKE2b-256 25fe8203bd1ec746897a8c2317727a4c0a3fa641a4343b3fe5c264a1ec8b99ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for colloquy_chatbot-0.1.0.tar.gz:

Publisher: python-publish.yml on Colloquy-ChatBot/colloquy-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file colloquy_chatbot-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for colloquy_chatbot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6b8c6a0646df82001c1c78465aee167a9a92d9b660f67344a27ee0e1bf6138d
MD5 5fbad9ef3ba6fdd17eeb9debdc277915
BLAKE2b-256 070ba767b86c01aba2f52a78ea714aa9c229b2e597a35f4a06f68dbbea61a6f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for colloquy_chatbot-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on Colloquy-ChatBot/colloquy-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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