feat(edit): 编辑页上报ozon 开发
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { makeModel, validateCopy, validatePackage } from '../src/product-ai.ts';
|
||||
import { deepSeekJson, makeModel, validateCopy, validatePackage } from '../src/product-ai.ts';
|
||||
|
||||
test('同一商品模型只由类目和稳定商品 ID 确定', () => {
|
||||
const category = { name: '手办', path: '玩具 / 手办' };
|
||||
@@ -113,3 +113,70 @@ test('包装字段名称可作为 1688 分离尺寸和重量证据', () => {
|
||||
};
|
||||
assert.equal(validatePackage(proposal, source)?.height_mm, '30');
|
||||
});
|
||||
|
||||
test('DeepSeek 结构化请求关闭思考,截断后提高输出上限重试', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const originalKey = process.env.DEEPSEEK_API_KEY;
|
||||
const requests = [];
|
||||
process.env.DEEPSEEK_API_KEY = 'test-key';
|
||||
globalThis.fetch = async (_url, options) => {
|
||||
requests.push(JSON.parse(options.body));
|
||||
const truncated = requests.length === 1;
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
choices: [
|
||||
{
|
||||
finish_reason: truncated ? 'length' : 'stop',
|
||||
message: { content: truncated ? '' : '{"ok":true}' },
|
||||
},
|
||||
],
|
||||
usage: { total_tokens: 25 },
|
||||
}),
|
||||
{ status: 200 },
|
||||
);
|
||||
};
|
||||
try {
|
||||
assert.deepEqual(await deepSeekJson('输出 JSON', '商品事实'), {
|
||||
data: { ok: true },
|
||||
tokens: 25,
|
||||
});
|
||||
assert.equal(requests.length, 2);
|
||||
assert.deepEqual(requests[0].thinking, { type: 'disabled' });
|
||||
assert.equal(requests[0].max_tokens, 8192);
|
||||
assert.equal(requests[1].max_tokens, 16384);
|
||||
assert.match(requests[1].messages[1].content, /不要只返回空白/);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
if (originalKey === undefined) delete process.env.DEEPSEEK_API_KEY;
|
||||
else process.env.DEEPSEEK_API_KEY = originalKey;
|
||||
}
|
||||
});
|
||||
|
||||
test('DeepSeek JSON 模式返回空白内容时调整提示词重试', async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const originalKey = process.env.DEEPSEEK_API_KEY;
|
||||
const requests = [];
|
||||
process.env.DEEPSEEK_API_KEY = 'test-key';
|
||||
globalThis.fetch = async (_url, options) => {
|
||||
requests.push(JSON.parse(options.body));
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
choices: [{
|
||||
finish_reason: 'stop',
|
||||
message: { content: requests.length === 1 ? ' ' : '{"ok":true}' },
|
||||
}],
|
||||
}),
|
||||
{ status: 200 },
|
||||
);
|
||||
};
|
||||
try {
|
||||
assert.deepEqual((await deepSeekJson('输出 JSON', '商品事实')).data, { ok: true });
|
||||
assert.equal(requests.length, 2);
|
||||
assert.equal(requests[1].max_tokens, 8192);
|
||||
assert.match(requests[1].messages[1].content, /不要只返回空白/);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
if (originalKey === undefined) delete process.env.DEEPSEEK_API_KEY;
|
||||
else process.env.DEEPSEEK_API_KEY = originalKey;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user