Skip to main content

ChatsAPI

The World's Fastest AI Agent Framework.
Based on SBERT and SpaCy Transforms, ChatsAPI is designed to enable seamless natural language processing for AI-powered conversational agents. With hybrid search capabilities and an extensible architecture, ChatsAPI offers blazing-fast performance and intuitive route management.

ChatsAPI-Banner.png

Features

  • SBERT & SpaCy-Based NLP: Combines the power of Sentence-BERT embeddings and SpaCy for intelligent semantic matching and entity extraction.
  • Hybrid Search: Supports HNSWlib-based nearest neighbor search and BM25 hybrid search for efficient query handling.
  • Dynamic Routing: Easily define conversational routes with decorators.
  • Parameter Extraction: Automatically extract parameters from user input with flexible type handling.
  • LLM Integration: Integrates with popular LLMs such as OpenAI, Gemini, and LlamaAPI for extended conversational capabilities.
  • Conversation Management: Supports multi-session conversation handling with unique session IDs.

Installation

Install the package via pip:

pip install chatsapi

Usage

Initializing the Framework

from chatsapi import ChatsAPI

chat = ChatsAPI(
    llm_type="gemini",  # Choose LLM type (e.g., gemini, openai, ollama)
    llm_model="models/gemini-pro",  # Specify model
    llm_api_key="YOUR_API_KEY"  # API key for the LLM
)

Registering Routes

Define conversational routes using decorators. Routes map user inputs to specific handler functions.

@chat.trigger("Want to cancel a credit card.")
@chat.extract([("card_number", "Credit card number (a 12-digit number)", str, None)])
async def cancel_credit_card(chat_message: str, extracted: dict):
    return {"message": chat_message, "extracted": extracted}

Explanation:

  • @chat.trigger: Registers the route with a user-friendly description.
  • @chat.extract: Automatically extracts parameters from user input.

Running the Chat API

Use the run method to handle user inputs.

async def main():
    response = await chat.run("I want to cancel my credit card.")
    print(response)

Full Example: FastAPI Integration

from fastapi import FastAPI, Request, Response
from pydantic import BaseModel
from chatsapi import ChatsAPI

app = FastAPI()
chat = ChatsAPI(
    llm_type="gemini",
    llm_model="models/gemini-pro",
    llm_api_key="YOUR_API_KEY",
)

@chat.trigger("Need help with account settings.")
@chat.extract([
    ("account_number", "Account number (a 9-digit number)", int, None),
    ("holder_name", "Account holder's name (a person name)", str, None)
])
async def account_help(chat_message: str, extracted: dict):
    return {"message": chat_message, "extracted": extracted}

class RequestModel(BaseModel):
    message: str

@app.post("/chat")
async def message(request: RequestModel):
    reply = await chat.run(request.message)
    return {"response": reply}

Advanced: Conversation Management

ChatsAPI supports multi-session conversations using unique session IDs:

session_id = chat.set_session()  # Start a new session
response = await chat.conversation("Tell me about my account", session_id)
print(response)

chat.end_session(session_id)  # End the session

Supported LLMs

  • OpenAI (ChatGPT)
  • Gemini
  • LlamaAPI
  • Ollama

Technical Details

  • SBERT: Used for creating sentence embeddings.
  • HNSWlib: Provides fast approximate nearest neighbor search.
  • BM25: Implements Okapi BM25 for token-based matching.
  • SpaCy: Handles natural language parsing and entity recognition.

logical_flow.png

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contribution

Contributions are welcome! Feel free to open issues or submit pull requests.

Metadata

Release files for chatsapi 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chatsapi 0.1.0
File Size Uploaded
chatsapi-0.1.0.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chatsapi 0.1.0
File Interpreter ABI Platform
chatsapi-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / chatsapi-0.1.0.tar.gz

Download URL chatsapi-0.1.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
40960cc1dafaa0e9700e6ae11e718cd43702dadfd864717802246fcc3d109212
BLAKE2b-256 checksum
How to use checksums
6cc4ef0b78bf6ff5ef51ab8ec57e88733e6d328e56714da250369f51b98d6f05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.1

Release files / chatsapi-0.1.0-py3-none-any.whl

Download URL chatsapi-0.1.0-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb2bffc33bc9e86755a4f5f3af1016f83b18caacf46dde5d7590b4a735d4d478
BLAKE2b-256 checksum
How to use checksums
1dd7bfa4ff963b2aafba20e007e46e2c02470546c65427060477926d7c2ff21d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.1

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page