Skip to main content

Add your description here

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.1.tar.gz (9.1 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.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for talkit_agent-0.1.1.tar.gz
Algorithm Hash digest
SHA256 df93d29c983a9b0a3cc2a823aeed4903a4725847972d45417ba20602aa81ef3e
MD5 b5bc155e0dda8ac1df3d3cdd66666e37
BLAKE2b-256 fc76342f5b9234b4ffda4c626dd0fa6f41e3d59e405a4c256dd8da6a8c64719b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for talkit_agent-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b0804e62a54529037a6dd2f9d6e7b6ede21d47abf985cf9ee6ee19549056df55
MD5 d30877e5a8ca6e14f0ced43385b3c966
BLAKE2b-256 47d0cea20434cd41905d1442ef613085f7e4c46c1428254a2957fa53ddcc7158

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