mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
fix: translate input_file↔file content parts
This commit is contained in:
@@ -122,6 +122,14 @@ export function openaiResponsesToOpenAIRequest(
|
||||
}
|
||||
return imgResult;
|
||||
}
|
||||
if (contentItem.type === "input_file") {
|
||||
const fileObj: JsonRecord = {};
|
||||
if (contentItem.file_data !== undefined) fileObj.file_data = contentItem.file_data;
|
||||
if (contentItem.file_id !== undefined) fileObj.file_id = contentItem.file_id;
|
||||
if (contentItem.file_url !== undefined) fileObj.file_url = contentItem.file_url;
|
||||
if (contentItem.filename !== undefined) fileObj.filename = contentItem.filename;
|
||||
return { type: "file", file: fileObj };
|
||||
}
|
||||
return contentValue;
|
||||
})
|
||||
: item.content;
|
||||
@@ -308,6 +316,15 @@ export function openaiToOpenAIResponsesRequest(
|
||||
}
|
||||
return imgResult;
|
||||
}
|
||||
if (contentItem.type === "file") {
|
||||
const file = toRecord(contentItem.file);
|
||||
const fileResult: JsonRecord = { type: "input_file" };
|
||||
if (file.file_data !== undefined) fileResult.file_data = file.file_data;
|
||||
if (file.file_id !== undefined) fileResult.file_id = file.file_id;
|
||||
if (file.file_url !== undefined) fileResult.file_url = file.file_url;
|
||||
if (file.filename !== undefined) fileResult.filename = file.filename;
|
||||
return fileResult;
|
||||
}
|
||||
return contentValue;
|
||||
})
|
||||
: [{ type: "input_text", text: "" }];
|
||||
|
||||
@@ -117,3 +117,44 @@ test("Chat→Responses: image_url without detail omits detail", () => {
|
||||
assert.ok(imgPart);
|
||||
assert.equal(imgPart.detail, undefined);
|
||||
});
|
||||
|
||||
test("Responses→Chat: input_file converted to file content part", () => {
|
||||
const body = {
|
||||
model: "gpt-4",
|
||||
input: [
|
||||
{
|
||||
type: "message",
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "input_file", file_id: "file-abc", filename: "data.csv" },
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
const result = openaiResponsesToOpenAIRequest(null, body, null, null);
|
||||
const userMsg = result.messages.find((m) => m.role === "user");
|
||||
const filePart = userMsg.content.find((c) => c.type === "file");
|
||||
assert.ok(filePart, "should have file content part");
|
||||
assert.equal(filePart.file.file_id, "file-abc");
|
||||
assert.equal(filePart.file.filename, "data.csv");
|
||||
});
|
||||
|
||||
test("Chat→Responses: file content part converted to input_file", () => {
|
||||
const body = {
|
||||
model: "gpt-4",
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "file", file: { file_id: "file-abc", filename: "data.csv" } },
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
const result = openaiToOpenAIResponsesRequest("gpt-4", body, true, null);
|
||||
const userItem = result.input.find((i) => i.type === "message" && i.role === "user");
|
||||
const filePart = userItem.content.find((c) => c.type === "input_file");
|
||||
assert.ok(filePart, "should have input_file content part");
|
||||
assert.equal(filePart.file_id, "file-abc");
|
||||
assert.equal(filePart.filename, "data.csv");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user