wzqvip / OpenAI_Simple_ChatBOT

simple openai chatbot written by chatGPT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpenAI_Simple_ChatBOT

This is generated by GPT-4 Model.

If you are in restricted country, you'll neen to use global proxy and uncomment the setting for Disable SSL verify( in the python file ).

Get you API

To get an API key from OpenAI, you need to sign up for their API access. Please follow these steps:

  1. Visit the OpenAI signup page: https://beta.openai.com/signup/
  2. Fill in the required information, such as your name, email, and password.
  3. After signing up, you will receive an email to confirm your account. Click the link in the email to confirm your registration.
  4. Log in to your OpenAI account: https://beta.openai.com/login/
  5. Once logged in, navigate to the API Keys section: https://beta.openai.com/account/api-keys/
  6. Click the "Create" button to generate a new API key. You can now use this key to access the OpenAI API.

Keep your API key secure, and don't share it with anyone. When using the key in your Python program, as shown in the previous example, it is recommended to set the key as an environment variable rather than hardcoding it in your code. This way, your key remains protected, and you can easily update or revoke it as needed.

Setup the chat bot

  1. Set up a Python virtual environment and install the openai package:
python -m venv venv source venv/bin/activate # For Linux and macOS venv\Scripts\activate # For Windows pip install openai
  1. Set your API key as an environment variable:
export OPENAI_API_KEY="your_api_key_here" # For Linux and macOS set OPENAI_API_KEY="your_api_key_here" # For Windows cmd $env:OPENAI_API_KEY="your_api_key_here" # For Windows powershell
  1. Run the main.py script:
python main.py

This program will allow you to interact with the GPT model. Type your input and press enter to get a response from the model. Type 'quit' and press enter to exit the program.

Please note that this example uses the text-davinci-002 engine. You can replace it with other engines, depending on your API access and requirements.

About

simple openai chatbot written by chatGPT

License:MIT License


Languages

Language:Python 100.0%