Skip to main content

Python client for interacting with the GPT Trainer API.

Project description

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).

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

gpt_trainer_api-0.1.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

gpt_trainer_api-0.1.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file gpt_trainer_api-0.1.0.tar.gz.

File metadata

  • Download URL: gpt_trainer_api-0.1.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for gpt_trainer_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7b205920ae823d300cd4a3ad398f0dd6a743159866e28dcd21873493be6674c7
MD5 9e05f3543404789228e1bb2c92c0c7c6
BLAKE2b-256 5b36952e77c232a65327d312c1961ee0c05414a67c9a778919808dd20ca6217e

See more details on using hashes here.

File details

Details for the file gpt_trainer_api-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gpt_trainer_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c37faf7b38101d04e0117054bf84b1b629973b64e7d52cd09e2d337fcefc4eb6
MD5 0d6c976f17bdd2ddf0cb6fba4bf47097
BLAKE2b-256 31f35a332d94e3b5aab148088a45111ad62fa8310040ba9e74b7028ac93daaaf

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