dragon-bot/app/gpt.py

32 lines
1.0 KiB
Python

import discord
import json
import requests
def answer_question(prompt):
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"]
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"
)
return embed
# answer = answer.replace("```python", "")
# answer = answer.replace("```", "")