feat: API for content
This commit is contained in:
@@ -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) . '...';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user