A lightweight Python library for building chat agents with function calling capabilities
Project description
joao
A dual-purpose tool providing both a Python library for building chat agents and a ready-to-use CLI chat interface. Built with function calling capabilities and compatible with OpenAI-style APIs.
Features
-
As a Library:
- Simple and clean API for chat interactions
- Support for function calling (tools)
- Both synchronous and asynchronous APIs
- Streaming support for real-time responses
- Compatible with any OpenAI-style API (tested with Gemini 2.0 Flash)
-
As a CLI:
- Interactive chat interface
- Single prompt mode
- Rich markdown formatting for output
- Temperature control for response randomness
- Configurable system prompts
- Multiple API provider support
-
Minimal dependencies
Requirements
- Python 3.7 or higher
- An API key from one of these providers:
- Gemini (Recommended): Get your API key from Google AI Studio
- OpenAI: Get your API key from OpenAI Platform
Installation
-
Install the package:
pip install joao
-
Set up environment variables:
For Gemini (default):
export OPENAI_API_KEY="your_gemini_api_key"
For OpenAI:
export OPENAI_API_KEY="your_openai_api_key" export OPENAI_BASE_URL="https://api.openai.com/v1" export OPENAI_MODEL="gpt-3.5-turbo" # or your preferred model
Usage
Command Line Options
# Start interactive chat mode (with system prompt)
joao -s "You are a helpful assistant"
# Start chat mode without system prompt
joao
# Single prompt mode with system prompt
joao -s "You are a helpful assistant" "What is the capital of France?"
# Single prompt mode without system prompt
joao "What is the capital of France?"
# Enable streaming output
joao -s "You are a storyteller" --stream "Tell me a story"
# Set temperature (0.0-2.0, default: 0)
joao -s "You are a creative writer" -t 0.7 "Tell me a creative story"
# Show raw output without markdown formatting
joao -s "You are a helpful assistant" --raw "Hello"
# Use different API provider
joao -s "You are a helpful assistant" -e OPENAI "Using OpenAI API"
# Show debug info
joao -s "You are a helpful assistant" --debug "Test message"
Interactive Chat Commands
When in chat mode, you have access to these commands:
/reset- Clear conversation history/reset <prompt>- Clear history and set new system promptCtrl+C- Exit chat session
Simple Chat API
from joao import Agent
# Create an agent with a personality
agent = Agent("You are Snoopy, the beloved Peanuts character")
# Get a response
response = agent.request("Who are your friends?")
print(response)
# Get a streamed response
for token in agent.request("Tell me a story", stream=True):
print(token, end="", flush=True)
print() # Final newline
Using Function Calling (Tools)
from joao import Agent
def drive_to(location: str):
"""Drive to the specified location"""
print(f"Driving to {location}!")
# Create an agent with tools
agent = Agent("You are a helpful driver")
response = agent.request(
"Can you drive me to San Francisco?",
tools=[drive_to],
auto_use_tools=True # Auto-execute any tool calls
)
Async Support
from joao import AsyncAgent
import asyncio
async def main():
agent = AsyncAgent("You are a helpful assistant")
response = await agent.request("Hello!")
print(response)
# With streaming
async for token in agent.request("Tell me a story", stream=True):
print(token, end="", flush=True)
print()
asyncio.run(main())
Environment Variables
OPENAI_API_KEY- Your API keyOPENAI_BASE_URL- API endpoint (default: Gemini endpoint)OPENAI_MODEL- Model to use (default: gemini-2.0-flash)
You can prefix these with any string by using the -e flag, e.g., -e AZURE will look for AZURE_OPENAI_API_KEY
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 joao-0.1.0.tar.gz.
File metadata
- Download URL: joao-0.1.0.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52b460ee3d12de86e27b0eb699079cc9d4c30709c25b6b552424f6da27629393
|
|
| MD5 |
949c8bfe2bd26e7f99289482af051259
|
|
| BLAKE2b-256 |
caee73affe9a3739edd839e611fed66e3319792b90662fa6ef096ec075b73127
|
File details
Details for the file joao-0.1.0-py3-none-any.whl.
File metadata
- Download URL: joao-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecc1636428ea288719fd9575d1ae3dd5e253dd55218fe22372a5dade0323a574
|
|
| MD5 |
61daa7e5f17138f3f2cded410a83895e
|
|
| BLAKE2b-256 |
1d0a399fc5896d862de71845d340b059e5c1ac5c3398be6d5f385d52aa265167
|