Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auth logic #396

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<key in dev.reecho.ai>
# not must
```

use `/env VOICE_REPLY_ME=NONE` to disable this env.
Expand Down
51 changes: 32 additions & 19 deletions app/receiver/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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):
"""
Expand Down
6 changes: 3 additions & 3 deletions llmkira/extra/plugins/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion llmkira/kv_manager/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
)

Expand Down
2 changes: 1 addition & 1 deletion llmkira/openai/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion llmkira/sdk/tools/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading