add router
This commit is contained in:
10
src/provider/chat-adapter/open-router.ts
Normal file
10
src/provider/chat-adapter/open-router.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { BaseChat, BaseChatOptions } from '../core/chat.ts';
|
||||
|
||||
export type OpenRouterOptions = Partial<BaseChatOptions>;
|
||||
export class OpenRouterChat extends BaseChat {
|
||||
static BASE_URL = 'https://openrouter.ai/api/v1';
|
||||
constructor(options: OpenRouterOptions) {
|
||||
const baseURL = options.baseURL || OpenRouterChat.BASE_URL;
|
||||
super({ ...(options as BaseChatOptions), baseURL: baseURL });
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ export type BaseChatOptions<T = Record<string, any>> = {
|
||||
} & T;
|
||||
export const getIsBrowser = () => {
|
||||
try {
|
||||
// @ts-ignore
|
||||
return IS_BROWSER;
|
||||
// 检查是否存在window对象
|
||||
return typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ export class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
|
||||
this.openai = new OpenAI({
|
||||
apiKey: this.apiKey,
|
||||
baseURL: this.baseURL,
|
||||
dangerouslyAllowBrowser: this.isBrowser,
|
||||
dangerouslyAllowBrowser: options?.dangerouslyAllowBrowser ?? this.isBrowser,
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user