Skip to content

Instantly share code, notes, and snippets.

@infrony
Created June 20, 2023 19:25
Show Gist options
  • Save infrony/d3a811ba5516747e8289890bf67ef36f to your computer and use it in GitHub Desktop.
Save infrony/d3a811ba5516747e8289890bf67ef36f to your computer and use it in GitHub Desktop.
Python ChatGPT Client
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