mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-20 11:26:07 +00:00
feat: external knowledge bases (#1783)
* Initial plan * Add backend support for external knowledge bases Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * Add frontend support for external knowledge bases with tabs UI Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * Add i18n translations for all languages (Traditional Chinese and Japanese) Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * Update knowledge base tab list styling to match plugins page Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * perf: margin-top for kb page * refactor: switch RetrievalResultEntry to langbot_plugin pkg ones * feat: knowledge retriever listing and creating * stash * refactor: unify sync mechanism for polymorphic components * feat: use unified retireval result struct in retrieval test page * chore: remove unused methods * feat: retriever icon displaying * feat: localagent retrieval with external kbs * chore: bump version of langbot-plugin to 0.2.0b1 * fix: i18n --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> Co-authored-by: Junyan Qin <rockchinq@gmail.com>
This commit is contained in:
@@ -48,11 +48,36 @@ export default function KBRetrieve({ kbId }: KBRetrieveProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const getFileName = (fileId: string) => {
|
||||
const getFileName = (fileId?: string) => {
|
||||
if (!fileId) return '';
|
||||
const file = files.find((f) => f.uuid === fileId);
|
||||
return file?.file_name || fileId;
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract text content from the content array
|
||||
* The content array may contain multiple items with type 'text'
|
||||
*/
|
||||
const extractTextFromContent = (result: RetrieveResult): string => {
|
||||
// First try to get content from the new format
|
||||
if (result.content && Array.isArray(result.content)) {
|
||||
const textParts = result.content
|
||||
.filter((item) => item.type === 'text' && item.text)
|
||||
.map((item) => item.text);
|
||||
|
||||
if (textParts.length > 0) {
|
||||
return textParts.join('\n\n');
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to metadata.text for backward compatibility
|
||||
if (result.metadata?.text) {
|
||||
return result.metadata.text as string;
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex gap-2">
|
||||
@@ -87,7 +112,7 @@ export default function KBRetrieve({ kbId }: KBRetrieveProps) {
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm whitespace-pre-wrap">
|
||||
{result.metadata.text}
|
||||
{extractTextFromContent(result)}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user