This commit is contained in:
Your Name
2026-08-22 08:51:35 +08:00
parent 6c444a4a04
commit c06d293424
69 changed files with 11431 additions and 1601 deletions
+28 -1
View File
@@ -36,8 +36,10 @@ difyStreamExpect(
);
difyStreamExpect($generic[1]['protocol'] === 'openai', 'OpenAI remains the fallback protocol');
difyStreamExpect($generic[1]['payload']['stream'] === true, 'OpenAI stream request uses stream=true');
// inputs 以对象语义上线(空 inputs 编码成 [] 会被 Dify 判为 invalid_param),
// 因此按线上实际编码结果断言,而不是按 PHP 数组比较。
difyStreamExpect(
$generic[0]['payload']['inputs'] === ['case' => 'redacted']
json_decode((string) json_encode($generic[0]['payload']['inputs']), true) === ['case' => 'redacted']
&& $generic[0]['payload']['query'] === 'safe query'
&& $generic[0]['payload']['user'] === 'admin-safe',
'Dify streaming preserves structured inputs, query and user'
@@ -59,6 +61,31 @@ difyStreamExpect(
'legacy OpenAI blocking request does not gain a stream field'
);
$withFiles = callDifyStreamPrivate('buildRequestSpecs', [
'https://ai.example.test/v1',
'model-safe',
['case' => 'full-context'],
'analyze all supplied records',
'admin-safe',
false,
[
['type' => 'image', 'transfer_method' => 'remote_url', 'url' => 'https://files.example.test/tongue.jpg'],
['type' => 'document', 'transfer_method' => 'remote_url', 'url' => 'https://files.example.test/report.pdf'],
],
]);
// 回退协议保留(网关 404/405 时才会用到),但任何附件都不得被静默丢弃:
// Dify 走文件通道,OpenAI-compatible 无法内联的附件必须落在提示词清单里。
difyStreamExpect(count($withFiles) === 2, 'ambiguous /v1 keeps the OpenAI fallback reachable');
difyStreamExpect($withFiles[0]['protocol'] === 'dify', 'Dify remains the preferred protocol');
difyStreamExpect(count($withFiles[0]['payload']['files']) === 2, 'Dify receives every supplied clinical file');
difyStreamExpect($withFiles[0]['payload']['files'][0]['type'] === 'image', 'tongue image keeps image type');
difyStreamExpect($withFiles[0]['payload']['files'][1]['type'] === 'document', 'report keeps document type');
$fallbackText = $withFiles[1]['payload']['messages'][0]['content'][0]['text'];
difyStreamExpect(
str_contains($fallbackText, 'https://files.example.test/report.pdf'),
'the fallback protocol declares the report it cannot inline'
);
$explicitDify = callDifyStreamPrivate('buildRequestSpecs', [
'https://ai.example.test/v1/chat-messages', 'model-safe', [], 'query', 'user', true,
]);