feat: API for content

This commit is contained in:
2026-04-06 17:36:09 +08:00
parent ad0add4500
commit 295cf12899
3 changed files with 75 additions and 6 deletions

View File

@@ -37,9 +37,12 @@ class KnowledgeContextService
}
$context .= $snippet . "\n\n";
$fullContent = $document->getMarkdownContent() ?? '';
$sources[] = [
'title' => $document->title,
'id' => 'kb-doc-' . str_pad($document->id, 3, '0', STR_PAD_LEFT),
'id' => $document->id,
'total_lines' => $fullContent !== '' ? substr_count($fullContent, "\n") + 1 : 0,
];
}
@@ -52,11 +55,12 @@ class KnowledgeContextService
private function extractSnippet($document): string
{
$content = $document->getMarkdownContent() ?? $document->description ?? '';
$header = "{$document->title}】(ID:{$document->id})";
if (mb_strlen($content) <= 500) {
return "{$document->title}\n{$content}";
return "{$header}\n{$content}";
}
return "{$document->title}\n" . mb_substr($content, 0, 500) . '...';
return "{$header}\n" . mb_substr($content, 0, 500) . '...';
}
}