feat: use language-neutral English prompts for multilingual LLM responses
Convert all LLM-facing prompts, templates, and tool output labels to language-neutral English so the model responds in the user's input language. Update frontend relevance/match-type mappings to match. Output language strategy: - User-facing: reply in user's input language - Vector-indexed: match source document language - LLM-internal: fixed English
This commit is contained in:
@@ -15,7 +15,7 @@ var listKnowledgeChunksTool = BaseTool{
|
||||
description: `Retrieve full chunk content for a document by knowledge_id.
|
||||
|
||||
## Use After grep_chunks or knowledge_search:
|
||||
1. grep_chunks(["keyword", "变体"]) → get knowledge_id
|
||||
1. grep_chunks(["keyword", "variant"]) → get knowledge_id
|
||||
2. list_knowledge_chunks(knowledge_id) → read full content
|
||||
|
||||
## When to Use:
|
||||
@@ -245,52 +245,52 @@ func (t *ListKnowledgeChunksTool) buildOutput(
|
||||
chunks []*types.Chunk,
|
||||
) string {
|
||||
builder := &strings.Builder{}
|
||||
builder.WriteString("=== 知识文档分块 ===\n\n")
|
||||
builder.WriteString("=== Knowledge Document Chunks ===\n\n")
|
||||
|
||||
if knowledgeTitle != "" {
|
||||
fmt.Fprintf(builder, "文档: %s (%s)\n", knowledgeTitle, knowledgeID)
|
||||
fmt.Fprintf(builder, "Document: %s (%s)\n", knowledgeTitle, knowledgeID)
|
||||
} else {
|
||||
fmt.Fprintf(builder, "文档 ID: %s\n", knowledgeID)
|
||||
fmt.Fprintf(builder, "Document ID: %s\n", knowledgeID)
|
||||
}
|
||||
fmt.Fprintf(builder, "总分块数: %d\n", total)
|
||||
fmt.Fprintf(builder, "Total chunks: %d\n", total)
|
||||
|
||||
if fetched == 0 {
|
||||
builder.WriteString("未找到任何分块,请确认文档是否已完成解析。\n")
|
||||
builder.WriteString("No chunks found. Please confirm the document has been parsed.\n")
|
||||
if total > 0 {
|
||||
builder.WriteString("文档存在但当前页数据为空,请检查分页参数。\n")
|
||||
builder.WriteString("Document exists but the current page is empty. Please check pagination parameters.\n")
|
||||
}
|
||||
return builder.String()
|
||||
}
|
||||
fmt.Fprintf(
|
||||
builder,
|
||||
"本次拉取: %d 条, 检索范围: %d - %d\n\n",
|
||||
"Fetched: %d chunks, range: %d - %d\n\n",
|
||||
fetched,
|
||||
chunks[0].ChunkIndex,
|
||||
chunks[len(chunks)-1].ChunkIndex,
|
||||
)
|
||||
|
||||
builder.WriteString("=== 分块内容预览 ===\n\n")
|
||||
builder.WriteString("=== Chunk Content Preview ===\n\n")
|
||||
for idx, c := range chunks {
|
||||
fmt.Fprintf(builder, "Chunk #%d (Index %d)\n", idx+1, c.ChunkIndex+1)
|
||||
fmt.Fprintf(builder, " chunk_id: %s\n", c.ID)
|
||||
fmt.Fprintf(builder, " 类型: %s\n", c.ChunkType)
|
||||
fmt.Fprintf(builder, " 内容: %s\n", summarizeContent(c.Content))
|
||||
fmt.Fprintf(builder, " Type: %s\n", c.ChunkType)
|
||||
fmt.Fprintf(builder, " Content: %s\n", summarizeContent(c.Content))
|
||||
|
||||
// 输出关联的图片信息
|
||||
// Output associated image information
|
||||
if c.ImageInfo != "" {
|
||||
var imageInfos []types.ImageInfo
|
||||
if err := json.Unmarshal([]byte(c.ImageInfo), &imageInfos); err == nil && len(imageInfos) > 0 {
|
||||
fmt.Fprintf(builder, " 关联图片 (%d):\n", len(imageInfos))
|
||||
fmt.Fprintf(builder, " Associated images (%d):\n", len(imageInfos))
|
||||
for imgIdx, img := range imageInfos {
|
||||
fmt.Fprintf(builder, " 图片 %d:\n", imgIdx+1)
|
||||
fmt.Fprintf(builder, " Image %d:\n", imgIdx+1)
|
||||
if img.URL != "" {
|
||||
fmt.Fprintf(builder, " URL: %s\n", img.URL)
|
||||
}
|
||||
if img.Caption != "" {
|
||||
fmt.Fprintf(builder, " 描述: %s\n", img.Caption)
|
||||
fmt.Fprintf(builder, " Caption: %s\n", img.Caption)
|
||||
}
|
||||
if img.OCRText != "" {
|
||||
fmt.Fprintf(builder, " OCR文本: %s\n", img.OCRText)
|
||||
fmt.Fprintf(builder, " OCR Text: %s\n", img.OCRText)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,7 +299,7 @@ func (t *ListKnowledgeChunksTool) buildOutput(
|
||||
}
|
||||
|
||||
if int64(fetched) < total {
|
||||
builder.WriteString("提示:文档仍有更多分块,可调整 offset 或多次调用以获取全部内容。\n")
|
||||
builder.WriteString("Note: The document has more chunks. Adjust offset or make multiple calls to retrieve all content.\n")
|
||||
}
|
||||
|
||||
return builder.String()
|
||||
@@ -309,7 +309,7 @@ func (t *ListKnowledgeChunksTool) buildOutput(
|
||||
func summarizeContent(content string) string {
|
||||
cleaned := strings.TrimSpace(content)
|
||||
if cleaned == "" {
|
||||
return "(空内容)"
|
||||
return "(empty)"
|
||||
}
|
||||
|
||||
return strings.TrimSpace(string(cleaned))
|
||||
|
||||
Reference in New Issue
Block a user