update
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user