generated from tailored/app-template
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { BaseChat, BaseChatOptions } from '../core/chat.ts';
|
|
import { OpenAI } from 'openai';
|
|
|
|
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.openai.get('/user/info');
|
|
}
|
|
async chat(messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[], options?: Partial<OpenAI.Chat.Completions.ChatCompletionCreateParams>) {
|
|
const res = await super.chat(messages, options);
|
|
return res;
|
|
}
|
|
}
|