Skip to content

PuterAi Python SDK provides a simple way to interact with the Puter AI API for chatbot interactions and text-to-speech (TTS) generation. This SDK allows you to integrate chatbot and TTS functionalities into your own applications.

License

Notifications You must be signed in to change notification settings

mowhn/PuterAi-python_SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PuterAi-python_SDK

PuterAi Python SDK provides a simple way to interact with the Puter AI API for chatbot interactions and text-to-speech (TTS) generation. This SDK allows you to integrate chatbot and TTS functionalities into your own applications.

Features

  • Chatbot Interaction: Communicate with a chatbot powered by Puter AI.
  • Text-to-Speech (TTS): Convert any text into audio using AWS Polly TTS service.

Project Structure

The project consists of multiple components:

  • login.py: Script to handle user login and retrieve an API token for further requests.
  • cli.py: Command-line interface that allows users to interact with the Puter chatbot or generate TTS output.
  • server.py: A Flask-based API server that exposes endpoints for chatbot and TTS functionalities.
  • example.html: A simple HTML front-end to interact with the chatbot and generate TTS via a browser.

Requirements

To run this project, you need to install the following dependencies:

  • requests: To handle HTTP requests.
  • flask: For the API server.
  • flask_cors: For handling Cross-Origin Resource Sharing (CORS).
  • dotenv: To load environment variables from a .env file.

You can install the required dependencies with:

pip install -r requirements.txt

Setup Instructions

  1. Clone the Repository
git clone https://github.com/mowhn/PuterAi-python_SDK.git
cd puterAi-python_SDK
  1. Setup .env File in Both CLI and API Folders

Create a .env file in both the cli and API directories and include your API_TOKEN:

API_TOKEN=your_api_token_here
  1. Get the API Token

To quickly obtain your API_TOKEN, you must first run login.py to log in and retrieve the token:

  • Run login.py:

    cd cli
    python login.py

    This will prompt you for your username and password, and if the login is successful, it will output the API_TOKEN. You can copy this token and paste it into the .env file in both the cli and API folders.

    Note: If you don't have a Puter AI account, you can sign up at Sign Up for PuterAI

  1. Running the Project
  • Run the API Server:

    cd API
    python server.py

    This will start the Flask API server on http://localhost:5000.

  • Use the Command-Line Interface (CLI):

    To interact with the chatbot or generate TTS from the command line, run:

    cd cli
    python cli.py
  1. Front-End Example

Open the example.html file in a browser to interact with the Puter chatbot and generate TTS:

  • Chat with the Bot: Enter a message and receive a response from the bot.
  • Generate TTS: Enter text to convert into speech, and play the generated audio.

Endpoints

The Flask API exposes the following endpoints:

  • POST /chat: Accepts a JSON object with a message field and returns a bot response.

    Example request:

    {
      "message": "Hello, bot!"
    }
  • POST /tts: Accepts a JSON object with a text field and returns the corresponding TTS audio.

    Example request:

    {
      "text": "Hello, this is a test."
    }

License

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


Enjoy building with Puter!

About

PuterAi Python SDK provides a simple way to interact with the Puter AI API for chatbot interactions and text-to-speech (TTS) generation. This SDK allows you to integrate chatbot and TTS functionalities into your own applications.

Topics

Resources

License

Stars

Watchers

Forks