Skip to main content

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

  1. Clone the repository:
git clone https://github.com/yourusername/mbxai.git
cd mbxai
  1. Create a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. 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-0.6.20.tar.gz (55.2 kB view details)

Uploaded Source

Built Distribution

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

mbxai-0.6.20-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file mbxai-0.6.20.tar.gz.

File metadata

  • Download URL: mbxai-0.6.20.tar.gz
  • Upload date:
  • Size: 55.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mbxai-0.6.20.tar.gz
Algorithm Hash digest
SHA256 e3652d5f5658b34449998743312bc0e373345166076fb1b95ef66b99b88b1f0c
MD5 4ee2ecb71c0d0a21adc27b41ce9f0cb0
BLAKE2b-256 b32ce5a0a5a5763aad37a379e2b4bfdeea30792eb54322182f6d65416a630b4f

See more details on using hashes here.

File details

Details for the file mbxai-0.6.20-py3-none-any.whl.

File metadata

  • Download URL: mbxai-0.6.20-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mbxai-0.6.20-py3-none-any.whl
Algorithm Hash digest
SHA256 ab13591fbbf6f66e0e8635574c02f80ce19d0450043da8dee5f7a6a9e96b6c27
MD5 2cadadb4a70c1c76224876336a4abb67
BLAKE2b-256 5987ce61e894fcb71161aab2ffd7a7d8afd0d803653680ecbda7ba9181932890

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