chatbot/functions.py

25 lines
938 B
Python
Raw Normal View History

2024-02-06 01:00:41 +00:00
import ollama
2024-02-06 01:21:53 +00:00
import scraper_functions as sf
2024-02-05 23:40:23 +00:00
def processmsg(msg, rcpt):
if "youtube.com/watch" in msg:
2024-02-06 00:03:54 +00:00
return msg.replace("youtube.com", "iv.datura.network")
elif msg.startswith("!wiki"):
2024-02-06 01:49:40 +00:00
cmd, query = msg.split(" ", 1)
return sf.query_external_website("https://en.wikipedia.org/wiki/", query)
2024-02-06 01:13:36 +00:00
elif "good bot" in msg:
return "^_^"
2024-02-06 00:03:54 +00:00
def command(msg, rcpt):
if msg.startswith("!help"):
2024-02-06 01:07:47 +00:00
response = "chatbot commands:" + "\n"
response += "!help Show this help page" + "\n"
2024-02-06 01:47:01 +00:00
response += "!ai [message] Ask llama2" + "\n"
response += "!wiki [message] Ask wiki"
2024-02-06 01:05:31 +00:00
return response
2024-02-06 01:00:41 +00:00
elif msg.startswith("!ai"):
client = ollama.Client(host='https://ollama.krov.dmz.rs')
response = client.chat(model='llama2-uncensored:latest', messages=[{'role':'user','content':f'{msg[4:]}'}])
return(response['message']['content'])