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.
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.txtgit clone https://github.com/mowhn/PuterAi-python_SDK.git
cd puterAi-python_SDKCreate a .env file in both the cli and API directories and include your API_TOKEN:
API_TOKEN=your_api_token_hereTo 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.pyThis 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
Run the API Server:
cd API
python server.pyThis 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.pyOpen the example.html file in a browser to interact with the Puter chatbot and generate TTS:
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."
}This project is licensed under the MIT License - see the LICENSE file for details.
Enjoy building with Puter!