MBX AI SDK
Project description
MBX AI
A Python library for building AI applications with LLMs.
Features
- OpenRouter Integration: Connect to various LLM providers through OpenRouter
- Tool Integration: Easily integrate tools with LLMs using the Model Context Protocol (MCP)
- Structured Output: Get structured, typed responses from LLMs
- Chat Interface: Simple chat interface for interacting with LLMs
- FastAPI Server: Built-in FastAPI server for tool integration
Installation
pip install mbxai
Quick Start
Basic Usage
from mbxai import OpenRouterClient
# Initialize the client
client = OpenRouterClient(api_key="your-api-key")
# Chat with an LLM
response = await client.chat([
{"role": "user", "content": "Hello, how are you?"}
])
print(response.choices[0].message.content)
Using Tools
from mbxai import OpenRouterClient, ToolClient
from pydantic import BaseModel
# Define your tool's input and output models
class CalculatorInput(BaseModel):
a: float
b: float
class CalculatorOutput(BaseModel):
result: float
# Create a calculator tool
async def calculator(input: CalculatorInput) -> CalculatorOutput:
return CalculatorOutput(result=input.a + input.b)
# Initialize the client with tools
client = ToolClient(OpenRouterClient(api_key="your-api-key"))
client.add_tool(calculator)
# Use the tool in a chat
response = await client.chat([
{"role": "user", "content": "What is 2 + 3?"}
])
print(response.choices[0].message.content)
Using MCP (Model Context Protocol)
from mbxai import OpenRouterClient, MCPClient
from mbxai.mcp import MCPServer
from mcp.server.fastmcp import FastMCP
from pydantic import BaseModel
# Define your tool's input and output models
class CalculatorInput(BaseModel):
a: float
b: float
class CalculatorOutput(BaseModel):
result: float
# Create a FastMCP instance
mcp = FastMCP("calculator-service")
# Create a calculator tool
@mcp.tool()
async def calculator(argument: CalculatorInput) -> CalculatorOutput:
return CalculatorOutput(result=argument.a + argument.b)
# Start the MCP server
server = MCPServer("calculator-service")
await server.add_tool(calculator)
await server.start()
# Initialize the MCP client
client = MCPClient(OpenRouterClient(api_key="your-api-key"))
await client.register_mcp_server("calculator-service", "http://localhost:8000")
# Use the tool in a chat
response = await client.chat([
{"role": "user", "content": "What is 2 + 3?"}
])
print(response.choices[0].message.content)
Development
Setup
- Clone the repository:
git clone https://github.com/yourusername/mbxai.git
cd mbxai
- Create a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install dependencies:
pip install -e ".[dev]"
Running Tests
pytest tests/
License
MIT License
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
mbxai-1.2.1.tar.gz
(22.3 kB
view details)
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
mbxai-1.2.1-py3-none-any.whl
(33.4 kB
view details)
File details
Details for the file mbxai-1.2.1.tar.gz.
File metadata
- Download URL: mbxai-1.2.1.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1b5d03324259abadf66298ba2d59d01369053f13593aca7b37c981fbd674f5b
|
|
| MD5 |
fe113f4a9915012c3c34aa60f23a0834
|
|
| BLAKE2b-256 |
0c9432b06a44c9b3a98d89993626050814e1f4239b6bf43187d7e630c20e443d
|
File details
Details for the file mbxai-1.2.1-py3-none-any.whl.
File metadata
- Download URL: mbxai-1.2.1-py3-none-any.whl
- Upload date:
- Size: 33.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
694dff94312e59db7fcd025762140cdc587362b16457e64ec21d67b6c45f18ce
|
|
| MD5 |
e5341edd115d395dfbe22169e6dc5e7d
|
|
| BLAKE2b-256 |
65083ebf1658622cb656265a96de26dc2062ddc0f383b883ac8c1fdc0ecc1a60
|