UNPKG

ant-design-x-vue-next

Version:

Ant Design X for Vue — community continuation aligned with @ant-design/x

38 lines (33 loc) 1.56 kB
function $(n) { return typeof n == "string" ? n : n && typeof n == "object" && "text" in n && n.text || ""; } function x(n) { var S, y, m; const { originMessage: a, chunk: s, responseHeaders: o } = n; let f = "", r = "", p = "assistant"; try { let l; if (((o == null ? void 0 : o.get("content-type")) || "").includes("text/event-stream") || typeof (s == null ? void 0 : s.data) == "string") { const t = s == null ? void 0 : s.data; t && String(t).trim() !== "[DONE]" && (l = typeof t == "string" ? JSON.parse(t) : t); } else s && (l = s); l && ((S = l == null ? void 0 : l.choices) == null || S.forEach((t) => { t != null && t.delta ? (r = t.delta.reasoning_content || "", f += t.delta.content || "", p = t.delta.role || p) : t != null && t.message && (r = t.message.reasoning_content || "", f += t.message.content || "", p = t.message.role || p); })); } catch (l) { console.error("[DeepSeekChatProvider] transformMessage error", l); } let e = $(a == null ? void 0 : a.content), d = ""; return !e && r ? d = ` <think> ${(y = r == null ? void 0 : r.replace) == null ? void 0 : y.call(r, /^\n{0,2}/, "")}` : e.includes("<think>") && !e.includes("</think>") && f ? (e = e.replace("<think>", '<think status="done">'), d = `${(m = e == null ? void 0 : e.replace) == null ? void 0 : m.call(e, /[\s\n]{0,2}$/, "")} </think> ${f}`) : d = `${e || ""}${r}${f}`, { ...a || {}, content: d, role: p || (a == null ? void 0 : a.role) || "assistant" }; } export { x as transformDeepSeekMessage };