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

View File

@@ -1,18 +1,30 @@
import { BaseChat, BaseChatOptions } from '../core/chat.ts';
import { Result } from '@kevisual/query'
export type CNBOptions = Partial<BaseChatOptions>;
export class CNBChat extends BaseChat {
static BASE_URL = 'https://api.cnb.cool/{repo}/-/ai';
repo: string;
constructor(options: CNBOptions & { repo: string }) {
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 }) {
const baseURL = 'https://api.cnb.cool/{repo}/-/knowledge/base/query'
.replace('{repo}', repo);
this.post(baseURL, {
data: rest,
});
async query(params: CNBQueryParam): Promise<Result<QueryRag[]>> {
const url = this.baseURL.replace('/ai', '/knowledge/base/query');
const response = await this.post(url, {
data: {
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 || [],
}
}
}
@@ -31,4 +43,17 @@ export type CNBQueryParam = {
},
score_threshold?: 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;
}
}