adding openwebui bot
This commit is contained in:
39
ollama/aibot.py
Normal file
39
ollama/aibot.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
from typing import Type
|
||||||
|
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
|
||||||
|
from maubot import Plugin, MessageEvent
|
||||||
|
from maubot.handlers import command
|
||||||
|
|
||||||
|
class Config(BaseProxyConfig):
|
||||||
|
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
||||||
|
helper.copy("api_token")
|
||||||
|
helper.copy("openwebui_url")
|
||||||
|
|
||||||
|
class AIBot(Plugin):
|
||||||
|
|
||||||
|
async def start(self) -> None:
|
||||||
|
await super().start()
|
||||||
|
self.config.load_and_update()
|
||||||
|
|
||||||
|
@command.new("gpt")
|
||||||
|
@command.argument("pattern", pass_raw=True, required=True)
|
||||||
|
async def gpt(self, evt: MessageEvent, pattern: str) -> None:
|
||||||
|
|
||||||
|
token=self.config['api_token']
|
||||||
|
url = self.config['openwebui_url']
|
||||||
|
headers = {
|
||||||
|
'Authorization': 'Bearer '+token
|
||||||
|
}
|
||||||
|
self.log.debug(str(headers))
|
||||||
|
payload = {"model": "llama3.1:latest","messages": [{"role": "user","content": pattern}]}
|
||||||
|
|
||||||
|
async with self.http.post(url,headers=headers,json=payload) as resp:
|
||||||
|
response_json = await resp.json()
|
||||||
|
self.log.debug(str(response_json))
|
||||||
|
self.log.debug(str(response_json['choices'][0]['message']['content']))
|
||||||
|
await evt.respond(str(response_json['choices'][0]['message']['content']))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_config_class(cls) -> Type[BaseProxyConfig]:
|
||||||
|
return Config
|
||||||
2
ollama/base-config.yaml
Normal file
2
ollama/base-config.yaml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
api_token: somestring
|
||||||
|
openwebui_url: http://someurl
|
||||||
9
ollama/maubot.yaml
Normal file
9
ollama/maubot.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
maubot: 0.1.0
|
||||||
|
id: nearfuture.maubot.ai
|
||||||
|
version: 0.1.0
|
||||||
|
modules:
|
||||||
|
- aibot
|
||||||
|
main_class: AIBot
|
||||||
|
config: true
|
||||||
|
extra_files:
|
||||||
|
- base-config.yaml
|
||||||
Reference in New Issue
Block a user