ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
32 lines (31 loc) • 1.23 kB
JavaScript
function m(s) {
var a;
const { originMessage: t, chunk: e, responseHeaders: f } = s;
let l = "", o = "assistant";
try {
let r;
if (((f == null ? void 0 : f.get("content-type")) || "").includes("text/event-stream") || typeof (e == null ? void 0 : e.data) == "string") {
const n = e == null ? void 0 : e.data;
n && String(n).trim() !== "[DONE]" && (r = typeof n == "string" ? JSON.parse(n) : n);
} else e && (r = e);
r && ((a = r == null ? void 0 : r.choices) == null || a.forEach((n) => {
n != null && n.delta ? (l += n.delta.content || "", o = n.delta.role || o) : n != null && n.message && (l += n.message.content || "", o = n.message.role || o);
}));
} catch (r) {
console.error("[OpenAIChatProvider] transformMessage error", r);
}
const p = typeof (t == null ? void 0 : t.content) == "string" ? t.content : t != null && t.content && typeof t.content == "object" && t.content.text || "";
return {
...t || {},
content: `${p}${l}`,
role: (t == null ? void 0 : t.role) || o
};
}
function S(s, t) {
const e = typeof t == "string" ? { role: "user", content: t } : t;
return [...s, e];
}
export {
S as toOpenAIMessages,
m as transformOpenAIMessage
};