Created
June 20, 2023 19:25
-
-
Save infrony/d3a811ba5516747e8289890bf67ef36f to your computer and use it in GitHub Desktop.
Python ChatGPT Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import openai | |
from dotenv import load_dotenv | |
load_dotenv() | |
openai.api_key = os.getenv("OPENAPI_KEY") | |
question = input("What is your question for ChatGTP? ") | |
response = openai.ChatCompletion.create( | |
model="gpt-3.5-turbo", | |
messages=[ | |
{"role": "system", "content": "You are a chatbot"}, | |
{"role": "user", "content": f"{ question }" }, | |
] | |
) | |
result = '' | |
for choice in response.choices: | |
result = choice.message.content | |
print(f"We asked chatGPT { question } - here is their response: ") | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment