Deploy huijutec package and stabilize AI model
This commit is contained in:
@@ -15,7 +15,7 @@ const actor: SafeUser = {
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
const createService = () => {
|
||||
const createService = (modelName = 'moonshot-v1') => {
|
||||
const settingsService = {
|
||||
getSystemSettings: vi.fn().mockResolvedValue({
|
||||
activeAiProvider: 'kimi',
|
||||
@@ -23,7 +23,7 @@ const createService = () => {
|
||||
kimi: {
|
||||
endpoint: 'https://provider.example/v1',
|
||||
apiKey: 'test-key',
|
||||
modelName: 'moonshot-v1',
|
||||
modelName,
|
||||
},
|
||||
},
|
||||
}),
|
||||
@@ -79,4 +79,29 @@ describe('AiService', () => {
|
||||
});
|
||||
expect(fetchMock).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it('removes unsupported sampling options for Kimi K2 models', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(
|
||||
new Response(JSON.stringify({ choices: [{ message: { content: '{"reply":"已完善"}' } }] }), { status: 200 }),
|
||||
);
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await createService('kimi-k2.6').chat(actor, {
|
||||
messages: [{ role: 'user', content: '请完善报告内容' }],
|
||||
temperature: 0.3,
|
||||
top_p: 0.8,
|
||||
presence_penalty: 0.1,
|
||||
frequency_penalty: 0.1,
|
||||
});
|
||||
|
||||
const requestBody = JSON.parse(String(fetchMock.mock.calls[0][1]?.body));
|
||||
expect(requestBody).toMatchObject({
|
||||
messages: [{ role: 'user', content: '请完善报告内容' }],
|
||||
model: 'kimi-k2.6',
|
||||
});
|
||||
expect(requestBody).not.toHaveProperty('temperature');
|
||||
expect(requestBody).not.toHaveProperty('top_p');
|
||||
expect(requestBody).not.toHaveProperty('presence_penalty');
|
||||
expect(requestBody).not.toHaveProperty('frequency_penalty');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -52,10 +52,10 @@ export class AiService {
|
||||
|
||||
const provider = await this.getActiveProvider(actor);
|
||||
const input = result.data;
|
||||
const payload = {
|
||||
const payload = this.normalizeProviderPayload({
|
||||
...input,
|
||||
model: provider.modelName || input.model,
|
||||
};
|
||||
});
|
||||
|
||||
const response = await this.fetchProviderWithRetry(`${provider.endpoint}/chat/completions`, {
|
||||
method: 'POST',
|
||||
@@ -99,6 +99,18 @@ export class AiService {
|
||||
};
|
||||
}
|
||||
|
||||
private normalizeProviderPayload(payload: Record<string, unknown>) {
|
||||
const model = typeof payload.model === 'string' ? payload.model : '';
|
||||
if (!/^kimi-k2(?:[.-]|$)/i.test(model)) return payload;
|
||||
|
||||
const normalized = { ...payload };
|
||||
delete normalized.temperature;
|
||||
delete normalized.top_p;
|
||||
delete normalized.presence_penalty;
|
||||
delete normalized.frequency_penalty;
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private async parseProviderResponse(response: Response) {
|
||||
const text = await response.text();
|
||||
if (!text) return null;
|
||||
|
||||
@@ -20,7 +20,7 @@ export const DEMO_SYSTEM_SETTINGS = {
|
||||
kimi: {
|
||||
endpoint: 'https://api.moonshot.cn/v1',
|
||||
apiKey: DEMO_AI_API_KEY,
|
||||
modelName: 'moonshot-v1-32k-vision-preview',
|
||||
modelName: 'kimi-k2.6',
|
||||
},
|
||||
deepseek: { endpoint: 'https://api.deepseek.com/v1', apiKey: '', modelName: 'deepseek-chat' },
|
||||
openai: { endpoint: 'https://api.openai.com/v1', apiKey: '', modelName: 'gpt-4o' },
|
||||
|
||||
@@ -13,7 +13,7 @@ import { PrismaService } from '../prisma/prisma.service.js';
|
||||
import { systemSettingsSchema, type SystemSettingsInput } from './settings.schemas.js';
|
||||
|
||||
const DEFAULT_AI_PROVIDERS = {
|
||||
kimi: { endpoint: 'https://api.moonshot.cn/v1', apiKey: DEMO_SYSTEM_SETTINGS.aiProviders.kimi.apiKey, modelName: 'moonshot-v1-32k-vision-preview' },
|
||||
kimi: { endpoint: 'https://api.moonshot.cn/v1', apiKey: DEMO_SYSTEM_SETTINGS.aiProviders.kimi.apiKey, modelName: 'kimi-k2.6' },
|
||||
deepseek: { endpoint: 'https://api.deepseek.com/v1', apiKey: '', modelName: 'deepseek-chat' },
|
||||
openai: { endpoint: 'https://api.openai.com/v1', apiKey: '', modelName: 'gpt-4o' },
|
||||
custom: { endpoint: '', apiKey: '', modelName: '' },
|
||||
|
||||
Reference in New Issue
Block a user