fix: update execution counts and improve message parsing in chat conversation functions
This commit is contained in:
@@ -157,12 +157,27 @@ app.get(`${prefix}/conversations/:id/messages`, async (c) => {
|
||||
convRow.openai_conversation_id,
|
||||
);
|
||||
|
||||
const conversacion = items.data.filter((it: any) =>
|
||||
it.type === "message" && (it.role === "assistant" || it.role === "user")
|
||||
).map((it: any) => ({
|
||||
role: it.role,
|
||||
content: it.content.map((c: any) => c.text).join(""),
|
||||
}));
|
||||
const conversacion = items.data
|
||||
.filter((it: any) =>
|
||||
it.type === "message" &&
|
||||
(it.role === "assistant" || it.role === "user")
|
||||
)
|
||||
.map((it: any) => {
|
||||
const rawText = it.content.map((c: any) => c.text).join("");
|
||||
|
||||
let parsedContent;
|
||||
|
||||
try {
|
||||
parsedContent = JSON.parse(rawText); // 👈 aquí lo convertimos
|
||||
} catch {
|
||||
parsedContent = rawText; // si no es JSON, lo dejamos normal
|
||||
}
|
||||
|
||||
return {
|
||||
role: it.role,
|
||||
content: parsedContent,
|
||||
};
|
||||
});
|
||||
|
||||
return withCors(jsonResponse({ source: "openai", items: conversacion }));
|
||||
} catch (err) {
|
||||
@@ -293,15 +308,9 @@ app.post(`${prefix}/conversations/:id/messages`, async (c) => {
|
||||
],
|
||||
});
|
||||
|
||||
let parsed: any = null;
|
||||
try {
|
||||
parsed = JSON.parse(resp.output_text ?? "null");
|
||||
} catch (_) {}
|
||||
|
||||
return withCors(jsonResponse({
|
||||
ok: true,
|
||||
openai_response_id: resp.id,
|
||||
data: parsed,
|
||||
raw: resp.output_text ?? null,
|
||||
}));
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user