make the /gpt function useable
This commit is contained in:
parent
03295c5b04
commit
7b49aaa8ff
@ -1,3 +1,4 @@
|
||||
import discord
|
||||
from discord import option
|
||||
from discord.ext import commands
|
||||
|
||||
@ -7,24 +8,59 @@ class Gpt(commands.Cog):
|
||||
self.bot: commands.Bot = bot
|
||||
|
||||
@commands.slash_command(
|
||||
guild_ids=None,
|
||||
guld_ids=None,
|
||||
name="gpt",
|
||||
description="Ask dalebot a question, he'll do his best to answer",
|
||||
description="Talk to an LLM",
|
||||
)
|
||||
@option(name="question", description="The question to ask", required=True)
|
||||
@option(
|
||||
name="prompt",
|
||||
description="What you want to ask dale-bot",
|
||||
required=True,
|
||||
name="temperature", description="I dunno", min_value=0, max_value=1, default=0.1
|
||||
)
|
||||
async def gpt(self, ctx: commands.Context, prompt):
|
||||
import gpt
|
||||
@option(name="top_p", description="I dunno", min_value=0, max_value=1, default=0.75)
|
||||
@option(name="top_k", description="I dunno", min_value=0, max_value=100, default=40)
|
||||
@option(name="beams", description="I dunno", min_value=0, max_value=4, default=4)
|
||||
@option(
|
||||
name="tokens", description="I dunno", min_value=1, max_value=512, default=128
|
||||
)
|
||||
async def gpt(
|
||||
self,
|
||||
ctx,
|
||||
question: str,
|
||||
temperature: int,
|
||||
top_p: int,
|
||||
top_k: int,
|
||||
beams: int,
|
||||
tokens: int,
|
||||
):
|
||||
import requests
|
||||
|
||||
# try:
|
||||
await ctx.defer()
|
||||
embed = gpt.answer_question(prompt, user=ctx.author.name)
|
||||
await ctx.send_followup(embed=embed)
|
||||
# except Exception as e:
|
||||
# await ctx.send(e)
|
||||
response = requests.post(
|
||||
"https://tloen-alpaca-lora.hf.space/run/predict",
|
||||
json={
|
||||
"data": [
|
||||
question,
|
||||
"You live in California in Silicon valley. You are a computer program that is running in a kubernetes cluster. The cluster is comprised of 3 Thinkcentre M92p tiny computers. Your hobbies include racing cars, eating ice cream, and petting dogs.",
|
||||
float(temperature),
|
||||
float(top_p),
|
||||
float(top_k),
|
||||
int(beams),
|
||||
int(tokens),
|
||||
]
|
||||
},
|
||||
).json()
|
||||
|
||||
data = response["data"][0]
|
||||
|
||||
embed = discord.Embed(
|
||||
description=data,
|
||||
color=discord.Color.green(),
|
||||
type="rich",
|
||||
)
|
||||
|
||||
embed.set_author(name="You asked me: %s" % question)
|
||||
|
||||
await ctx.followup.send(embed=embed)
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
16
app/gpt.py
16
app/gpt.py
@ -1,16 +0,0 @@
|
||||
import discord
|
||||
import os
|
||||
|
||||
import openai
|
||||
|
||||
|
||||
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"
|
||||
|
||||
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||
|
||||
completion = openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo", messages=[{"role": user, "content": prompt}]
|
||||
)
|
||||
|
||||
return completion.choices[0].message
|
@ -1,26 +0,0 @@
|
||||
apiVersion: argoproj.io/v1alpha1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: dragon-bot
|
||||
namespace: argocd
|
||||
spec:
|
||||
project: default
|
||||
source:
|
||||
repoURL: git@git.luker.fr:ldooks/dragon-bot.git
|
||||
targetRevision: HEAD
|
||||
path: helm
|
||||
destination:
|
||||
server: https://kubernetes.default.svc
|
||||
namespace: default
|
||||
syncPolicy:
|
||||
automated:
|
||||
prune: true
|
||||
selfHeal: true
|
||||
retry:
|
||||
limit: 2
|
||||
backoff:
|
||||
duration: 5s
|
||||
factor: 2
|
||||
maxDuration: 3m0s
|
||||
syncOptions:
|
||||
- PruneLast=true
|
Loading…
x
Reference in New Issue
Block a user