Skip to main content

Talkit Agent turns any OpenAPI spec into a conversational API assistant. It understands user prompts, picks the right endpoint, makes the call, and returns the result. Just talk to your API.

Project description

talkit_agent

Talkit Agent turns any OpenAPI spec into a conversational API assistant. It understands user prompts, picks the right endpoint, makes the call, and returns the result. Just talk to your API.

Installation

You can install the talkit_agent package using pip:

pip install talkit-agent

Or clone the repository and install locally:

git clone https://github.com/your-username/talkit_agent.git
cd talkit_agent
pip install -e .

Requirements

  • Python 3.12 or later
  • OpenAI API key

Usage

import asyncio
import os
from talkit_agent import TalkitAgent
from talkit_agent.ai_models import AIModelClient
from talkit_agent.open_api import OpenAPIClient

# Define your OpenAPI spec
spec = {
    "openapi": "3.0.0",
    "info": {
        "title": "Example API",
        "version": "1.0.0",
    },
    "paths": {
        "/api/users": {
            "get": {
                "summary": "Get all users",
                "description": "Returns a list of all users in the system",
                "operationId": "getUsers",
                "responses": {
                    "200": {
                        "description": "Successful operation",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "array",
                                    "items": {
                                        "type": "object",
                                        "properties": {
                                            "id": {"type": "integer"},
                                            "name": {"type": "string"},
                                            "email": {"type": "string"},
                                        },
                                    },
                                }
                            }
                        },
                    }
                },
            }
        }
    },
}

async def main():
    # Initialize the TalkitAgent
    talkit_agent = TalkitAgent(
        base_url="https://api.example.com",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        open_api_client=OpenAPIClient(spec),
        ai_model_client=AIModelClient(api_key=os.getenv("OPENAI_API_KEY")),
    )

    # Create a new chat
    chat_id = talkit_agent.create_chat()

    # Send a message to the chat
    chat_message = await talkit_agent.send_message(
        chat_id=chat_id, prompt="List all users"
    )
    print(f"Chat ID: {chat_id} - Message: {chat_message.content}")

if __name__ == "__main__":
    asyncio.run(main())

API Reference

TalkitAgent

The main class that manages conversations and interactions with APIs.

  • __init__(base_url, headers, open_api_client, ai_model_client): Initialize the agent
  • create_chat(): Create a new chat session and return its ID
  • get_chat(chat_id): Get a chat by ID
  • list_chats(): List all available chat IDs
  • delete_chat(chat_id): Delete a chat by ID
  • send_message(chat_id, prompt): Send a message to a chat and get AI response

OpenAPIClient

Handles OpenAPI specification parsing and operation management.

  • __init__(spec): Initialize with an OpenAPI spec dictionary
  • from_string(data): Create from a JSON string
  • from_file(path): Create from a JSON file
  • list_operations(): List all available API operations
  • get_operation_details(path, method): Get details of an operation
  • get_operation_details_by_id(operation_id): Get operation details by ID

AIModelClient

Manages interactions with OpenAI models.

  • __init__(api_key=None, model=None): Initialize with an API key and model name
  • call(input, tools=None, output_format=None): Call the OpenAI API

License

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

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

talkit_agent-0.1.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

talkit_agent-0.1.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file talkit_agent-0.1.2.tar.gz.

File metadata

  • Download URL: talkit_agent-0.1.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.20

File hashes

Hashes for talkit_agent-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c5cc95c4bf5537fdb0d14f85998e072f23af22848878ba34c70ea5487b4d8f55
MD5 cd78b39a6d2d5ecbdff6d4ea44f8badd
BLAKE2b-256 020f19d40a91ce862e40cdbe4e97d60085ca3cb8b0ec3f6117ed23691000fc86

See more details on using hashes here.

File details

Details for the file talkit_agent-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for talkit_agent-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 862dd07f46464132f4add35e8a8b78a871c0bbe7c3a2161dabe66d9137a89751
MD5 9e44835d618f75f91ef8b799f65cda2f
BLAKE2b-256 4807781d38745c43e8b4bfae79290f0160fe8a6240606f4f61d07ec17b44d973

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