feat: 添加知识库和用户模块,更新核心功能并修复导入路径
This commit is contained in:
@@ -51,7 +51,7 @@ export class CNBCore {
|
|||||||
_headers['Cookie'] = this.cookie || "";
|
_headers['Cookie'] = this.cookie || "";
|
||||||
delete _headers.Authorization;
|
delete _headers.Authorization;
|
||||||
}
|
}
|
||||||
console.log('Request URL:', url, data, _headers);
|
// console.log('Request URL:', url, data, _headers);
|
||||||
const response = await fetch(url || '', {
|
const response = await fetch(url || '', {
|
||||||
method,
|
method,
|
||||||
headers: _headers,
|
headers: _headers,
|
||||||
|
|||||||
27
src/index.ts
27
src/index.ts
@@ -1,10 +1,29 @@
|
|||||||
import { CNBCore, CNBCoreOptions } from "./cnb-core";
|
import { CNBCore, CNBCoreOptions } from "./cnb-core.ts";
|
||||||
import { Workspace } from "./workspace";
|
import { Workspace } from "./workspace.ts";
|
||||||
|
import { KnowledgeBase } from "./knowledge/index.ts";
|
||||||
|
import { Repo } from "./repo/index.ts";
|
||||||
|
import { User } from "./user/index.ts";
|
||||||
|
|
||||||
type CNBOptions = CNBCoreOptions<{}>;
|
type CNBOptions = CNBCoreOptions<{}>;
|
||||||
|
|
||||||
export class CNB extends CNBCore {
|
export class CNB extends CNBCore {
|
||||||
workspace: Workspace;
|
workspace!: Workspace;
|
||||||
|
knowledgeBase!: KnowledgeBase;
|
||||||
|
repo!: Repo;
|
||||||
|
user!: User;
|
||||||
constructor(options: CNBOptions) {
|
constructor(options: CNBOptions) {
|
||||||
super({ token: options.token });
|
super({ token: options.token, cookie: options.cookie });
|
||||||
|
this.init(options);
|
||||||
|
}
|
||||||
|
init(options: CNBOptions) {
|
||||||
this.workspace = new Workspace(options.token);
|
this.workspace = new Workspace(options.token);
|
||||||
|
this.knowledgeBase = new KnowledgeBase({ token: options.token, cookie: options.cookie });
|
||||||
|
this.repo = new Repo({ token: options.token, cookie: options.cookie });
|
||||||
|
this.user = new User({ token: options.token, cookie: options.cookie });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export * from './workspace.ts'
|
||||||
|
export * from './cnb-core.ts'
|
||||||
|
export * from './knowledge/index.ts'
|
||||||
|
export * from './repo/index.ts'
|
||||||
|
|||||||
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'
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core";
|
import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts";
|
||||||
|
|
||||||
type RepoOptions = CNBCoreOptions<{
|
type RepoOptions = CNBCoreOptions<{
|
||||||
group?: string;
|
group?: string;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CNBCore, CNBCoreOptions } from "../cnb-core";
|
import { CNBCore, CNBCoreOptions } from "../cnb-core.ts";
|
||||||
|
|
||||||
export class User extends CNBCore {
|
export class User extends CNBCore {
|
||||||
constructor(options: CNBCoreOptions<{}>) {
|
constructor(options: CNBCoreOptions<{}>) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @createdAt 2025-12-04
|
* @createdAt 2025-12-04
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CNBCore } from "./cnb-core";
|
import { CNBCore } from "./cnb-core.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 工作空间列表查询参数
|
* 工作空间列表查询参数
|
||||||
|
|||||||
10
test/knowledge.ts
Normal file
10
test/knowledge.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { KnowledgeBase } from "../src/knowledge/index.ts";
|
||||||
|
|
||||||
|
import { token, showMore, cookie } from "./common.ts";
|
||||||
|
|
||||||
|
const repo = new KnowledgeBase({ group: "kevisual/demo", token: token, cookie: cookie });
|
||||||
|
const repoName = "test-cnb";
|
||||||
|
|
||||||
|
const queryRes = await repo.getEmbeddingModels(repoName);
|
||||||
|
|
||||||
|
console.log("queryRes", showMore(queryRes));
|
||||||
Reference in New Issue
Block a user