XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Update run_tools.py

ddaac019
H Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +2 -29
Modified g4f/tools/run_tools.py +2 -29
@@ -409,9 +409,10 @@ async def async_iter_run_tools(
409 409 "label": usage_label,
410 410 **usage.get_dict(),
411 411 }
412 prompt_tokens = usage_dict.get("prompt_tokens", 0)
412 413 if saved_tokens:
413 414 usage_dict["saved_tokens"] = saved_tokens
414 prompt_tokens = usage_dict.get("prompt_tokens", 0) + saved_tokens
415 prompt_tokens += saved_tokens
415 416 saved_percent = round(saved_tokens / prompt_tokens * 100) if prompt_tokens > 0 and saved_tokens > 0 else 0
416 417 debug.log(f"Token savings:", (f"{int(saved_tokens/1000)}k" if saved_tokens >= 1000 else str(saved_tokens)) + f"/{prompt_tokens} tokens ({saved_percent}%)")
417 418 cached_tokens = usage_dict.get("prompt_tokens_details", usage_dict).get("cached_tokens", 0)
@@ -542,34 +543,6 @@ def iter_run_tools(
542 543 raise_search_exceptions=True,
543 544 **tool["function"]["arguments"],
544 545 )
545 elif function_name == TOOL_NAMES["CONTINUE"]:
546 if provider.__name__ not in ("OpenaiAccount", "HuggingFace"):
547 last_line = messages[-1]["content"].strip().splitlines()[-1]
548 content = f"Carry on from this point:\n{last_line}"
549 messages.append({"role": "user", "content": content})
550 else:
551 # Enable provider native continue
552 kwargs["action"] = "continue"
553 elif function_name == TOOL_NAMES["BUCKET"]:
554
555 def on_bucket(match):
556 return "".join(read_bucket(get_bucket_dir(match.group(1))))
557
558 has_bucket = False
559 for message in messages:
560 if "content" in message and isinstance(message["content"], str):
561 new_message_content = re.sub(
562 r'{"bucket_id":"([^"]*)"}',
563 on_bucket,
564 message["content"],
565 )
566 if new_message_content != message["content"]:
567 has_bucket = True
568 message["content"] = new_message_content
569 last_message = messages[-1]["content"]
570 if has_bucket and isinstance(last_message, str):
571 if "\nSource: " in last_message:
572 messages[-1]["content"] = last_message + BUCKET_INSTRUCTIONS
573 546
574 547 # Build a cache key from all messages except the last user message and the
575 548 # last assistant/bot response. A cache hit supplies the cached