Chat GPT Python
ChatGPT with Python calling
Config
Create a api key from here:
https://platform.openai.com/account/api-keys
.env
OPEN_AI_APIKEY=xxxxxxxxxxxx
Then add the library with
pip install openai dotenv
Code
chat.py
from dotenv import dotenv_values
import openai
openai.api_key = dotenv_values(".env")["OPEN_AI_APIKEY"]
def gptGen():
result = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{ "role": "user", "content": "Help me to make a instagram post"},
]
)
print(result.choices[0].message.content)
if __name__ == "__main__":
gptGen()