Skip to main content

GPT Trainer API Python Client

A Python client library for interacting with the GPT Trainer API. This library provides an easy-to-use interface for managing chatbots, agents, sessions, messages, and data sources.


Features

  • Chatbot Management: Create, update, list, and delete chatbots.
  • Agent Management: Manage agents associated with chatbots.
  • Session Management: Create and manage chatbot sessions.
  • Message Management: Retrieve and manage messages within sessions.
  • Data Source Management: Upload, update, and delete chatbot data sources.

Installation

Install the library via pip:

pip install gpt-trainer-api

Alternatively, if you're developing locally, clone this repository and install it:

git clone https://github.com/Tahir-Siddique/gpt-trainer-api.git
cd gpt-trainer-api
pip install .

Usage

Initialize the API

from gpt_trainer.api import GPTTrainerAPI

# Initialize the GPT Trainer API client
api = GPTTrainerAPI(token="<your-api-token>")

Chatbot API

List all chatbots

chatbots = api.chatbot.get_chatbots()
for chatbot in chatbots:
    print(chatbot.name, chatbot.uuid)

Create a chatbot

data = {
    "name": "My New Chatbot",
    "visibility": "private",
    "rate_limit": [20, 240],
    "rate_limit_message": "Too many messages. Try again later.",
    "show_citations": True,
}
new_chatbot = api.chatbot.create_chatbot(data)
print(new_chatbot.uuid, new_chatbot.name)

Agent API

List all agents for a chatbot

chatbot_uuid = "<chatbot-uuid>"
agents = api.agent.get_agents(chatbot_uuid)
for agent in agents:
    print(agent.name, agent.type)

Create an agent

data = {
    "name": "Agent 1",
    "description": "Handles FAQs",
    "prompt": "Answer all FAQs concisely.",
    "type": "user-facing",
    "enabled": True,
}
new_agent = api.agent.create_agent(chatbot_uuid, data)
print(new_agent.uuid, new_agent.name)

Session API

Create a new session

new_session = api.session.create_session(chatbot_uuid)
print(new_session.uuid, new_session.created_at)

List sessions

sessions = api.session.list_sessions(chatbot_uuid)
for session in sessions:
    print(session.uuid, session.meta)

Message API

List messages in a session

session_uuid = "<session-uuid>"
messages = api.message.list_messages(session_uuid)
for message in messages:
    print(message.query, message.response)

Data Source API

List all data sources for a chatbot

sources = api.data_source.list_sources(chatbot_uuid)
for source in sources:
    print(source.file_name, source.status)

Upload a file as a data source

file_path = "/path/to/your/file.txt"
new_source = api.data_source.upload_file(chatbot_uuid, file_path)
print(new_source.uuid, new_source.title)

Requirements

  • Python >= 3.7
  • requests library

Contributing

  1. Fork the repository.
  2. Create a feature branch.
  3. Commit your changes.
  4. Push to your branch.
  5. Submit a pull request.

License

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


Support

If you encounter any issues or have questions, please open an issue in the GitHub repository.


Authors

Key Sections

  1. Features:
    • Highlights what the library can do.
  2. Installation:
    • Instructions for installing the package.
  3. Usage:
    • Code examples for common operations.
  4. Requirements:
    • Dependencies for the library.
  5. Contributing:
    • Instructions for contributing to the project.
  6. License:
    • Licensing information.
  7. Support:
    • Instructions for getting help or reporting issues.
  8. Authors:
    • Credits to the creator(s).

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.2.3] - 2025-01-23

Added

  • Added test cases and improved flow.

[0.2.2] - 2025-01-23

Added

  • Handled 400 bad request to show the respons on error raise.

[0.2.1] - 2025-01-23

Added

  • Added stream_message method to MessageAPI:
    • Supports real-time streaming of chatbot responses from the GPT Trainer API.
    • Returns concatenated streamed response as a single string.
  • Added full support for managing session messages, including:
    • Listing messages (list_messages).
    • Deleting individual messages (delete_message).
    • Bulk deleting messages (bulk_delete_messages).

Changed

  • Improved error handling and documentation for MessageAPI.

[0.2.0] - 2025-01-23

Added

  • Implemented full support for Data Sources, including:
    • File upload
    • Adding QA pairs
    • Adding URLs
    • Bulk deletion of sources
    • Re-scraping URLs.
  • Unified API client GPTTrainerAPI for easy access to all APIs.

Changed

  • Improved source_api.py with additional methods for managing data sources.

[0.1.0] - 2025-01-20

Added

  • Initial release of gpt_trainer_api:
    • Chatbot management.
    • Agent management.
    • Session creation and message handling.
    • Basic data source management.

Metadata

Release files for gpt-trainer-api 0.2.3

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

Source distribution (sdist)

Source distribution for gpt-trainer-api 0.2.3
File Size Uploaded
gpt_trainer_api-0.2.3.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gpt-trainer-api 0.2.3
File Interpreter ABI Platform
gpt_trainer_api-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 38.1 kB

Release files / gpt_trainer_api-0.2.3.tar.gz

Download URL gpt_trainer_api-0.2.3.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
90de37e9b0a2d20d8417e52ea1320d22167144d41a09d33b83f84747ae169b9f
BLAKE2b-256 checksum
How to use checksums
b522f0e65dac6d50dfdf8024971a7b94a4b3f597488744952977d49dca47aba8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / gpt_trainer_api-0.2.3-py3-none-any.whl

Download URL gpt_trainer_api-0.2.3-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d3e2707248cdd8577a490b9595b7a482b754a7d89b329fa1dbf838fc8d1eaa1
BLAKE2b-256 checksum
How to use checksums
43e197e05cc56b3c3c4a0263e0e299b9c3c487600a559218bd3ebb5887e37e43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

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