feat: 添加知识库和用户模块,更新核心功能并修复导入路径

This commit is contained in:
2025-12-15 18:11:30 +08:00
parent 6a579b3ae0
commit a050a8ec17
8 changed files with 95 additions and 10 deletions

55
src/knowledge/index.ts Normal file
View File

@@ -0,0 +1,55 @@
import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts";
type RepoOptions = CNBCoreOptions<{
group?: string;
}>
export class KnowledgeBase extends CNBCore {
group: string;
constructor(options: RepoOptions) {
super({ token: options.token, cookie: options.cookie });
this.group = options.group || '';
}
queryKnowledgeBase(repo: string, data: {
query: string,
score_threshold?: number,
top_k?: number,
metadata_filtering_conditions?: MetadataFilteringConditions
}): Promise<any> {
const group = this.group || '';
const url = `/${group}/${repo}/-/knowledge/query`;
let postData = {
query: data.query,
};
return this.post({ url, data: postData });
}
getEmbeddingModels(repo: string): Promise<Result<Array<{ name: string, dimensions: number }>>> {
const group = this.group || '';
const url = `/${group}/${repo}/-/knowledge/embedding/models`;
// bg3-m3 1024
// hunyuan 1024
return this.get({ url });
}
getBase(repo: string): Promise<Result<any>> {
const group = this.group || '';
const url = `/${group}/${repo}/-/knowledge/base`;
return this.get({ url });
}
deleteBase(repo: string): Promise<Result<any>> {
const group = this.group || '';
const url = `/${group}/${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'
}