Merge branch 'master' into dhk-1
解决 8 处冲突: - app.py:同时挂载 public_embed + html_page_favorites 两个 router - .env:保留 dhk-1 的 CORS 配置(含 5174、ALLOW_ALL=0) - message-list.tsx:并入双方新增(onSetupWriting* 解构 + contentClassName/fitMessageRowsToContent 类型) - WorkspaceRoutes.tsx:采用 master 的路由结构(含 chats_iframe/IframeChatPage),补回 dhk-1 的 BusinessChainEditorPage 导入与 roundtable/chains 路由 - LoginPage.tsx:合并两套登录(master 的 token 换登录 + dhk-1 的 online-ticket),并集依赖数组 - ScheduledTasksPage.tsx:采用 master 的 HTML 定时任务表单(isHtmlTask 分支) - AIWritingForm.tsx:保留 dhk-1 的 useWritingForm 重构,补回 master 的笔记来源 useState;WritingFormContext.materialSource 扩展支持 'notebook' - useAIWritingStream.ts:保留 dhk-1 重构(仅 reducer/helpers,useAIWriting 已移至 AIWritingContext),不并入 master 在此文件的旧实现 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
d49406d2f1
102 files changed
+6816
-6016
No files matched your search
+1
-1
@@ -56,7 +56,7 @@ def notebook_search_tool(query: str, top_k: int = 10) -> str:
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
json={
|
||||
"query": query,
|
||||
"source_ids": [source_ids],
|
||||
"source_ids": source_ids,
|
||||
"search_space_id": search_space_id,
|
||||
"top_k": top_k,
|
||||
},
|
||||
|
||||
+37
-5
@@ -51,20 +51,33 @@ def view_image_tool(
|
||||
runtime: ToolRuntime[ContextT, ThreadState],
|
||||
image_path: str,
|
||||
tool_call_id: Annotated[str, InjectedToolCallId],
|
||||
question: str | None = None,
|
||||
) -> Command:
|
||||
"""Read an image file.
|
||||
"""Read and understand an image file.
|
||||
|
||||
Use this tool to read an image file and make it available for display.
|
||||
This is the ONLY correct way to understand an image. The image is analyzed by
|
||||
the configured vision model and its description/answer is returned to you as
|
||||
the tool result. Treat that result as authoritative.
|
||||
|
||||
When to use the view_image tool:
|
||||
- When you need to view an image file.
|
||||
- Whenever you need to view, describe, or answer a question about an image file.
|
||||
|
||||
When NOT to use the view_image tool:
|
||||
- For non-image files (use present_files instead)
|
||||
- For multiple files at once (use present_files instead)
|
||||
|
||||
IMPORTANT — do NOT attempt to understand images any other way:
|
||||
- Never read, open, decode, or parse an image with read_file, grep, bash,
|
||||
python, PIL/Pillow, OpenCV, EXIF parsing, or byte/hex inspection. Those
|
||||
cannot interpret visual content and will only waste turns.
|
||||
- If `view_image` returns a weak or incomplete description, do not fall back
|
||||
to code. Either call `view_image` again with a more specific `question`,
|
||||
or tell the user the configured vision model could not extract more detail
|
||||
(the vision model may need to be changed in config).
|
||||
|
||||
Args:
|
||||
image_path: Absolute /mnt/user-data virtual path to the image file. Common formats supported: jpg, jpeg, png, webp.
|
||||
question: Optional specific question to ask about the image (e.g. "What is the total on this invoice?"). When omitted, a general detailed description is produced.
|
||||
"""
|
||||
from deerflow.sandbox.exceptions import SandboxRuntimeError
|
||||
from deerflow.sandbox.tools import (
|
||||
@@ -153,8 +166,27 @@ def view_image_tool(
|
||||
mime_type = detected_mime_type
|
||||
image_base64 = base64.b64encode(image_data).decode("utf-8")
|
||||
|
||||
# Update viewed_images in state
|
||||
# The merge_viewed_images reducer will handle merging with existing images
|
||||
# Delegated recognition: when a dedicated vision model is configured, send
|
||||
# the image to that model and return its description as the tool result, so
|
||||
# a text-only main chat model can still "see" the image.
|
||||
from deerflow.models.vision import is_delegated_vision, recognize_image
|
||||
|
||||
if is_delegated_vision():
|
||||
try:
|
||||
description = recognize_image(image_base64, mime_type, question=question)
|
||||
except Exception as e: # noqa: BLE001 - surface as a recoverable tool error
|
||||
return Command(
|
||||
update={"messages": [ToolMessage(f"Error recognizing image: {_sanitize_image_error(e, thread_data)}", tool_call_id=tool_call_id)]},
|
||||
)
|
||||
if not description:
|
||||
description = "The vision model returned an empty description."
|
||||
return Command(
|
||||
update={"messages": [ToolMessage(f"Image recognition result for {image_path}:\n\n{description}", tool_call_id=tool_call_id)]},
|
||||
)
|
||||
|
||||
# Native vision: store the image so ViewImageMiddleware injects it into the
|
||||
# (vision-capable) main model before the next LLM call.
|
||||
# The merge_viewed_images reducer will handle merging with existing images.
|
||||
new_viewed_images = {image_path: {"base64": image_base64, "mime_type": mime_type}}
|
||||
|
||||
return Command(
|
||||
|
||||
@@ -138,11 +138,14 @@ def get_available_tools(
|
||||
if model_name is None and config.models:
|
||||
model_name = config.models[0].name
|
||||
|
||||
# Add view_image_tool only if the model supports vision
|
||||
model_config = config.get_model_config(model_name) if model_name else None
|
||||
if model_config is not None and model_config.supports_vision:
|
||||
# Add view_image_tool when vision is available — either the main model
|
||||
# supports vision natively, or a dedicated vision model is configured
|
||||
# (vision.model_name) so recognition can be delegated to it.
|
||||
from deerflow.models.vision import vision_enabled
|
||||
|
||||
if vision_enabled(model_name, app_config=config):
|
||||
builtin_tools.append(view_image_tool)
|
||||
logger.info(f"Including view_image_tool for model '{model_name}' (supports_vision=True)")
|
||||
logger.info(f"Including view_image_tool for model '{model_name}' (vision available)")
|
||||
|
||||
# Get cached MCP tools if enabled
|
||||
# NOTE: We use ExtensionsConfig.from_file() instead of config.extensions
|
||||
|
||||
Reference in new issue
Block a user