import { CNBCore, CNBCoreOptions, Result } from "../cnb-core.ts"; export class KnowledgeBase extends CNBCore { constructor(options: CNBCoreOptions) { super({ token: options.token, cookie: options.cookie }); } queryKnowledgeBase(repo: string, data: { query: string, score_threshold?: number, top_k?: number, metadata_filtering_conditions?: MetadataFilteringConditions }): Promise { const url = `/${repo}/-/knowledge/base/query`; let postData = { query: data.query, }; return this.post({ url, data: postData }); } getEmbeddingModels(repo: string): Promise>> { const url = `/${repo}/-/knowledge/embedding/models`; // bg3-m3 1024 // hunyuan 1024 return this.get({ url }); } getBase(repo: string): Promise> { const url = `/${repo}/-/knowledge/base`; return this.get({ url }); } deleteBase(repo: string): Promise> { const url = `/${repo}/-/knowledge/base`; return this.request({ url, method: 'DELETE' }); } } type MetadataFilteringConditions = { conditions: Array<{ comparison_operator?: 'is' | 'is not' | 'contains' | 'not contains' | 'start with' | 'end with' | 'is empty' | 'is not empty'; name?: "position" | "path" | "type", /** * "is empty" and "is not empty" 时候忽略该字段 */ value?: string }> logical_operator?: 'adn' | 'or' }