feat: 添加知识库和用户模块,更新核心功能并修复导入路径
This commit is contained in:
55
src/knowledge/index.ts
Normal file
55
src/knowledge/index.ts
Normal 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'
|
||||
}
|
||||
Reference in New Issue
Block a user