Adding in the first pass at llm
This commit is contained in:
parent
3177f0b60c
commit
111ba07190
47
app/bot.py
47
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"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user