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.3.tar.gz (9.2 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.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for talkit_agent-0.1.3.tar.gz
Algorithm Hash digest
SHA256 52f6c6af9a1d2fec00590be708fc35eae0af7bc0750ef48fcb626d92feff12aa
MD5 e56f438b6506d0928fe63195407dbeab
BLAKE2b-256 a3e2a0586a70e9f614d3ff5b4b61501d84abbcec8f7064363cf5b5870a23d242

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for talkit_agent-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 60bb28810b4074578219aa77177b874940d49057ff2d4548a1e0945fcc42e30a
MD5 e3459b6a7ea94caa17b0bdcb9b55db12
BLAKE2b-256 75a7522d4bf73365a162c908614bd98e918ea7166395b8d23b5fc5588284e090

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