Adding in the first pass at llm

This commit is contained in:
Luke Robles 2024-04-05 23:16:56 -07:00
parent 3177f0b60c
commit 111ba07190

View File

@ -2,6 +2,7 @@
from discord.ext import commands from discord.ext import commands
import discord import discord
import os import os
import requests
import requests_cache import requests_cache
intents = discord.Intents.default() intents = discord.Intents.default()
@ -155,16 +156,44 @@ async def fix_social_media_links(ctx):
@bot.event @bot.event
async def on_message(ctx): async def on_message(ctx):
if str(bot.user.id) in ctx.content: if str(bot.user.id) in ctx.content:
import wolframalpha
client = wolframalpha.Client(os.getenv("wolfram_token")) url = "http://192.168.1.52:1337/v1/chat/completions"
query = " ".join(ctx.content.split()[1:]) bot_prompt = (
try: "You are a helpful assistant. You will answer questions conciesely"
res = client.query(query) "and as detailed as possible. You are based out of the United states in California."
return await ctx.reply(next(res.results).text) )
except Exception as e:
print(e) payload = {
return await ctx.reply("Sorry, I'm unable to answer that") "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")) bot.run(os.getenv("discord_token"))