46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
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<any> {
|
|
const url = `/${repo}/-/knowledge/base/query`;
|
|
let postData = {
|
|
query: data.query,
|
|
};
|
|
return this.post({ url, data: postData });
|
|
}
|
|
getEmbeddingModels(repo: string): Promise<Result<Array<{ name: string, dimensions: number }>>> {
|
|
const url = `/${repo}/-/knowledge/embedding/models`;
|
|
// bg3-m3 1024
|
|
// hunyuan 1024
|
|
return this.get({ url });
|
|
}
|
|
getBase(repo: string): Promise<Result<any>> {
|
|
const url = `/${repo}/-/knowledge/base`;
|
|
return this.get({ url });
|
|
}
|
|
deleteBase(repo: string): Promise<Result<any>> {
|
|
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'
|
|
} |