diff --git a/package.json b/package.json index 2710f0d..bb01c93 100644 --- a/package.json +++ b/package.json @@ -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 (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", diff --git a/src/provider/chat-adapter/cnb.ts b/src/provider/chat-adapter/cnb.ts index ab53117..c4389eb 100644 --- a/src/provider/chat-adapter/cnb.ts +++ b/src/provider/chat-adapter/cnb.ts @@ -1,18 +1,30 @@ import { BaseChat, BaseChatOptions } from '../core/chat.ts'; - +import { Result } from '@kevisual/query' export type CNBOptions = Partial; 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> { + 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; + } } \ No newline at end of file