feat: add百炼

This commit is contained in:
2025-06-21 14:01:33 +08:00
parent 3cd3be6024
commit 00a23af998
10 changed files with 113 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ export type BaseChatOptions<T = Record<string, any>> = {
/**
* 默认baseURL
*/
baseURL: string;
baseURL?: string;
/**
* 默认模型
*/
@@ -32,7 +32,14 @@ export type BaseChatOptions<T = Record<string, any>> = {
*/
stream?: boolean;
} & T;
export const getIsBrowser = () => {
try {
// @ts-ignore
return IS_BROWSER;
} catch (e) {
return false;
}
};
export class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
/**
* 默认baseURL
@@ -63,7 +70,9 @@ export class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
this.baseURL = options.baseURL;
this.model = options.model;
this.apiKey = options.apiKey;
this.isBrowser = options.isBrowser ?? false;
// @ts-ignore
const DEFAULT_IS_BROWSER = getIsBrowser();
this.isBrowser = options.isBrowser ?? DEFAULT_IS_BROWSER;
this.openai = new OpenAI({
apiKey: this.apiKey,
baseURL: this.baseURL,