This commit is contained in:
2026-01-27 03:42:47 +08:00
parent fa470a272a
commit 7bbdfa73b3
2 changed files with 36 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@kevisual/ai", "name": "@kevisual/ai",
"version": "0.0.22", "version": "0.0.23",
"description": "AI Center Services", "description": "AI Center Services",
"main": "index.js", "main": "index.js",
"basename": "/root/ai-center-services", "basename": "/root/ai-center-services",
@@ -27,7 +27,7 @@
], ],
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)", "author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
"license": "MIT", "license": "MIT",
"packageManager": "pnpm@10.28.1", "packageManager": "pnpm@10.28.2",
"type": "module", "type": "module",
"publishConfig": { "publishConfig": {
"registry": "https://registry.npmjs.org/", "registry": "https://registry.npmjs.org/",
@@ -48,7 +48,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@kevisual/router": "0.0.60", "@kevisual/router": "0.0.62",
"@kevisual/types": "^0.0.12", "@kevisual/types": "^0.0.12",
"@kevisual/use-config": "^1.0.28", "@kevisual/use-config": "^1.0.28",
"@types/bun": "^1.3.6", "@types/bun": "^1.3.6",

View File

@@ -1,18 +1,30 @@
import { BaseChat, BaseChatOptions } from '../core/chat.ts'; import { BaseChat, BaseChatOptions } from '../core/chat.ts';
import { Result } from '@kevisual/query'
export type CNBOptions = Partial<BaseChatOptions>; export type CNBOptions = Partial<BaseChatOptions>;
export class CNBChat extends BaseChat { export class CNBChat extends BaseChat {
static BASE_URL = 'https://api.cnb.cool/{repo}/-/ai'; static BASE_URL = 'https://api.cnb.cool/{repo}/-/ai';
repo: string;
constructor(options: CNBOptions & { repo: string }) { constructor(options: CNBOptions & { repo: string }) {
const baseURL = CNBChat.BASE_URL.replace('{repo}', options.repo); const baseURL = CNBChat.BASE_URL.replace('{repo}', options.repo);
super({ ...(options as BaseChatOptions), baseURL: baseURL }); super({ model: "hunyuan-a13b", ...(options as BaseChatOptions), baseURL: baseURL });
} }
query({ repo, ...rest }: CNBQueryParam & { repo: string }) { async query(params: CNBQueryParam): Promise<Result<QueryRag[]>> {
const baseURL = 'https://api.cnb.cool/{repo}/-/knowledge/base/query' const url = this.baseURL.replace('/ai', '/knowledge/base/query');
.replace('{repo}', repo); const response = await this.post(url, {
this.post(baseURL, { data: {
data: rest, score_threshold: 0.62,
}); top_k: 10,
...params
},
})
if (!response.ok) {
throw new Error(`query API error: ${response.status} ${response.statusText}`);
}
const res = await response.json() as QueryRag[];
return {
code: 200,
data: res || [],
}
} }
} }
@@ -32,3 +44,16 @@ export type CNBQueryParam = {
score_threshold?: number; score_threshold?: number;
top_k?: number; top_k?: number;
} }
type QueryRag = {
chunk: string;
score: number;
metadata: {
hash: string;
name: string;
path: string;
position: string;
type: string; // code, text
url: string;
}
}