mslxdff 0.1.102 → 0.1.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/upstream-responses.js +28 -3
package/package.json
CHANGED
|
@@ -17,10 +17,35 @@ export function chatToResponsesBody(chatBody) {
|
|
|
17
17
|
return `${m.role}: ${String(c || "")}`;
|
|
18
18
|
});
|
|
19
19
|
const input = inputParts.join("\n\n") || "hi";
|
|
20
|
-
const out = { model: chatBody.model, input, stream:
|
|
20
|
+
const out = { model: chatBody.model, input, stream: false };
|
|
21
21
|
if (system) out.instructions = system;
|
|
22
|
-
|
|
23
|
-
if (chatBody.
|
|
22
|
+
// responses 的 tools 形状为平铺 {type,name,description,parameters},而 chat 为 {type,function:{name,...}}
|
|
23
|
+
if (Array.isArray(chatBody.tools) && chatBody.tools.length) {
|
|
24
|
+
const mapped = chatBody.tools.map((t) => {
|
|
25
|
+
if (!t || typeof t !== "object") return null;
|
|
26
|
+
if (t.type === "function" && t.function && typeof t.function === "object") {
|
|
27
|
+
const fn = t.function;
|
|
28
|
+
const nt = { type: "function", name: fn.name, description: fn.description || undefined, parameters: fn.parameters || undefined };
|
|
29
|
+
// 清理 undefined
|
|
30
|
+
Object.keys(nt).forEach((k) => nt[k] === undefined && delete nt[k]);
|
|
31
|
+
return nt.name ? nt : null;
|
|
32
|
+
}
|
|
33
|
+
// 已是平铺形态或未知形态,透传但确保 name 存在
|
|
34
|
+
if (t.name) return t;
|
|
35
|
+
return null;
|
|
36
|
+
}).filter(Boolean);
|
|
37
|
+
if (mapped.length) out.tools = mapped;
|
|
38
|
+
}
|
|
39
|
+
if (chatBody.tool_choice) {
|
|
40
|
+
const tc = chatBody.tool_choice;
|
|
41
|
+
// chat: "auto" | {type:"auto"} | {type:"function", function:{name}} -> responses: "auto" | {type:"function", name}
|
|
42
|
+
if (typeof tc === "string") out.tool_choice = tc;
|
|
43
|
+
else if (tc && typeof tc === "object") {
|
|
44
|
+
if (tc.type === "function" && tc.function?.name) out.tool_choice = { type: "function", name: tc.function.name };
|
|
45
|
+
else if (tc.type) out.tool_choice = tc;
|
|
46
|
+
else out.tool_choice = tc;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
24
49
|
if (chatBody.temperature != null) out.temperature = chatBody.temperature;
|
|
25
50
|
if (chatBody.max_tokens != null) out.max_output_tokens = chatBody.max_tokens;
|
|
26
51
|
return out;
|