mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 11:35:50 +00:00
添加 ModelCaller 和 Options 类,重构 Logger,增强 Amily2Bus 架构,更新 README 和 TODO 文件
This commit is contained in:
98
SL/bus/api/Options.js
Normal file
98
SL/bus/api/Options.js
Normal file
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* ModelCaller 请求配置类
|
||||
* 支持构造函数直接传入对象,或使用 Builder 链式调用
|
||||
*/
|
||||
export class Options {
|
||||
constructor(config = {}) {
|
||||
/** @type {'direct'|'preset'} */
|
||||
this.mode = config.mode || 'direct';
|
||||
/** @type {boolean} */
|
||||
this.fakeStream = config.fakeStream ?? false;
|
||||
/** @type {string} */
|
||||
this.apiUrl = config.apiUrl || '';
|
||||
/** @type {string} */
|
||||
this.apiKey = config.apiKey || '';
|
||||
/** @type {string} */
|
||||
this.model = config.model || '';
|
||||
/** @type {string} */
|
||||
this.presetId = config.presetId || '';
|
||||
/** @type {number} */
|
||||
this.maxTokens = config.maxTokens || 4000;
|
||||
/** @type {number} */
|
||||
this.temperature = config.temperature || 0.7;
|
||||
/** @type {Object} 额外透传参数 */
|
||||
this.params = config.params || {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Builder 实例
|
||||
* @returns {OptionsBuilder}
|
||||
*/
|
||||
static builder() {
|
||||
return new OptionsBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Options 构建器类
|
||||
*/
|
||||
class OptionsBuilder {
|
||||
constructor() {
|
||||
this.config = {};
|
||||
}
|
||||
|
||||
setMode(mode) {
|
||||
this.config.mode = mode;
|
||||
return this;
|
||||
}
|
||||
|
||||
setFakeStream(enabled) {
|
||||
this.config.fakeStream = enabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
setApiUrl(url) {
|
||||
this.config.apiUrl = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
setApiKey(key) {
|
||||
this.config.apiKey = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
setModel(model) {
|
||||
this.config.model = model;
|
||||
return this;
|
||||
}
|
||||
|
||||
setPresetId(id) {
|
||||
this.config.presetId = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
setMaxTokens(tokens) {
|
||||
this.config.maxTokens = tokens;
|
||||
return this;
|
||||
}
|
||||
|
||||
setTemperature(temp) {
|
||||
this.config.temperature = temp;
|
||||
return this;
|
||||
}
|
||||
|
||||
setParams(params) {
|
||||
this.config.params = { ...(this.config.params || {}), ...params };
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建最终的 Options 对象
|
||||
* @returns {Options}
|
||||
*/
|
||||
build() {
|
||||
return new Options(this.config);
|
||||
}
|
||||
}
|
||||
|
||||
export default Options;
|
||||
Reference in New Issue
Block a user