st-comp 0.0.261 → 0.0.263

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "st-comp",
3
3
  "public": true,
4
- "version": "0.0.261",
4
+ "version": "0.0.263",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -223,7 +223,7 @@ const drawSub = () => {
223
223
  }
224
224
 
225
225
  requestAnimationFrame(() => {
226
- klineSubRef.value.draw({ startValue, endValue, maxValueSpan: maxShowCounts }, { gridLeft, gridRight });
226
+ klineSubRef.value?.draw({ startValue, endValue, maxValueSpan: maxShowCounts }, { gridLeft, gridRight });
227
227
  });
228
228
  };
229
229
  // 图表渲染: 预警线
@@ -2,7 +2,8 @@
2
2
  <script setup name="FactorScreen">
3
3
  import { nextTick, ref, watch, inject, reactive } from "vue";
4
4
  import { Close, Plus, CircleCloseFilled, InfoFilled, Document } from "@element-plus/icons-vue";
5
- import { handleVerifyScore, extractConditionDetails, extractVariables, sendToAi } from "./tools.js";
5
+ import { handleVerifyScore, extractConditionDetails, extractVariables } from "./tools.js";
6
+ import { sendToBaiLianAppStreaming } from "../../../../public/aiTools";
6
7
  import FactorDescription from "./FactorDescription.vue";
7
8
  import MonacoEditor from "../../../MonacoEditor/index.vue";
8
9
 
@@ -395,12 +396,24 @@ const handleTestAi = () => {
395
396
  const apiKey = "sk-d995eb26a4334bdeb2ccb4cbfaf51de8";
396
397
  scriptAILoading.value = true;
397
398
  scriptTestResult.ai = "";
398
- sendToAi(appId, apiKey, scriptTestResult.code, (type, res) => {
399
- if (type === "finish") {
400
- scriptAILoading.value = false;
401
- return;
402
- }
403
- scriptTestResult.ai = scriptTestResult.ai + res;
399
+ let fullResponse = "";
400
+ sendToBaiLianAppStreaming({
401
+ appId,
402
+ apiKey,
403
+ value: scriptTestResult.code,
404
+ callback: (type, data) => {
405
+ // 百炼应用错误
406
+ if (type === "error") return;
407
+ // 流式输出(正常)
408
+ else if (type === "message") {
409
+ fullResponse += data;
410
+ scriptTestResult.ai = fullResponse;
411
+ }
412
+ // 流式输出(完毕)
413
+ else if (type === "finish") {
414
+ scriptAILoading.value = false;
415
+ }
416
+ },
404
417
  });
405
418
  };
406
419
 
@@ -32,44 +32,3 @@ export const extractVariables = (content) => {
32
32
 
33
33
  return [...new Set(variables)]; // 去重
34
34
  };
35
-
36
- // 发送AI
37
- export const sendToAi = async (appId, apiKey, value, callback) => {
38
- try {
39
- const res = await fetch(`https://dashscope.aliyuncs.com/api/v1/apps/${appId}/completion`, {
40
- method: "POST",
41
- body: JSON.stringify({
42
- input: { prompt: value },
43
- parameters: {
44
- incremental_output: "true", // 流式返回
45
- },
46
- debug: {},
47
- }),
48
- headers: {
49
- Authorization: `Bearer ${apiKey}`,
50
- "Content-Type": "application/json",
51
- "X-DashScope-SSE": "enable", // 流式输出
52
- },
53
- });
54
- if (!res.ok || !res.body) throw new Error("请求失败");
55
-
56
- const reader = res.body.getReader();
57
- const decoder = new TextDecoder();
58
-
59
- while (true) {
60
- const { done, value } = await reader.read();
61
- if (done && callback) {
62
- callback("finish", "");
63
- break;
64
- }
65
- try {
66
- const data = decoder.decode(value, { stream: true });
67
- const resData = JSON.parse(data.split("\n")[3].substr(5));
68
- const resText = resData?.output?.text;
69
- if (resText && callback) callback("message", resText);
70
- } catch (error) {}
71
- }
72
- } catch (error) {
73
- console.error(error);
74
- }
75
- };