A Python script that interacts with the OpenAI API to generate conversational AI responses based on user input. It simulates a chat environment where the AI responds thoughtfully to each message.
-
Create prompt 🎉
-
Select model 🎉
-
Function call 🎉
-
Chat completions mode 🎉
- Streaming
- Without streaming
-
Assistant mode 🎉
- Streaming
- Without streaming
-
Run any commands on local PC 🎉
-
Access website 🎉
This is a function call.
Usage:
You: Check the content of the webpage: example.com (this will parse the html text within the page)
You: Check the full content of the webpage: example.com (this will grad all the content including the js)
-
Get current date and time 🎉
A function call to get the time and date based on the time zone.
-
Get current weather
A function call to get the current weather based on the location. Currently it's a dummy function. Fully implementation needs to register a weather API to fetch the weather data.
-
Read files
A function call.
-
-
Count tokens 🎉
-
tiktoken
Utilizes
tiktoken
for accurate token counting, enabling estimation of the number of tokens used by prompts and responses. This is vital for effectively managing API costs, especially given the diverse pricing models based on token usage. -
Without streaming
- Chat completions
- Assistant
-
Streaming
[!NOTE] The counting of tokens is not supported officially yet.
- Chat completions
- Assistant
-
-
Calculate cost based on tokens and model 🎉
See OpenAI API pricing for more details.
-
Save/Load conversations
-
Without streaming
- Chat completions
- Assistant
-
Streaming
- Chat completions
- Assistant
-
-
Logging
-
Embeddings
-
Image generation
-
Vision
-
Text-to-speech
-
Speech-to-text
-
Moderation
This script leverages the OpenAI API to generate responses, creating an interactive chat experience. Follow these instructions to set up and run the script in your local environment.
- Python 3: Ensure Python 3.10 or newer is installed on your system. Download it from the official Python website.
- OpenAI API Key: A valid OpenAI API key is required for authentication. Obtain one by signing up at OpenAI's API keys page.
- Configuration File: A
.env
file in the same directory as the script is needed. This file stores your API key. ReplaceYOUR_API_KEY
with your actual API key:
OPENAI_API_KEY = YOUR_API_KEY
Before running the script, you need to install the OpenAI Python package. You can do this by running the following command in your terminal:
make
To run the script, follow these steps:
-
Open a terminal and navigate to the directory containing the script.
-
Before using make, ensure you have a Makefile with appropriate commands for executing the script. If you’re not using a Makefile, you can directly run the script using Python:
make run
-
Upon running, you’ll be prompted to enter your message. Type your message and press enter. To send multiple lines, press enter after each line. When finished, press enter twice to send your message to the AI.
-
The script will then process your input, displaying “AI is thinking…” while generating a response. Once completed, it will display the AI’s response.
-
To exit the chat, type exit at the prompt.
Distributed under the MIT License. See LICENSE for more information.
- Jeffrey Cai - Initial work - jeffreyc2017