diff --git a/README.md b/README.md index a3ec26a39..0dd7c35ce 100644 --- a/README.md +++ b/README.md @@ -192,8 +192,11 @@ Hooks control the EventMessage in sender and receiver. For example, we have `voi you can enable it by setting `VOICE_REPLY_ME=true` in `.env`. ```shell -/env VOICE_REPLY_ME=true +/env VOICE_REPLY_ME=yes +# must + /env REECHO_VOICE_KEY= +# not must ``` use `/env VOICE_REPLY_ME=NONE` to disable this env. diff --git a/app/receiver/function.py b/app/receiver/function.py index bc41ee911..301683b29 100644 --- a/app/receiver/function.py +++ b/app/receiver/function.py @@ -232,6 +232,7 @@ async def run_pending_task(task: TaskHeader, pending_task: ToolCall): async def process_function_call(self, message: AbstractIncomingMessage): """ 定位,解析,运行函数。要求认证,或申请结束/继续指标。 + Receive credential, or a list of function calls, attention, message may queue itself for auth. :param message: message from queue :return: None """ @@ -242,27 +243,39 @@ async def process_function_call(self, message: AbstractIncomingMessage): f"[552351] Received A Function Call from {message.body.decode('utf-8')}" ) task: TaskHeader = TaskHeader.model_validate_json(message.body.decode("utf-8")) - RUN_LIMIT = 6 - while task.task_sign.tool_calls_pending and RUN_LIMIT > 0: + # Get Function Call + pending_task: ToolCall = await task.task_sign.get_pending_tool_call( + tool_calls_pending_now=task.task_sign.snapshot_credential, + return_default_if_empty=False, + ) + if pending_task: + await self.run_task(task=task, pending_task=pending_task) + if task.task_sign.snapshot_credential: + return logger.debug( + f"Received A Credential {task.task_sign.snapshot_credential}, End Run Function Call Loop!" + ) + RUN_LIMIT = 4 + for pending_task in task.task_sign.tool_calls_pending: RUN_LIMIT -= 1 - # Get Function Call - pending_task: ToolCall = await task.task_sign.get_pending_tool_call( - tool_calls_pending_now=task.task_sign.snapshot_credential, - return_default_if_empty=True, + if RUN_LIMIT <= 0: + logger.error("Limit Run Times, Stop Run Function Call Loop!") + break + logger.debug( + f"Received A ToolCall {RUN_LIMIT} {len(task.task_sign.tool_calls_pending)}" ) - if not pending_task: - return logger.debug("But No ToolCall") - logger.debug("Received A ToolCall") - try: - await self.run_pending_task(task=task, pending_task=pending_task) - except Exception as e: - await task.task_sign.complete_task( - tool_calls=pending_task, success_or_not=False, run_result=str(e) - ) - logger.error(f"Function Call Error {e}") - raise e - finally: - logger.trace("Function Call Finished") + await self.run_task(task=task, pending_task=pending_task) + + async def run_task(self, task, pending_task): + try: + await self.run_pending_task(task=task, pending_task=pending_task) + except Exception as e: + await task.task_sign.complete_task( + tool_calls=pending_task, success_or_not=False, run_result=str(e) + ) + logger.error(f"Function Call Error {e}") + raise e + finally: + logger.trace("Function Call Finished") async def on_message(self, message: AbstractIncomingMessage): """ diff --git a/llmkira/extra/plugins/search/__init__.py b/llmkira/extra/plugins/search/__init__.py index 05f4bf689..07f3687e6 100644 --- a/llmkira/extra/plugins/search/__init__.py +++ b/llmkira/extra/plugins/search/__init__.py @@ -63,9 +63,9 @@ class SearchTool(BaseTool): env_prefix: str = "SERPER_" def require_auth(self, env_map: dict) -> bool: - if "SERPER_API_KEY" in env_map: - return False - return True + if env_map.get("SERPER_API_KEY", None) is None: + return True + return False @classmethod def env_help_docs(cls, empty_env: List[str]) -> str: diff --git a/llmkira/kv_manager/instruction.py b/llmkira/kv_manager/instruction.py index 8b8fdb28a..3b04df1de 100644 --- a/llmkira/kv_manager/instruction.py +++ b/llmkira/kv_manager/instruction.py @@ -5,7 +5,7 @@ DEFAULT_INSTRUCTION = ( "[ASSISTANT RULE]" "SPEAK IN MORE CUTE STYLE, DONT REPEAT, ACT STEP BY STEP, CALL USER MASTER, REPLY IN USER " - "LANGUAGE" + "LANGUAGE, ACT STEP BY STEP" "[RULE END]" ) diff --git a/llmkira/openai/request.py b/llmkira/openai/request.py index 91940c5c2..30e8c59c4 100644 --- a/llmkira/openai/request.py +++ b/llmkira/openai/request.py @@ -166,7 +166,7 @@ def make_url(base_url: str): def check_vision(self): if not self.model.startswith(("gpt-4-vision", "gpt-4-turbo", "claude-3")): logger.info( - "Remove the image content part from the messages, because the model is not supported." + "Try to remove the image content part from the messages, because the model is not supported." ) for message in self.messages: if isinstance(message, UserMessage) and isinstance( diff --git a/llmkira/sdk/tools/schema.py b/llmkira/sdk/tools/schema.py index f99abf16f..1ee232444 100644 --- a/llmkira/sdk/tools/schema.py +++ b/llmkira/sdk/tools/schema.py @@ -70,7 +70,7 @@ def require_auth(self, env_map: dict) -> bool: """ Check if authentication is required """ - return False + return True @final def get_os_env(self, env_name):