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.
- Chatbot Interaction: Communicate with a chatbot powered by Puter AI.
- Text-to-Speech (TTS): Convert any text into audio using AWS Polly TTS service.
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.
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
- Clone the Repository
git clone https://github.com/mowhn/PuterAi-python_SDK.git
cd puterAi-python_SDK
- 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
- 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 thecli
andAPI
folders.Note: If you don't have a Puter AI account, you can sign up at
- 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
- 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.
The Flask API exposes the following endpoints:
-
POST
/chat
: Accepts a JSON object with amessage
field and returns a bot response.Example request:
{ "message": "Hello, bot!" }
-
POST
/tts
: Accepts a JSON object with atext
field and returns the corresponding TTS audio.Example request:
{ "text": "Hello, this is a test." }
This project is licensed under the MIT License - see the LICENSE file for details.
Enjoy building with Puter!