mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 12:45:51 +00:00
Update Ngms_api.js
This commit is contained in:
@@ -139,28 +139,37 @@ export async function callNgmsAI(messages, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function callNgmsOpenAITest(messages, options) {
|
async function callNgmsOpenAITest(messages, options) {
|
||||||
const response = await fetch('/api/backends/chat-completions/generate', {
|
const isGoogleApi = options.apiUrl.includes('googleapis.com');
|
||||||
method: 'POST',
|
|
||||||
headers: { ...getRequestHeaders(), 'Content-Type': 'application/json' },
|
const body = {
|
||||||
body: JSON.stringify({
|
|
||||||
chat_completion_source: 'openai',
|
chat_completion_source: 'openai',
|
||||||
|
messages: messages,
|
||||||
|
model: options.model,
|
||||||
|
reverse_proxy: options.apiUrl,
|
||||||
|
proxy_password: options.apiKey,
|
||||||
|
stream: false,
|
||||||
|
max_tokens: options.maxTokens || 30000,
|
||||||
|
temperature: options.temperature || 1,
|
||||||
|
top_p: options.top_p || 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!isGoogleApi) {
|
||||||
|
Object.assign(body, {
|
||||||
custom_prompt_post_processing: 'strict',
|
custom_prompt_post_processing: 'strict',
|
||||||
enable_web_search: false,
|
enable_web_search: false,
|
||||||
frequency_penalty: 0,
|
frequency_penalty: 0,
|
||||||
group_names: [],
|
group_names: [],
|
||||||
include_reasoning: false,
|
include_reasoning: false,
|
||||||
max_tokens: options.maxTokens || 65000,
|
|
||||||
messages: messages,
|
|
||||||
model: options.model,
|
|
||||||
presence_penalty: 0.12,
|
presence_penalty: 0.12,
|
||||||
proxy_password: options.apiKey,
|
|
||||||
reasoning_effort: 'medium',
|
reasoning_effort: 'medium',
|
||||||
request_images: false,
|
request_images: false,
|
||||||
reverse_proxy: options.apiUrl,
|
});
|
||||||
stream: false,
|
}
|
||||||
temperature: options.temperature || 1,
|
|
||||||
top_p: options.top_p || 1
|
const response = await fetch('/api/backends/chat-completions/generate', {
|
||||||
})
|
method: 'POST',
|
||||||
|
headers: { ...getRequestHeaders(), 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -352,7 +361,11 @@ export async function testNgmsApiConnection() {
|
|||||||
try {
|
try {
|
||||||
toastr.info('正在发送测试消息"你好!"...', 'Ngms API连接测试');
|
toastr.info('正在发送测试消息"你好!"...', 'Ngms API连接测试');
|
||||||
|
|
||||||
|
const userName = window.SillyTavern.getContext?.()?.name1 || '用户';
|
||||||
|
const systemPrompt = `接下来用户会使用测试按钮测试api连接是否正常,请回复ta连接是正常的,称呼用户为:“${userName}大人”,并复述群号1060183271,告知ta,本扩展开发者:“诗与酒.”正静待ta的入驻。`;
|
||||||
|
|
||||||
const testMessages = [
|
const testMessages = [
|
||||||
|
{ role: 'system', content: systemPrompt },
|
||||||
{ role: 'user', content: '你好!' }
|
{ role: 'user', content: '你好!' }
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -360,7 +373,8 @@ export async function testNgmsApiConnection() {
|
|||||||
|
|
||||||
if (response && response.trim()) {
|
if (response && response.trim()) {
|
||||||
console.log('[Amily2号-Ngms外交部] 测试消息响应:', response);
|
console.log('[Amily2号-Ngms外交部] 测试消息响应:', response);
|
||||||
toastr.success(`连接测试成功!AI回复: "${response.substring(0, 50)}${response.length > 50 ? '...' : ''}"`, 'Ngms API连接测试成功');
|
const formattedResponse = response.replace(/\*\*(.*?)\*\*/g, '<b>$1</b>');
|
||||||
|
toastr.success(`连接测试成功!AI回复: "${formattedResponse}"`, 'Ngms API连接测试成功', { "escapeHtml": false });
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('API未返回有效响应');
|
throw new Error('API未返回有效响应');
|
||||||
|
|||||||
Reference in New Issue
Block a user