Skip to content

Commit

Permalink
feat: hello plugin support app code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhayujie committed Nov 29, 2023
1 parent dd36d8c commit 5f19f37
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion bot/linkai/link_ai_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import requests

import config
from bot.bot import Bot
from bot.chatgpt.chat_gpt_session import ChatGPTSession
from bot.session_manager import SessionManager
Expand Down Expand Up @@ -60,7 +61,8 @@ def _chat(self, query, context, retry_count=0) -> Reply:
logger.info(f"[LINKAI] won't set appcode because a plugin ({context['generate_breaked_by']}) affected the context")
app_code = None
else:
app_code = context.kwargs.get("app_code") or conf().get("linkai_app_code")
plugin_app_code = self._find_group_mapping_code(context)
app_code = context.kwargs.get("app_code") or plugin_app_code or conf().get("linkai_app_code")
linkai_api_key = conf().get("linkai_api_key")

session_id = context["session_id"]
Expand Down Expand Up @@ -164,6 +166,18 @@ def _process_image_msg(self, app_code: str, session_id: str, query:str, img_cach
except Exception as e:
logger.exception(e)

def _find_group_mapping_code(self, context):
try:
if context.kwargs.get("isgroup"):
group_name = context.kwargs.get("msg").from_user_nickname
if config.plugin_config and config.plugin_config.get("linkai"):
linkai_config = config.plugin_config.get("linkai")
group_mapping = linkai_config.get("group_app_map")
if group_mapping and group_name:
return group_mapping.get(group_name)
except Exception as e:
logger.exception(e)
return None

def _build_vision_msg(self, query: str, path: str):
try:
Expand Down

0 comments on commit 5f19f37

Please sign in to comment.