mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 17:25:51 +00:00
feat(api): bridge ApiProfileManager to all AI callers, fix config split
- Add core/api/api-resolver.js: getSlotProfile(slot) + providerToApiMode() - core/api.js: getApiSettings() async, reads 'main' slot profile first - NccsApi.js: getNccsApiSettings() async, reads 'nccs' slot profile first - Ngms_api.js: getNgmsApiSettings() async, reads 'ngms' slot profile first - JqyhApi.js: getJqyhApiSettings() async, reads 'jqyh' slot profile first - All callers updated with await; legacy DOM/extension_settings as fallback - .gitignore: add WorkDiary.md and Structure.md (local-only files) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
44
core/api.js
44
core/api.js
@@ -1,5 +1,6 @@
|
||||
import { extension_settings, getContext } from "/scripts/extensions.js";
|
||||
import { characters } from "/script.js";
|
||||
import { getSlotProfile } from './api/api-resolver.js';
|
||||
import { world_names } from "/scripts/world-info.js";
|
||||
import { extensionName } from "../utils/settings.js";
|
||||
import { extractContentByTag, replaceContentByTag, extractFullTagBlock } from '../utils/tagProcessor.js';
|
||||
@@ -433,28 +434,43 @@ async function fetchSillyTavernPresetModels() {
|
||||
}
|
||||
|
||||
|
||||
export function getApiSettings() {
|
||||
export async function getApiSettings() {
|
||||
// 优先读取 'main' 槽位分配的 Profile
|
||||
const profile = await getSlotProfile('main');
|
||||
if (profile) {
|
||||
return {
|
||||
apiProvider: profile.provider,
|
||||
apiUrl: profile.apiUrl,
|
||||
apiKey: profile.apiKey ?? '',
|
||||
model: profile.model,
|
||||
maxTokens: profile.maxTokens ?? 65500,
|
||||
temperature: profile.temperature ?? 1.0,
|
||||
tavernProfile: '',
|
||||
};
|
||||
}
|
||||
|
||||
// 降级:读旧 DOM 面板配置
|
||||
const settings = extension_settings[extensionName] || {};
|
||||
const apiProvider = document.getElementById('amily2_api_provider')?.value || 'openai';
|
||||
|
||||
|
||||
let model;
|
||||
if (apiProvider === 'sillytavern_preset') {
|
||||
const context = getContext();
|
||||
const profileId = document.getElementById('amily2_preset_selector')?.value;
|
||||
const profile = context.extensionSettings?.connectionManager?.profiles?.find(p => p.id === profileId);
|
||||
model = profile?.openai_model || 'Preset Model';
|
||||
const stProfile = context.extensionSettings?.connectionManager?.profiles?.find(p => p.id === profileId);
|
||||
model = stProfile?.openai_model || 'Preset Model';
|
||||
} else {
|
||||
model = document.getElementById('amily2_model')?.value;
|
||||
}
|
||||
|
||||
return {
|
||||
apiProvider: apiProvider,
|
||||
apiUrl: document.getElementById('amily2_api_url')?.value.trim() || '',
|
||||
apiKey: document.getElementById('amily2_api_key')?.value.trim() || '',
|
||||
model: model,
|
||||
maxTokens: settings.maxTokens || 4000,
|
||||
temperature: settings.temperature || 0.7,
|
||||
tavernProfile: document.getElementById('amily2_preset_selector')?.value || ''
|
||||
apiProvider,
|
||||
apiUrl: document.getElementById('amily2_api_url')?.value.trim() || '',
|
||||
apiKey: document.getElementById('amily2_api_key')?.value.trim() || '',
|
||||
model,
|
||||
maxTokens: settings.maxTokens || 4000,
|
||||
temperature: settings.temperature || 0.7,
|
||||
tavernProfile: document.getElementById('amily2_preset_selector')?.value || '',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -468,8 +484,8 @@ export async function testApiConnection() {
|
||||
$button.prop("disabled", true).html('<i class="fas fa-spinner fa-spin"></i> 测试中');
|
||||
|
||||
try {
|
||||
const apiSettings = getApiSettings();
|
||||
|
||||
const apiSettings = await getApiSettings();
|
||||
|
||||
if (apiSettings.apiProvider === 'sillytavern_preset') {
|
||||
if (!apiSettings.tavernProfile) {
|
||||
throw new Error("请先在下方选择一个SillyTavern预设");
|
||||
@@ -518,7 +534,7 @@ export async function callAI(messages, options = {}) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const apiSettings = getApiSettings();
|
||||
const apiSettings = await getApiSettings();
|
||||
|
||||
const finalOptions = {
|
||||
maxTokens: apiSettings.maxTokens,
|
||||
|
||||
Reference in New Issue
Block a user