st-comp 0.0.249 → 0.0.251
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/VarietyAiHelper.cjs +3 -2
- package/es/VarietyAiHelper.js +220 -173
- package/es/aiTools.js +41 -8
- package/es/style.css +1 -1
- package/lib/aiTools.js +41 -8
- package/lib/bundle.js +1 -1
- package/lib/bundle.umd.cjs +9 -8
- package/lib/{index-6ac0579e.js → index-013031db.js} +504 -457
- package/lib/{python-0432340a.js → python-693b64f2.js} +1 -1
- package/lib/style.css +1 -1
- package/package.json +1 -1
- package/packages/VarietyAiHelper/index.vue +106 -33
- package/public/aiTools.js +41 -8
package/es/VarietyAiHelper.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const u=require("./base-ef747d02.cjs"),I=require("./el-dialog-1b185570.cjs");require("./el-overlay-ea65cb05.cjs");const C=require("./el-button-974ff9e9.cjs"),z=require("./el-input-fa18ef84.cjs"),e=require("vue"),N=require("./dayjs.min-2c20abe6.cjs"),S=require("./index-33f80550.cjs"),T=require("./_plugin-vue_export-helper-f246444f.cjs"),q=require("./index-6ca95c8a.cjs"),b=require("./use-form-common-props-d3ed62c6.cjs");require("./index-28e03bad.cjs");require("./index-9780a537.cjs");require("./index-bb833443.cjs");require("./index-f1c702f6.cjs");require("./vnode-b906ae6d.cjs");require("./scroll-b108dabd.cjs");require("./use-global-config-c80f33a4.cjs");require("./index-37b8d3c6.cjs");require("./index-eea0bcb3.cjs");require("./typescript-b63f8e83.cjs");require("./index-7dce9f59.cjs");require("./config-provider-2ae47cc8.cjs");const H=u.buildProps({size:{type:[Number,String],values:b.componentSizes,default:"",validator:s=>u.isNumber(s)},shape:{type:String,values:["circle","square"],default:"circle"},icon:{type:b.iconPropType},src:{type:String,default:""},alt:String,srcSet:String,fit:{type:u.definePropType(String),default:"cover"}}),M={error:s=>s instanceof Event},j=e.defineComponent({name:"ElAvatar"}),R=e.defineComponent({...j,props:H,emits:M,setup(s,{emit:g}){const d=s,a=u.useNamespace("avatar"),p=e.ref(!1),r=e.computed(()=>{const{size:t,icon:l,shape:o}=d,n=[a.b()];return u.isString(t)&&n.push(a.m(t)),l&&n.push(a.m("icon")),o&&n.push(a.m(o)),n}),i=e.computed(()=>{const{size:t}=d;return u.isNumber(t)?a.cssVarBlock({size:u.addUnit(t)||""}):void 0}),m=e.computed(()=>({objectFit:d.fit}));e.watch(()=>d.src,()=>p.value=!1);function f(t){p.value=!0,g("error",t)}return(t,l)=>(e.openBlock(),e.createElementBlock("span",{class:e.normalizeClass(e.unref(r)),style:e.normalizeStyle(e.unref(i))},[(t.src||t.srcSet)&&!p.value?(e.openBlock(),e.createElementBlock("img",{key:0,src:t.src,alt:t.alt,srcset:t.srcSet,style:e.normalizeStyle(e.unref(m)),onError:f},null,44,["src","alt","srcset"])):t.icon?(e.openBlock(),e.createBlock(e.unref(S.ElIcon),{key:1},{default:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(t.icon)))]),_:1})):e.renderSlot(t.$slots,"default",{key:2})],6))}});var $=u._export_sfc(R,[["__file","avatar.vue"]]);const D=u.withInstall($);const L=async({appId:s,apiKey:g,value:d,callback:a})=>{var p;try{const r=await fetch(`https://dashscope.aliyuncs.com/api/v1/apps/${s}/completion`,{method:"POST",body:JSON.stringify({input:{prompt:d},parameters:{incremental_output:"true"},debug:{}}),headers:{Authorization:`Bearer ${g}`,"Content-Type":"application/json","X-DashScope-SSE":"enable"}});if(!r.ok||!r.body)throw new Error("请求失败");const i=r.body.getReader(),m=new TextDecoder;for(;;){const{done:f,value:t}=await i.read();if(f&&a){a("finish","");break}try{const l=m.decode(t,{stream:!0}),o=JSON.parse(l.split(`
|
|
2
|
+
`)[3].substr(5)),n=(p=o==null?void 0:o.output)==null?void 0:p.text;n&&a&&a("message",n)}catch{}}}catch(r){console.error(r)}};const x=s=>(e.pushScopeId("data-v-46407344"),s=s(),e.popScopeId(),s),P={class:"chat-container"},K={class:"avatar"},F={class:"message-content"},O={class:"message-text"},J={class:"message-time"},U={key:0,class:"message-item assistant"},X={class:"avatar"},G=x(()=>e.createElementVNode("div",{class:"message-content"},[e.createElementVNode("div",{class:"typing-indicator"},[e.createElementVNode("span"),e.createElementVNode("span"),e.createElementVNode("span")])],-1)),Q={class:"input-area"},W={class:"input-actions"},Y=x(()=>e.createElementVNode("div",{class:"input-hint"},[e.createElementVNode("span",null,"Ctrl + Enter 发送")],-1)),Z={__name:"index",props:{defaultMessage:{type:String,default:`你好呀!我是你的品种池AI助手,会根据您的自然语言去进行品种的条件查询
|
|
2
3
|
|
|
3
4
|
示例:
|
|
4
|
-
|
|
5
|
+
帮我查A股科创板下品种转价差上证50并且总市值大于1千万, 按照总市值升序进行排序`}},emits:["callBack"],setup(s,{expose:g,emit:d}){const a=d,p=s,r=e.ref(!1),i=e.ref(!1),m=e.ref(!1),f=e.ref(null),t=e.ref([]),l=e.ref(""),o=e.ref(null),n=e.ref(-1),w=async()=>{const E=l.value.trim();if(!E)return q.ElMessage.warning("请输入消息内容");if(i.value)return;t.value.push({role:"user",time:N.dayjs().format("HH:mm"),content:E}),l.value="",await y();const _={role:"assistant",time:N.dayjs().format("HH:mm"),content:""};t.value.push(_),n.value=t.value.length-1,o.value=_,await y(),i.value=!0,m.value=!0;let v="";try{await L({appId:"9e54d112acfe4531bd1fc4fee8827fef",apiKey:"sk-d995eb26a4334bdeb2ccb4cbfaf51de8",value:E,callback:(V,h)=>{if(V==="message")v+=h,o.value&&(o.value.content=v,y());else if(V==="finish"){m.value=!1,i.value=!1,console.log(v);try{const c=JSON.parse(v);a("callBack",c)}catch{a("callBack",v)}o.value=null,n.value=-1}}})}catch(k){q.ElMessage.error(`AI响应异常: ${k}`),console.error("AI响应异常:",k),n.value!==-1&&(t.value.splice(n.value,1),o.value=null,n.value=-1),t.value.push({role:"assistant",time:N.dayjs().format("HH:mm"),content:"抱歉,AI服务响应异常,请稍后重试。"}),await y(),i.value=!1,m.value=!1}},y=async()=>{await e.nextTick(),f.value&&(f.value.scrollTop=f.value.scrollHeight)};return e.onMounted(()=>{t.value.push({role:"assistant",time:N.dayjs().format("HH:mm"),content:p.defaultMessage})}),e.watch(()=>t.value,()=>{y()},{deep:!0}),g({open:E=>{r.value=!0,e.nextTick(()=>{y()})}}),(E,_)=>{const v=D,k=z.ElInput,B=C.ElButton,V=I.ElDialog;return e.openBlock(),e.createBlock(V,{class:"ai-dialog",modelValue:r.value,"onUpdate:modelValue":_[1]||(_[1]=h=>r.value=h),title:"✨ 品种池参数解析AI助手",width:"500px",center:"",draggable:"",overflow:"",modal:!1,"modal-penetrable":!0},{default:e.withCtx(()=>{var h;return[e.createElementVNode("div",P,[e.createElementVNode("div",{ref_key:"messageListRef",ref:f,class:"message-list"},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.value,(c,A)=>(e.openBlock(),e.createElementBlock("div",{key:A,class:e.normalizeClass(["message-item",c.role])},[c.content?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createElementVNode("div",K,[e.createVNode(v,{size:32,icon:c.role==="user"?e.unref(S.user_filled_default):e.unref(S.service_default)},null,8,["icon"])]),e.createElementVNode("div",F,[e.createElementVNode("div",O,e.toDisplayString(c.content),1),e.createElementVNode("div",J,e.toDisplayString(c.time),1)])],64)):e.createCommentVNode("",!0)],2))),128)),m.value&&!((h=o.value)!=null&&h.content)?(e.openBlock(),e.createElementBlock("div",U,[e.createElementVNode("div",X,[e.createVNode(v,{size:32,icon:e.unref(S.service_default)},null,8,["icon"])]),G])):e.createCommentVNode("",!0)],512),e.createElementVNode("div",Q,[e.createVNode(k,{class:"message-input",modelValue:l.value,"onUpdate:modelValue":_[0]||(_[0]=c=>l.value=c),type:"textarea",rows:4,autosize:{minRows:2,maxRows:4},placeholder:"输入您想查询的品种条件...",onKeydown:e.withKeys(e.withModifiers(w,["ctrl"]),["enter"])},null,8,["modelValue","onKeydown"]),e.createElementVNode("div",W,[Y,e.createVNode(B,{class:"send-btn",type:"primary",icon:e.unref(S.promotion_default),loading:i.value,onClick:w,round:""},{default:e.withCtx(()=>[e.createTextVNode(" 发送 ")]),_:1},8,["icon","loading"])])])])]}),_:1},8,["modelValue"])}}},ee=T._export_sfc(Z,[["__scopeId","data-v-46407344"]]),te={install(s){s.component("st-varietyAiHelper",ee)}};module.exports=te;
|
package/es/VarietyAiHelper.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { b as
|
|
2
|
-
import { E as
|
|
1
|
+
import { b as F, p as P, e as q, u as X, c as G, n as Q, _ as W, w as Y } from "./base-29f73b05.js";
|
|
2
|
+
import { E as Z } from "./el-dialog-eedcfd3e.js";
|
|
3
3
|
import "./el-overlay-1ee0338d.js";
|
|
4
|
-
import { E as
|
|
5
|
-
import { E as
|
|
6
|
-
import { defineComponent as
|
|
7
|
-
import { d as
|
|
8
|
-
import { E as
|
|
9
|
-
import { _ as
|
|
10
|
-
import { E as
|
|
11
|
-
import { k as
|
|
4
|
+
import { E as ee } from "./el-button-e2c63c08.js";
|
|
5
|
+
import { E as te } from "./el-input-d47281da.js";
|
|
6
|
+
import { defineComponent as j, ref as u, computed as z, watch as D, openBlock as p, createElementBlock as w, normalizeClass as O, unref as h, normalizeStyle as N, createBlock as T, withCtx as V, resolveDynamicComponent as se, renderSlot as ae, onMounted as oe, nextTick as C, createElementVNode as t, Fragment as M, renderList as ne, createVNode as I, toDisplayString as R, createCommentVNode as L, withKeys as re, withModifiers as ie, createTextVNode as le, pushScopeId as ce, popScopeId as ue } from "vue";
|
|
7
|
+
import { d as x } from "./dayjs.min-8313b006.js";
|
|
8
|
+
import { E as pe, u as de, s as $, p as me } from "./index-c2b9bbfd.js";
|
|
9
|
+
import { _ as ve } from "./_plugin-vue_export-helper-dad06003.js";
|
|
10
|
+
import { E as K } from "./index-f30561d3.js";
|
|
11
|
+
import { k as fe, i as _e } from "./use-form-common-props-cb0ca65c.js";
|
|
12
12
|
import "./index-0f79095c.js";
|
|
13
13
|
import "./index-8391a3df.js";
|
|
14
14
|
import "./index-de24705f.js";
|
|
@@ -21,12 +21,12 @@ import "./index-657047bb.js";
|
|
|
21
21
|
import "./typescript-7ae59c4c.js";
|
|
22
22
|
import "./index-c71e37dc.js";
|
|
23
23
|
import "./config-provider-7860903c.js";
|
|
24
|
-
const
|
|
24
|
+
const he = F({
|
|
25
25
|
size: {
|
|
26
26
|
type: [Number, String],
|
|
27
|
-
values:
|
|
27
|
+
values: fe,
|
|
28
28
|
default: "",
|
|
29
|
-
validator: (
|
|
29
|
+
validator: (s) => P(s)
|
|
30
30
|
},
|
|
31
31
|
shape: {
|
|
32
32
|
type: String,
|
|
@@ -34,7 +34,7 @@ const me = j({
|
|
|
34
34
|
default: "circle"
|
|
35
35
|
},
|
|
36
36
|
icon: {
|
|
37
|
-
type:
|
|
37
|
+
type: _e
|
|
38
38
|
},
|
|
39
39
|
src: {
|
|
40
40
|
type: String,
|
|
@@ -43,149 +43,191 @@ const me = j({
|
|
|
43
43
|
alt: String,
|
|
44
44
|
srcSet: String,
|
|
45
45
|
fit: {
|
|
46
|
-
type:
|
|
46
|
+
type: q(String),
|
|
47
47
|
default: "cover"
|
|
48
48
|
}
|
|
49
|
-
}),
|
|
50
|
-
error: (
|
|
51
|
-
},
|
|
49
|
+
}), ye = {
|
|
50
|
+
error: (s) => s instanceof Event
|
|
51
|
+
}, ge = j({
|
|
52
52
|
name: "ElAvatar"
|
|
53
|
-
}),
|
|
54
|
-
...
|
|
55
|
-
props:
|
|
56
|
-
emits:
|
|
57
|
-
setup(
|
|
58
|
-
const
|
|
59
|
-
const { size: e, icon:
|
|
60
|
-
return
|
|
61
|
-
}),
|
|
62
|
-
const { size: e } =
|
|
63
|
-
return
|
|
64
|
-
size:
|
|
53
|
+
}), Se = /* @__PURE__ */ j({
|
|
54
|
+
...ge,
|
|
55
|
+
props: he,
|
|
56
|
+
emits: ye,
|
|
57
|
+
setup(s, { emit: b }) {
|
|
58
|
+
const d = s, a = X("avatar"), m = u(!1), r = z(() => {
|
|
59
|
+
const { size: e, icon: i, shape: o } = d, n = [a.b()];
|
|
60
|
+
return G(e) && n.push(a.m(e)), i && n.push(a.m("icon")), o && n.push(a.m(o)), n;
|
|
61
|
+
}), c = z(() => {
|
|
62
|
+
const { size: e } = d;
|
|
63
|
+
return P(e) ? a.cssVarBlock({
|
|
64
|
+
size: Q(e) || ""
|
|
65
65
|
}) : void 0;
|
|
66
|
-
}), v =
|
|
67
|
-
objectFit:
|
|
66
|
+
}), v = z(() => ({
|
|
67
|
+
objectFit: d.fit
|
|
68
68
|
}));
|
|
69
|
-
|
|
70
|
-
function
|
|
71
|
-
|
|
69
|
+
D(() => d.src, () => m.value = !1);
|
|
70
|
+
function f(e) {
|
|
71
|
+
m.value = !0, b("error", e);
|
|
72
72
|
}
|
|
73
|
-
return (e,
|
|
74
|
-
class:
|
|
75
|
-
style:
|
|
73
|
+
return (e, i) => (p(), w("span", {
|
|
74
|
+
class: O(h(r)),
|
|
75
|
+
style: N(h(c))
|
|
76
76
|
}, [
|
|
77
|
-
(e.src || e.srcSet) && !
|
|
77
|
+
(e.src || e.srcSet) && !m.value ? (p(), w("img", {
|
|
78
78
|
key: 0,
|
|
79
79
|
src: e.src,
|
|
80
80
|
alt: e.alt,
|
|
81
81
|
srcset: e.srcSet,
|
|
82
|
-
style:
|
|
83
|
-
onError:
|
|
84
|
-
}, null, 44, ["src", "alt", "srcset"])) : e.icon ? (p(),
|
|
85
|
-
default:
|
|
86
|
-
(p(),
|
|
82
|
+
style: N(h(v)),
|
|
83
|
+
onError: f
|
|
84
|
+
}, null, 44, ["src", "alt", "srcset"])) : e.icon ? (p(), T(h(pe), { key: 1 }, {
|
|
85
|
+
default: V(() => [
|
|
86
|
+
(p(), T(se(e.icon)))
|
|
87
87
|
]),
|
|
88
88
|
_: 1
|
|
89
|
-
})) :
|
|
89
|
+
})) : ae(e.$slots, "default", { key: 2 })
|
|
90
90
|
], 6));
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
|
-
var
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
var
|
|
93
|
+
var we = /* @__PURE__ */ W(Se, [["__file", "avatar.vue"]]);
|
|
94
|
+
const be = Y(we);
|
|
95
|
+
const Ee = async ({ appId: s, apiKey: b, value: d, callback: a }) => {
|
|
96
|
+
var m;
|
|
97
97
|
try {
|
|
98
|
-
const
|
|
98
|
+
const r = await fetch(`https://dashscope.aliyuncs.com/api/v1/apps/${s}/completion`, {
|
|
99
99
|
method: "POST",
|
|
100
|
-
headers: {
|
|
101
|
-
Authorization: `Bearer ${h}`,
|
|
102
|
-
"Content-Type": "application/json"
|
|
103
|
-
},
|
|
104
100
|
body: JSON.stringify({
|
|
105
|
-
input: { prompt:
|
|
101
|
+
input: { prompt: d },
|
|
106
102
|
parameters: {
|
|
107
|
-
incremental_output:
|
|
108
|
-
//
|
|
109
|
-
}
|
|
110
|
-
|
|
103
|
+
incremental_output: "true"
|
|
104
|
+
// 流式返回
|
|
105
|
+
},
|
|
106
|
+
debug: {}
|
|
107
|
+
}),
|
|
108
|
+
headers: {
|
|
109
|
+
Authorization: `Bearer ${b}`,
|
|
110
|
+
"Content-Type": "application/json",
|
|
111
|
+
"X-DashScope-SSE": "enable"
|
|
112
|
+
// 流式输出
|
|
113
|
+
}
|
|
111
114
|
});
|
|
112
|
-
if (!
|
|
113
|
-
throw new Error(
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
if (!r.ok || !r.body)
|
|
116
|
+
throw new Error("请求失败");
|
|
117
|
+
const c = r.body.getReader(), v = new TextDecoder();
|
|
118
|
+
for (; ; ) {
|
|
119
|
+
const { done: f, value: e } = await c.read();
|
|
120
|
+
if (f && a) {
|
|
121
|
+
a("finish", "");
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const i = v.decode(e, { stream: !0 }), o = JSON.parse(i.split(`
|
|
126
|
+
`)[3].substr(5)), n = (m = o == null ? void 0 : o.output) == null ? void 0 : m.text;
|
|
127
|
+
n && a && a("message", n);
|
|
128
|
+
} catch {
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} catch (r) {
|
|
132
|
+
console.error(r);
|
|
118
133
|
}
|
|
119
134
|
};
|
|
120
|
-
const
|
|
135
|
+
const J = (s) => (ce("data-v-46407344"), s = s(), ue(), s), ke = { class: "chat-container" }, Ae = { class: "avatar" }, Ie = { class: "message-content" }, xe = { class: "message-text" }, ze = { class: "message-time" }, Te = {
|
|
121
136
|
key: 0,
|
|
122
137
|
class: "message-item assistant"
|
|
123
|
-
},
|
|
138
|
+
}, Ve = { class: "avatar" }, Be = /* @__PURE__ */ J(() => /* @__PURE__ */ t("div", { class: "message-content" }, [
|
|
124
139
|
/* @__PURE__ */ t("div", { class: "typing-indicator" }, [
|
|
125
140
|
/* @__PURE__ */ t("span"),
|
|
126
141
|
/* @__PURE__ */ t("span"),
|
|
127
142
|
/* @__PURE__ */ t("span")
|
|
128
143
|
])
|
|
129
|
-
], -1)),
|
|
144
|
+
], -1)), He = { class: "input-area" }, Ne = { class: "input-actions" }, Ce = /* @__PURE__ */ J(() => /* @__PURE__ */ t("div", { class: "input-hint" }, [
|
|
130
145
|
/* @__PURE__ */ t("span", null, "Ctrl + Enter 发送")
|
|
131
|
-
], -1)),
|
|
146
|
+
], -1)), Me = {
|
|
132
147
|
__name: "index",
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
role: "assistant",
|
|
138
|
-
time: E().format("HH:mm"),
|
|
139
|
-
content: `你好呀!我是你的品种池AI助手,会根据您的自然语言去进行品种的条件查询
|
|
148
|
+
props: {
|
|
149
|
+
defaultMessage: {
|
|
150
|
+
type: String,
|
|
151
|
+
default: `你好呀!我是你的品种池AI助手,会根据您的自然语言去进行品种的条件查询
|
|
140
152
|
|
|
141
153
|
示例:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
154
|
+
帮我查A股科创板下品种转价差上证50并且总市值大于1千万, 按照总市值升序进行排序`
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
emits: ["callBack"],
|
|
158
|
+
setup(s, { expose: b, emit: d }) {
|
|
159
|
+
const a = d, m = s, r = u(!1), c = u(!1), v = u(!1), f = u(null), e = u([]), i = u(""), o = u(null), n = u(-1), B = async () => {
|
|
160
|
+
const E = i.value.trim();
|
|
161
|
+
if (!E)
|
|
162
|
+
return K.warning("请输入消息内容");
|
|
163
|
+
if (c.value)
|
|
149
164
|
return;
|
|
150
|
-
|
|
165
|
+
e.value.push({
|
|
151
166
|
role: "user",
|
|
152
|
-
time:
|
|
153
|
-
content:
|
|
154
|
-
}),
|
|
155
|
-
|
|
167
|
+
time: x().format("HH:mm"),
|
|
168
|
+
content: E
|
|
169
|
+
}), i.value = "", await g();
|
|
170
|
+
const y = {
|
|
171
|
+
role: "assistant",
|
|
172
|
+
time: x().format("HH:mm"),
|
|
173
|
+
content: ""
|
|
174
|
+
};
|
|
175
|
+
e.value.push(y), n.value = e.value.length - 1, o.value = y, await g(), c.value = !0, v.value = !0;
|
|
176
|
+
let _ = "";
|
|
156
177
|
try {
|
|
157
|
-
|
|
178
|
+
await Ee({
|
|
179
|
+
appId: "9e54d112acfe4531bd1fc4fee8827fef",
|
|
180
|
+
apiKey: "sk-d995eb26a4334bdeb2ccb4cbfaf51de8",
|
|
181
|
+
value: E,
|
|
182
|
+
callback: (A, S) => {
|
|
183
|
+
if (A === "message")
|
|
184
|
+
_ += S, o.value && (o.value.content = _, g());
|
|
185
|
+
else if (A === "finish") {
|
|
186
|
+
v.value = !1, c.value = !1, console.log(_);
|
|
187
|
+
try {
|
|
188
|
+
const l = JSON.parse(_);
|
|
189
|
+
a("callBack", l);
|
|
190
|
+
} catch {
|
|
191
|
+
a("callBack", _);
|
|
192
|
+
}
|
|
193
|
+
o.value = null, n.value = -1;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
} catch (k) {
|
|
198
|
+
K.error(`AI响应异常: ${k}`), console.error("AI响应异常:", k), n.value !== -1 && (e.value.splice(n.value, 1), o.value = null, n.value = -1), e.value.push({
|
|
158
199
|
role: "assistant",
|
|
159
|
-
time:
|
|
160
|
-
content:
|
|
161
|
-
}), await
|
|
162
|
-
} catch (y) {
|
|
163
|
-
B.error(`AI响应异常: ${y}`), console.error("AI响应异常:", y);
|
|
164
|
-
} finally {
|
|
165
|
-
n.value = !1, f.value = !1;
|
|
200
|
+
time: x().format("HH:mm"),
|
|
201
|
+
content: "抱歉,AI服务响应异常,请稍后重试。"
|
|
202
|
+
}), await g(), c.value = !1, v.value = !1;
|
|
166
203
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
await I(), v.value && (v.value.scrollTop = v.value.scrollHeight);
|
|
204
|
+
}, g = async () => {
|
|
205
|
+
await C(), f.value && (f.value.scrollTop = f.value.scrollHeight);
|
|
170
206
|
};
|
|
171
|
-
return
|
|
172
|
-
|
|
207
|
+
return oe(() => {
|
|
208
|
+
e.value.push({
|
|
209
|
+
role: "assistant",
|
|
210
|
+
time: x().format("HH:mm"),
|
|
211
|
+
content: m.defaultMessage
|
|
212
|
+
});
|
|
213
|
+
}), D(
|
|
214
|
+
() => e.value,
|
|
173
215
|
() => {
|
|
174
|
-
|
|
216
|
+
g();
|
|
175
217
|
},
|
|
176
218
|
{ deep: !0 }
|
|
177
|
-
),
|
|
178
|
-
open: (
|
|
179
|
-
|
|
180
|
-
|
|
219
|
+
), b({
|
|
220
|
+
open: (E) => {
|
|
221
|
+
r.value = !0, C(() => {
|
|
222
|
+
g();
|
|
181
223
|
});
|
|
182
224
|
}
|
|
183
|
-
}), (
|
|
184
|
-
const
|
|
185
|
-
return p(),
|
|
225
|
+
}), (E, y) => {
|
|
226
|
+
const _ = be, k = te, H = ee, A = Z;
|
|
227
|
+
return p(), T(A, {
|
|
186
228
|
class: "ai-dialog",
|
|
187
|
-
modelValue:
|
|
188
|
-
"onUpdate:modelValue":
|
|
229
|
+
modelValue: r.value,
|
|
230
|
+
"onUpdate:modelValue": y[1] || (y[1] = (S) => r.value = S),
|
|
189
231
|
title: "✨ 品种池参数解析AI助手",
|
|
190
232
|
width: "500px",
|
|
191
233
|
center: "",
|
|
@@ -194,77 +236,82 @@ const L = (a) => (oe("data-v-3b75cb12"), a = a(), ne(), a), ge = { class: "chat-
|
|
|
194
236
|
modal: !1,
|
|
195
237
|
"modal-penetrable": !0
|
|
196
238
|
}, {
|
|
197
|
-
default:
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
key: R,
|
|
206
|
-
class: $(["message-item", c.role])
|
|
239
|
+
default: V(() => {
|
|
240
|
+
var S;
|
|
241
|
+
return [
|
|
242
|
+
t("div", ke, [
|
|
243
|
+
t("div", {
|
|
244
|
+
ref_key: "messageListRef",
|
|
245
|
+
ref: f,
|
|
246
|
+
class: "message-list"
|
|
207
247
|
}, [
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
class: "message-input",
|
|
232
|
-
modelValue: e.value,
|
|
233
|
-
"onUpdate:modelValue": l[0] || (l[0] = (c) => e.value = c),
|
|
234
|
-
type: "textarea",
|
|
235
|
-
rows: 4,
|
|
236
|
-
autosize: { minRows: 2, maxRows: 4 },
|
|
237
|
-
placeholder: "输入您想查询的品种条件...",
|
|
238
|
-
onKeydown: te(se(g, ["ctrl"]), ["enter"])
|
|
239
|
-
}, null, 8, ["modelValue", "onKeydown"]),
|
|
240
|
-
t("div", Ie, [
|
|
241
|
-
ze,
|
|
242
|
-
b(P, {
|
|
243
|
-
class: "send-btn",
|
|
244
|
-
type: "primary",
|
|
245
|
-
icon: u(le),
|
|
246
|
-
loading: n.value,
|
|
247
|
-
onClick: g,
|
|
248
|
-
round: ""
|
|
249
|
-
}, {
|
|
250
|
-
default: T(() => [
|
|
251
|
-
ae(" 发送 ")
|
|
248
|
+
(p(!0), w(M, null, ne(e.value, (l, U) => (p(), w("div", {
|
|
249
|
+
key: U,
|
|
250
|
+
class: O(["message-item", l.role])
|
|
251
|
+
}, [
|
|
252
|
+
l.content ? (p(), w(M, { key: 0 }, [
|
|
253
|
+
t("div", Ae, [
|
|
254
|
+
I(_, {
|
|
255
|
+
size: 32,
|
|
256
|
+
icon: l.role === "user" ? h(de) : h($)
|
|
257
|
+
}, null, 8, ["icon"])
|
|
258
|
+
]),
|
|
259
|
+
t("div", Ie, [
|
|
260
|
+
t("div", xe, R(l.content), 1),
|
|
261
|
+
t("div", ze, R(l.time), 1)
|
|
262
|
+
])
|
|
263
|
+
], 64)) : L("", !0)
|
|
264
|
+
], 2))), 128)),
|
|
265
|
+
v.value && !((S = o.value) != null && S.content) ? (p(), w("div", Te, [
|
|
266
|
+
t("div", Ve, [
|
|
267
|
+
I(_, {
|
|
268
|
+
size: 32,
|
|
269
|
+
icon: h($)
|
|
270
|
+
}, null, 8, ["icon"])
|
|
252
271
|
]),
|
|
253
|
-
|
|
254
|
-
|
|
272
|
+
Be
|
|
273
|
+
])) : L("", !0)
|
|
274
|
+
], 512),
|
|
275
|
+
t("div", He, [
|
|
276
|
+
I(k, {
|
|
277
|
+
class: "message-input",
|
|
278
|
+
modelValue: i.value,
|
|
279
|
+
"onUpdate:modelValue": y[0] || (y[0] = (l) => i.value = l),
|
|
280
|
+
type: "textarea",
|
|
281
|
+
rows: 4,
|
|
282
|
+
autosize: { minRows: 2, maxRows: 4 },
|
|
283
|
+
placeholder: "输入您想查询的品种条件...",
|
|
284
|
+
onKeydown: re(ie(B, ["ctrl"]), ["enter"])
|
|
285
|
+
}, null, 8, ["modelValue", "onKeydown"]),
|
|
286
|
+
t("div", Ne, [
|
|
287
|
+
Ce,
|
|
288
|
+
I(H, {
|
|
289
|
+
class: "send-btn",
|
|
290
|
+
type: "primary",
|
|
291
|
+
icon: h(me),
|
|
292
|
+
loading: c.value,
|
|
293
|
+
onClick: B,
|
|
294
|
+
round: ""
|
|
295
|
+
}, {
|
|
296
|
+
default: V(() => [
|
|
297
|
+
le(" 发送 ")
|
|
298
|
+
]),
|
|
299
|
+
_: 1
|
|
300
|
+
}, 8, ["icon", "loading"])
|
|
301
|
+
])
|
|
255
302
|
])
|
|
256
303
|
])
|
|
257
|
-
]
|
|
258
|
-
|
|
304
|
+
];
|
|
305
|
+
}),
|
|
259
306
|
_: 1
|
|
260
307
|
}, 8, ["modelValue"]);
|
|
261
308
|
};
|
|
262
309
|
}
|
|
263
|
-
},
|
|
264
|
-
install(
|
|
265
|
-
|
|
310
|
+
}, Re = /* @__PURE__ */ ve(Me, [["__scopeId", "data-v-46407344"]]), rt = {
|
|
311
|
+
install(s) {
|
|
312
|
+
s.component("st-varietyAiHelper", Re);
|
|
266
313
|
}
|
|
267
314
|
};
|
|
268
315
|
export {
|
|
269
|
-
|
|
316
|
+
rt as default
|
|
270
317
|
};
|
package/es/aiTools.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* 发送非流式请求到百炼 AI 应用
|
|
3
|
-
* @param {Object} options
|
|
4
|
-
* @param {string} options.appId - 应用ID
|
|
5
|
-
* @param {string} options.apiKey - API Key
|
|
6
|
-
* @param {string} options.value - 用户输入
|
|
7
|
-
* @returns {Promise<string>} 返回 AI 输出的完整文本(JSON 字符串)
|
|
8
|
-
*/
|
|
1
|
+
// 非流式返回
|
|
9
2
|
export const sendToBaiLianAppNonStreaming = async ({ appId, apiKey, value }) => {
|
|
10
3
|
try {
|
|
11
4
|
const response = await fetch(`https://dashscope.aliyuncs.com/api/v1/apps/${appId}/completion`, {
|
|
@@ -34,3 +27,43 @@ export const sendToBaiLianAppNonStreaming = async ({ appId, apiKey, value }) =>
|
|
|
34
27
|
throw error;
|
|
35
28
|
}
|
|
36
29
|
};
|
|
30
|
+
// 流式返回
|
|
31
|
+
export const sendToBaiLianAppStreaming = async ({ appId, apiKey, value, callback }) => {
|
|
32
|
+
try {
|
|
33
|
+
const res = await fetch(`https://dashscope.aliyuncs.com/api/v1/apps/${appId}/completion`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
body: JSON.stringify({
|
|
36
|
+
input: { prompt: value },
|
|
37
|
+
parameters: {
|
|
38
|
+
incremental_output: "true", // 流式返回
|
|
39
|
+
},
|
|
40
|
+
debug: {},
|
|
41
|
+
}),
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: `Bearer ${apiKey}`,
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
"X-DashScope-SSE": "enable", // 流式输出
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
if (!res.ok || !res.body) throw new Error("请求失败");
|
|
49
|
+
|
|
50
|
+
const reader = res.body.getReader();
|
|
51
|
+
const decoder = new TextDecoder();
|
|
52
|
+
|
|
53
|
+
while (true) {
|
|
54
|
+
const { done, value } = await reader.read();
|
|
55
|
+
if (done && callback) {
|
|
56
|
+
callback("finish", "");
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const data = decoder.decode(value, { stream: true });
|
|
61
|
+
const resData = JSON.parse(data.split("\n")[3].substr(5));
|
|
62
|
+
const resText = resData?.output?.text;
|
|
63
|
+
if (resText && callback) callback("message", resText);
|
|
64
|
+
} catch (error) {}
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(error);
|
|
68
|
+
}
|
|
69
|
+
};
|