diff --git a/app/cogs/gpt.py b/app/cogs/gpt.py index f77cea7e..a64a71dc 100755 --- a/app/cogs/gpt.py +++ b/app/cogs/gpt.py @@ -21,7 +21,7 @@ class Gpt(commands.Cog): # try: await ctx.defer() - embed = gpt.answer_question(prompt) + embed = gpt.answer_question(prompt, user=ctx.author.name) await ctx.send_followup(embed=embed) # except Exception as e: # await ctx.send(e) diff --git a/app/gpt.py b/app/gpt.py index 84de352f..a45505d3 100644 --- a/app/gpt.py +++ b/app/gpt.py @@ -1,31 +1,16 @@ import discord -import json -import requests +import os + +import openai -def answer_question(prompt): +def answer_question(prompt, user): bots_context = "You are located in zipcode 94549. You are a chatbot written in python and you are answering questions for me" - session = requests.Session() - payload = { - "model": "text-davinci-003", - "messages": [ - {"role": "system", "content": bots_context}, - {"role": "user", "content": prompt}, - ], - } - r = requests.post( - "https://sharegpt.churchless.tech/share/v1/chat", - headers={"Content-Type": "application/json"}, - data=json.dumps(payload), - ) - answer = json.loads(r.text)["choices"][0]["message"]["content"] + openai.api_key = os.getenv("OPENAI_API_KEY") - embed = discord.Embed(description=answer, color=discord.Color.green(), type="rich") - embed.set_author(name="You asked me: %s" % prompt) - embed.set_thumbnail( - url="https://cdn.discordapp.com/emojis/1087404359844892712.webp" + completion = openai.ChatCompletion.create( + model="gpt-3.5-turbo", messages=[{"role": user, "content": prompt}] ) - return embed - # answer = answer.replace("```python", "") - # answer = answer.replace("```", "") + + return completion.choices[0].message diff --git a/app/requirements.txt b/app/requirements.txt index 6c275968..85f66d01 100755 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -1,6 +1,6 @@ beautifulsoup4 cmagick -git+https://github.com/pycord-development/pycord@fa0f16030eba9c2b708419a89d57f1d33882659c +git+https://github.com/pycord-development/pycord@eb4fd12eda4f0236532e7b4e2ee71dc5a6bc65d0 gTTS httpx humanfriendly