40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { BaseChat, BaseChatOptions } from '../core/chat.ts';
|
|
import type { ChatMessage, ChatMessageOptions } from '../core/index.ts';
|
|
|
|
export type SiliconFlowOptions = Partial<BaseChatOptions>;
|
|
|
|
type SiliconFlowUsageData = {
|
|
id: string;
|
|
name: string;
|
|
image: string;
|
|
email: string;
|
|
isAdmin: boolean;
|
|
balance: string;
|
|
status: 'normal' | 'suspended' | 'expired' | string; // 状态
|
|
introduce: string;
|
|
role: string;
|
|
chargeBalance: string;
|
|
totalBalance: string;
|
|
category: string;
|
|
};
|
|
type SiliconFlowUsageResponse = {
|
|
code: number;
|
|
message: string;
|
|
status: boolean;
|
|
data: SiliconFlowUsageData;
|
|
};
|
|
export class SiliconFlow extends BaseChat {
|
|
static BASE_URL = 'https://api.siliconflow.cn/v1';
|
|
constructor(options: SiliconFlowOptions) {
|
|
const baseURL = options.baseURL || SiliconFlow.BASE_URL;
|
|
super({ ...(options as BaseChatOptions), baseURL: baseURL });
|
|
}
|
|
async getUsageInfo(): Promise<SiliconFlowUsageResponse> {
|
|
return this.get('/user/info');
|
|
}
|
|
async chat(messages: ChatMessage[], options?: ChatMessageOptions) {
|
|
const res = await super.chat(messages, options);
|
|
return res;
|
|
}
|
|
}
|