From 111ba07190e4605a9d6b51a5ea606c0f4dbec9dc Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Fri, 5 Apr 2024 23:16:56 -0700 Subject: [PATCH] Adding in the first pass at llm --- app/bot.py | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/app/bot.py b/app/bot.py index dc51e7b5..70681f47 100755 --- a/app/bot.py +++ b/app/bot.py @@ -2,6 +2,7 @@ from discord.ext import commands import discord import os +import requests import requests_cache intents = discord.Intents.default() @@ -155,16 +156,44 @@ async def fix_social_media_links(ctx): @bot.event async def on_message(ctx): if str(bot.user.id) in ctx.content: - import wolframalpha - client = wolframalpha.Client(os.getenv("wolfram_token")) - query = " ".join(ctx.content.split()[1:]) - try: - res = client.query(query) - return await ctx.reply(next(res.results).text) - except Exception as e: - print(e) - return await ctx.reply("Sorry, I'm unable to answer that") + url = "http://192.168.1.52:1337/v1/chat/completions" + bot_prompt = ( + "You are a helpful assistant. You will answer questions conciesely" + "and as detailed as possible. You are based out of the United states in California." + ) + + payload = { + "messages": [ + { + "content": bot_prompt, + "role": "system", + }, + { + "content": ctx.content.replace(str(bot.user.id), "").replace( + "<@> ", "" + ), + "role": "user", + }, + ], + "model": "openchat-3.5-7b", + "stream": False, + "max_tokens": 4096, + "stop": ["hello"], + "frequency_penalty": 0, + "presence_penalty": 0, + "temperature": 0.7, + "top_p": 0.95, + } + headers = {"Content-Type": "application/json"} + + response = requests.post(url, json=payload, headers=headers) + + await ctx.reply( + response.json()["choices"][0]["message"]["content"].replace( + "<|end_of_turn|>", "" + ) + ) bot.run(os.getenv("discord_token"))