fixed content mapping
This commit is contained in:
parent
c161a93796
commit
afe77233f9
1 changed files with 8 additions and 6 deletions
|
|
@ -339,7 +339,7 @@ def _registerCoreTools(registry: ToolRegistry, services):
|
||||||
chunks = knowledgeService._knowledgeDb.getContentChunks(fileId)
|
chunks = knowledgeService._knowledgeDb.getContentChunks(fileId)
|
||||||
textChunks = [
|
textChunks = [
|
||||||
c for c in (chunks or [])
|
c for c in (chunks or [])
|
||||||
if c.get("contentType") == "text" and c.get("data")
|
if c.get("contentType") != "image" and c.get("data")
|
||||||
]
|
]
|
||||||
if textChunks:
|
if textChunks:
|
||||||
assembled = "\n\n".join(c["data"] for c in textChunks)
|
assembled = "\n\n".join(c["data"] for c in textChunks)
|
||||||
|
|
@ -389,7 +389,8 @@ def _registerCoreTools(registry: ToolRegistry, services):
|
||||||
|
|
||||||
contentObjects = []
|
contentObjects = []
|
||||||
for part in extracted.parts:
|
for part in extracted.parts:
|
||||||
ct = "image" if part.typeGroup == "image" else ("text" if part.typeGroup == "text" else "other")
|
tg = (part.typeGroup or "").lower()
|
||||||
|
ct = "image" if tg == "image" else "text"
|
||||||
if not part.data or not part.data.strip():
|
if not part.data or not part.data.strip():
|
||||||
continue
|
continue
|
||||||
contentObjects.append({
|
contentObjects.append({
|
||||||
|
|
@ -414,7 +415,7 @@ def _registerCoreTools(registry: ToolRegistry, services):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
textParts = [o["data"] for o in contentObjects if o["contentType"] == "text"]
|
textParts = [o["data"] for o in contentObjects if o["contentType"] != "image"]
|
||||||
if textParts:
|
if textParts:
|
||||||
joined = "\n\n".join(textParts)
|
joined = "\n\n".join(textParts)
|
||||||
if len(joined) > _MAX_TOOL_RESULT_CHARS:
|
if len(joined) > _MAX_TOOL_RESULT_CHARS:
|
||||||
|
|
@ -427,7 +428,7 @@ def _registerCoreTools(registry: ToolRegistry, services):
|
||||||
return ToolResult(
|
return ToolResult(
|
||||||
toolCallId="", toolName="readFile", success=True,
|
toolCallId="", toolName="readFile", success=True,
|
||||||
data=f"[Extracted {len(contentObjects)} content objects from '{fileName}' "
|
data=f"[Extracted {len(contentObjects)} content objects from '{fileName}' "
|
||||||
f"({imgCount} images, 0 text). "
|
f"({imgCount} images, no readable text). "
|
||||||
f"Use describeImage(fileId='{fileId}') to analyze visual content.]",
|
f"Use describeImage(fileId='{fileId}') to analyze visual content.]",
|
||||||
)
|
)
|
||||||
except Exception as extractErr:
|
except Exception as extractErr:
|
||||||
|
|
@ -1252,7 +1253,7 @@ def _registerCoreTools(registry: ToolRegistry, services):
|
||||||
if not objects:
|
if not objects:
|
||||||
return ToolResult(toolCallId="", toolName="summarizeContent", success=True, data="No content found to summarize.")
|
return ToolResult(toolCallId="", toolName="summarizeContent", success=True, data="No content found to summarize.")
|
||||||
|
|
||||||
textParts = [obj.get("data", "") for obj in objects if obj.get("contentType") == "text"]
|
textParts = [obj.get("data", "") for obj in objects if obj.get("contentType") != "image"]
|
||||||
combinedText = "\n\n".join(textParts)[:6000]
|
combinedText = "\n\n".join(textParts)[:6000]
|
||||||
|
|
||||||
aiService = services.ai
|
aiService = services.ai
|
||||||
|
|
@ -1383,7 +1384,8 @@ def _registerCoreTools(registry: ToolRegistry, services):
|
||||||
|
|
||||||
contentObjects = []
|
contentObjects = []
|
||||||
for part in extracted.parts:
|
for part in extracted.parts:
|
||||||
ct = "image" if part.typeGroup == "image" else ("text" if part.typeGroup == "text" else "other")
|
tg = (part.typeGroup or "").lower()
|
||||||
|
ct = "image" if tg == "image" else "text"
|
||||||
if not part.data or not part.data.strip():
|
if not part.data or not part.data.strip():
|
||||||
continue
|
continue
|
||||||
contentObjects.append({
|
contentObjects.append({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue