From b5ac289497c9b8c61cb50d90b7500b6c5ebea117 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Fri, 21 Jul 2023 09:03:32 -0700 Subject: [PATCH] make the /gpt function useable --- app/cogs/gpt.py | 60 ++++++++++++++++++++++++++++++++--------- app/gpt.py | 16 ----------- argocd-application.yaml | 26 ------------------ 3 files changed, 48 insertions(+), 54 deletions(-) delete mode 100644 app/gpt.py delete mode 100755 argocd-application.yaml diff --git a/app/cogs/gpt.py b/app/cogs/gpt.py index a64a71dc..e0143f46 100755 --- a/app/cogs/gpt.py +++ b/app/cogs/gpt.py @@ -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): diff --git a/app/gpt.py b/app/gpt.py deleted file mode 100644 index da1b2f42..00000000 --- a/app/gpt.py +++ /dev/null @@ -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 diff --git a/argocd-application.yaml b/argocd-application.yaml deleted file mode 100755 index 8ded4c54..00000000 --- a/argocd-application.yaml +++ /dev/null @@ -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