Skip to content

jeffreyc2017/openai-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI Chat

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.

Features

  • 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

  • Coder

Getting Started

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.

Prerequisites

  • 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. Replace YOUR_API_KEY with your actual API key:
OPENAI_API_KEY = YOUR_API_KEY

Installation

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

Running the Script

To run the script, follow these steps:

  1. Open a terminal and navigate to the directory containing the script.

  2. 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
  3. 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.

  4. The script will then process your input, displaying “AI is thinking…” while generating a response. Once completed, it will display the AI’s response.

  5. To exit the chat, type exit at the prompt.

License

Distributed under the MIT License. See LICENSE for more information.

Author

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published