perf: 优化 token 和 apikey,token 字段也可以用

This commit is contained in:
2025-12-08 14:54:11 +08:00
parent 809bf4e373
commit 966a465fb4
3 changed files with 12 additions and 2 deletions

View File

@@ -5,6 +5,9 @@ export class BailianChat extends BaseChat {
static BASE_URL = 'https://dashscope.aliyuncs.com/compatible-mode/v1'; static BASE_URL = 'https://dashscope.aliyuncs.com/compatible-mode/v1';
constructor(options: BailianOptions) { constructor(options: BailianOptions) {
const baseURL = options.baseURL || BailianChat.BASE_URL; const baseURL = options.baseURL || BailianChat.BASE_URL;
if (!options.model) {
options.model = 'qwen-plus'
}
super({ ...(options as BaseChatOptions), baseURL: baseURL }); super({ ...(options as BaseChatOptions), baseURL: baseURL });
} }
} }

View File

@@ -9,6 +9,9 @@ export class Kevisual extends BaseChat {
static BASE_URL = 'https://newapi.kevisual.cn/v1/'; static BASE_URL = 'https://newapi.kevisual.cn/v1/';
constructor(options: KevisualOptions) { constructor(options: KevisualOptions) {
const baseURL = options.baseURL || Kevisual.BASE_URL; const baseURL = options.baseURL || Kevisual.BASE_URL;
if (!options.model) {
options.model = 'qwen-plus'
}
super({ ...(options as BaseChatOptions), baseURL: baseURL }); super({ ...(options as BaseChatOptions), baseURL: baseURL });
} }
} }

View File

@@ -22,7 +22,11 @@ export type BaseChatOptions<T = Record<string, any>> = {
/** /**
* 默认apiKey * 默认apiKey
*/ */
apiKey: string; apiKey?: string;
/**
* token
*/
token?: string;
/** /**
* 是否在浏览器中使用 * 是否在浏览器中使用
*/ */
@@ -54,7 +58,7 @@ export class BaseChat implements BaseChatInterface, BaseChatUsageInterface {
constructor(options: BaseChatOptions) { constructor(options: BaseChatOptions) {
this.baseURL = options.baseURL; this.baseURL = options.baseURL;
this.model = options.model; this.model = options.model;
this.apiKey = options.apiKey; this.apiKey = options.token || options.apiKey;
} }
post(url = '', opts: { headers?: Record<string, string>, data?: any } = {}) { post(url = '', opts: { headers?: Record<string, string>, data?: any } = {}) {
let _url = url.startsWith('http') ? url : this.baseURL + url; let _url = url.startsWith('http') ? url : this.baseURL + url;