feat: add CNBChat adapter for CNB API integration
- Introduced CNBChat class in src/provider/chat-adapter/cnb.ts to handle interactions with the CNB API. - Updated chat.ts to export CNBChat for use in the application. - CNBChat includes methods for querying the CNB API with customizable parameters.
This commit is contained in:
34
src/provider/chat-adapter/cnb.ts
Normal file
34
src/provider/chat-adapter/cnb.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { BaseChat, BaseChatOptions } from '../core/chat.ts';
|
||||
|
||||
export type CNBOptions = Partial<BaseChatOptions>;
|
||||
export class CNBChat extends BaseChat {
|
||||
static BASE_URL = 'https://api.cnb.cool/{repo}/-/ai';
|
||||
constructor(options: CNBOptions & { repo: string }) {
|
||||
const baseURL = CNBChat.BASE_URL.replace('{repo}', options.repo);
|
||||
super({ ...(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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export type CNBQueryParam = {
|
||||
query: string;
|
||||
metadata_filtering_conditions?: {
|
||||
conditions: Array<{
|
||||
// "position", "path", "type"
|
||||
name: 'position' | 'path' | 'type';
|
||||
value: string;
|
||||
// "is", "is not", "contains", "not contains", "starts with", "ends with", "is empty", "is not empty"
|
||||
comparison_operator: 'is' | 'is not' | 'contains' | 'not contains' | 'starts with' | 'ends with' | 'is empty' | 'is not empty';
|
||||
}>;
|
||||
// "and" 或 "or",默认 "and"
|
||||
logical_operator: 'and' | 'or';
|
||||
},
|
||||
score_threshold?: number;
|
||||
top_k?: number;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import { BailianChat } from './chat-adapter/dashscope.ts';
|
||||
import { Zhipu } from './chat-adapter/zhipu.ts';
|
||||
import { Kimi } from './chat-adapter/kimi.ts';
|
||||
import { Kevisual } from './chat-adapter/kevisual.ts';
|
||||
import { CNBChat } from './chat-adapter/cnb.ts';
|
||||
|
||||
import { ChatMessage } from './core/type.ts';
|
||||
|
||||
@@ -27,6 +28,7 @@ export {
|
||||
Kimi,
|
||||
ChatMessage,
|
||||
Kevisual,
|
||||
CNBChat,
|
||||
}
|
||||
export class OllamaProvider extends Ollama { }
|
||||
export class SiliconFlowProvider extends SiliconFlow { }
|
||||
|
||||
Reference in New Issue
Block a user