mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-18 11:44:18 +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:
@@ -162,6 +162,25 @@ export interface KnowledgeBase {
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface ExternalKnowledgeBase {
|
||||
uuid?: string;
|
||||
name: string;
|
||||
description: string;
|
||||
created_at?: string;
|
||||
plugin_author: string;
|
||||
plugin_name: string;
|
||||
retriever_name: string;
|
||||
retriever_config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface ApiRespExternalKnowledgeBases {
|
||||
bases: ExternalKnowledgeBase[];
|
||||
}
|
||||
|
||||
export interface ApiRespExternalKnowledgeBase {
|
||||
base: ExternalKnowledgeBase;
|
||||
}
|
||||
|
||||
export interface ApiRespKnowledgeBaseFiles {
|
||||
files: KnowledgeBaseFile[];
|
||||
}
|
||||
@@ -295,12 +314,22 @@ export interface ApiRespWebChatMessages {
|
||||
messages: Message[];
|
||||
}
|
||||
|
||||
export interface RetrieveResultContent {
|
||||
type: 'text' | 'image_url' | 'image_base64' | 'file_url';
|
||||
text?: string;
|
||||
file_name?: string;
|
||||
file_url?: string;
|
||||
image_url?: string;
|
||||
image_base64?: string;
|
||||
}
|
||||
|
||||
export interface RetrieveResult {
|
||||
id: string;
|
||||
content?: RetrieveResultContent[];
|
||||
metadata: {
|
||||
file_id: string;
|
||||
text: string;
|
||||
uuid: string;
|
||||
file_id?: string;
|
||||
text?: string;
|
||||
uuid?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
distance: number;
|
||||
|
||||
@@ -36,6 +36,9 @@ import {
|
||||
ApiRespMCPServers,
|
||||
ApiRespMCPServer,
|
||||
MCPServer,
|
||||
ExternalKnowledgeBase,
|
||||
ApiRespExternalKnowledgeBases,
|
||||
ApiRespExternalKnowledgeBase,
|
||||
} from '@/app/infra/entities/api';
|
||||
import { Plugin } from '@/app/infra/entities/plugin';
|
||||
import { GetBotLogsRequest } from '@/app/infra/http/requestParam/bots/GetBotLogsRequest';
|
||||
@@ -445,6 +448,47 @@ export class BackendClient extends BaseHttpClient {
|
||||
return this.post(`/api/v1/knowledge/bases/${uuid}/retrieve`, { query });
|
||||
}
|
||||
|
||||
// ============ External Knowledge Base API ============
|
||||
public getExternalKnowledgeBases(): Promise<ApiRespExternalKnowledgeBases> {
|
||||
return this.get('/api/v1/knowledge/external-bases');
|
||||
}
|
||||
|
||||
public getExternalKnowledgeBase(
|
||||
uuid: string,
|
||||
): Promise<ApiRespExternalKnowledgeBase> {
|
||||
return this.get(`/api/v1/knowledge/external-bases/${uuid}`);
|
||||
}
|
||||
|
||||
public createExternalKnowledgeBase(
|
||||
base: ExternalKnowledgeBase,
|
||||
): Promise<{ uuid: string }> {
|
||||
return this.post('/api/v1/knowledge/external-bases', base);
|
||||
}
|
||||
|
||||
public updateExternalKnowledgeBase(
|
||||
uuid: string,
|
||||
base: ExternalKnowledgeBase,
|
||||
): Promise<{ uuid: string }> {
|
||||
return this.put(`/api/v1/knowledge/external-bases/${uuid}`, base);
|
||||
}
|
||||
|
||||
public deleteExternalKnowledgeBase(uuid: string): Promise<object> {
|
||||
return this.delete(`/api/v1/knowledge/external-bases/${uuid}`);
|
||||
}
|
||||
|
||||
public retrieveExternalKnowledgeBase(
|
||||
uuid: string,
|
||||
query: string,
|
||||
): Promise<ApiRespKnowledgeBaseRetrieve> {
|
||||
return this.post(`/api/v1/knowledge/external-bases/${uuid}/retrieve`, {
|
||||
query,
|
||||
});
|
||||
}
|
||||
|
||||
public listKnowledgeRetrievers(): Promise<{ retrievers: unknown[] }> {
|
||||
return this.get('/api/v1/knowledge/external-bases/retrievers');
|
||||
}
|
||||
|
||||
// ============ Plugins API ============
|
||||
public getPlugins(): Promise<ApiRespPlugins> {
|
||||
return this.get('/api/v1/plugins');
|
||||
|
||||
Reference in New Issue
Block a user