add: 添加ollama调用AI chat逻辑

This commit is contained in:
taylor
2024-10-13 16:46:13 +08:00
parent 2a8054b36a
commit 9199aacc69
4 changed files with 9 additions and 7 deletions

View File

@@ -116,7 +116,7 @@ class AiBotPlugin(Plugin):
await event.mark_read()
await self.client.set_typing(event.room_id, timeout=99999)
platform = self.get_ai_platform()
chat_completion = await platform.create_chat_completion(event)
chat_completion = await platform.create_chat_completion(self, event)
# ai gpt调用
# 关闭typing提示
await self.client.set_typing(event.room_id, timeout=0)

View File

@@ -1,6 +1,7 @@
import json
from aiohttp import ClientSession
from maubot import Plugin
from mautrix.types import MessageEvent
from mautrix.util.config import BaseProxyConfig
@@ -16,9 +17,9 @@ class Ollama(Platform):
super().__init__(config, http)
self.chat_api = '/api/chat'
async def create_chat_completion(self, evt: MessageEvent) -> ChatCompletion:
async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion:
full_context = []
context = maubot_llmplus.platforms.get_context(evt)
context = maubot_llmplus.platforms.get_context(plugin, evt)
full_context.extend(list(context))
endpoint = f"{self.url}/api/chat"
@@ -50,5 +51,5 @@ class LmStudio(Platform):
super().__init__(config, http)
pass
async def create_chat_completion(self, evt: MessageEvent) -> ChatCompletion:
async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion:
pass

View File

@@ -49,7 +49,7 @@ class Platform:
调用AI对话接口, 响应结果
"""
async def create_chat_completion(self, evt: MessageEvent) -> ChatCompletion:
async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion:
raise NotImplementedError()
def get_type(self) -> str:

View File

@@ -1,4 +1,5 @@
from aiohttp import ClientSession
from maubot import Plugin
from mautrix.types import MessageEvent
from mautrix.util.config import BaseProxyConfig
@@ -10,7 +11,7 @@ class OpenAi(Platform):
def __init__(self, config: BaseProxyConfig, http: ClientSession) -> None:
super().__init__(config, http)
async def create_chat_completion(self, evt: MessageEvent) -> ChatCompletion:
async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion:
# 获取系统提示词
# 获取额外的其他角色的提示词: role: user role: system
@@ -25,7 +26,7 @@ class Anthropic(Platform):
def __init__(self, config: BaseProxyConfig, http: ClientSession) -> None:
super().__init__(config, http)
async def create_chat_completion(self, evt: MessageEvent) -> ChatCompletion:
async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion:
# 获取系统提示词
# 获取额外的其他角色的提示词: role: user role: system