UNPKG

ant-design-x-vue-next

Version:

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

10 lines (5 loc) 1.29 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function m(n){return typeof n=="string"?n:n&&typeof n=="object"&&"text"in n&&n.text||""}function u(n){var S,y,i;const{originMessage:l,chunk:s,responseHeaders:d}=n;let f="",r="",o="assistant";try{let a;if(((d==null?void 0:d.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]"&&(a=typeof t=="string"?JSON.parse(t):t)}else s&&(a=s);a&&((S=a==null?void 0:a.choices)==null||S.forEach(t=>{t!=null&&t.delta?(r=t.delta.reasoning_content||"",f+=t.delta.content||"",o=t.delta.role||o):t!=null&&t.message&&(r=t.message.reasoning_content||"",f+=t.message.content||"",o=t.message.role||o)}))}catch(a){console.error("[DeepSeekChatProvider] transformMessage error",a)}let e=m(l==null?void 0:l.content),p="";return!e&&r?p=` <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">'),p=`${(i=e==null?void 0:e.replace)==null?void 0:i.call(e,/[\s\n]{0,2}$/,"")} </think> ${f}`):p=`${e||""}${r}${f}`,{...l||{},content:p,role:o||(l==null?void 0:l.role)||"assistant"}}exports.transformDeepSeekMessage=u;