add: 添加命令ai model list的逻辑

This commit is contained in:
taylor
2024-10-13 19:52:35 +08:00
parent cae9dc5c78
commit c5b8566d83
4 changed files with 13 additions and 15 deletions

View File

@@ -141,15 +141,15 @@ class AiBotPlugin(Plugin):
if use_platform == 'local_ai': if use_platform == 'local_ai':
type = self.config['platforms']['local_ai']['type'] type = self.config['platforms']['local_ai']['type']
if type == 'ollama': if type == 'ollama':
return Ollama(self.config, self.name, self.http) return Ollama(self.config, self.http)
elif type == 'lmstudio': elif type == 'lmstudio':
return LmStudio(self.config, self.name, self.http) return LmStudio(self.config, self.http)
else: else:
raise ValueError(f"not found platform type: {type}") raise ValueError(f"not found platform type: {type}")
if use_platform == 'openai': if use_platform == 'openai':
return OpenAi(self.config, self.name, self.http) return OpenAi(self.config, self.http)
if use_platform == 'anthropic': if use_platform == 'anthropic':
return Anthropic(self.config, self.name, self.http) return Anthropic(self.config, self.http)
raise ValueError(f"unknown backend type {use_platform}") raise ValueError(f"unknown backend type {use_platform}")
""" """

View File

@@ -14,8 +14,8 @@ from maubot_llmplus.platforms import Platform, ChatCompletion
class Ollama(Platform): class Ollama(Platform):
chat_api: str chat_api: str
def __init__(self, config: BaseProxyConfig, name: str, http: ClientSession) -> None: def __init__(self, config: BaseProxyConfig, http: ClientSession) -> None:
super().__init__(config, name, http) super().__init__(config, http)
self.chat_api = '/api/chat' self.chat_api = '/api/chat'
async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion: async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion:
@@ -55,8 +55,8 @@ class Ollama(Platform):
class LmStudio(Platform): class LmStudio(Platform):
def __init__(self, config: BaseProxyConfig, name: str, http: ClientSession) -> None: def __init__(self, config: BaseProxyConfig, http: ClientSession) -> None:
super().__init__(config, name, http) super().__init__(config, http)
pass pass
async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion: async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion:

View File

@@ -33,9 +33,8 @@ class Platform:
additional_prompt: List[dict] additional_prompt: List[dict]
system_prompt: str system_prompt: str
max_context_messages: int max_context_messages: int
name: str
def __init__(self, config: BaseProxyConfig, name: str, http: ClientSession) -> None: def __init__(self, config: BaseProxyConfig, http: ClientSession) -> None:
self.http = http self.http = http
self.config = config['platforms'][self.get_type()] self.config = config['platforms'][self.get_type()]
self.url = self.config['url'] self.url = self.config['url']
@@ -45,7 +44,6 @@ class Platform:
self.max_context_messages = self.config['max_context_messages'] self.max_context_messages = self.config['max_context_messages']
self.additional_prompt = config['additional_prompt'] self.additional_prompt = config['additional_prompt']
self.system_prompt = config['system_prompt'] self.system_prompt = config['system_prompt']
self.name = name
"""a """a
调用AI对话接口, 响应结果 调用AI对话接口, 响应结果

View File

@@ -8,8 +8,8 @@ from maubot_llmplus.platforms import Platform, ChatCompletion
class OpenAi(Platform): class OpenAi(Platform):
def __init__(self, config: BaseProxyConfig, name: str, http: ClientSession) -> None: def __init__(self, config: BaseProxyConfig, http: ClientSession) -> None:
super().__init__(config, name, http) super().__init__(config, http)
async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion: async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion:
# 获取系统提示词 # 获取系统提示词
@@ -23,8 +23,8 @@ class OpenAi(Platform):
class Anthropic(Platform): class Anthropic(Platform):
def __init__(self, config: BaseProxyConfig, name: str, http: ClientSession) -> None: def __init__(self, config: BaseProxyConfig, http: ClientSession) -> None:
super().__init__(config, name, http) super().__init__(config, http)
async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion: async def create_chat_completion(self, plugin: Plugin, evt: MessageEvent) -> ChatCompletion:
# 获取系统提示词 # 获取系统提示词