mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
refactor(backend):重构数据处理和前端AI分析结果展示
- 新增 Resp 结构体用于统一响应格式- 优化 OpenAI API 流数据处理逻辑,解析并展示具体错误信息 - 更新前端 stock组件,改进 AI 分析结果的接收和展示 - 调整代码格式,提高可读性
This commit is contained in:
parent
e21ba1b800
commit
34ac6755a9
@ -406,13 +406,16 @@ func (o OpenAi) NewChatStream(stock, stockCode, userQuestion string) <-chan map[
|
||||
}
|
||||
} else {
|
||||
if strutil.RemoveNonPrintable(line) != "" {
|
||||
//ch <- line
|
||||
ch <- map[string]any{
|
||||
"code": 0,
|
||||
"question": question,
|
||||
"content": line,
|
||||
}
|
||||
logger.SugaredLogger.Infof("Stream data error : %s", line)
|
||||
res := &models.Resp{}
|
||||
if err := json.Unmarshal([]byte(line), res); err == nil {
|
||||
//ch <- line
|
||||
ch <- map[string]any{
|
||||
"code": 0,
|
||||
"question": question,
|
||||
"content": res.Message,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -162,3 +162,8 @@ type VersionInfo struct {
|
||||
func (receiver VersionInfo) TableName() string {
|
||||
return "version_info"
|
||||
}
|
||||
|
||||
type Resp struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
@ -1,14 +1,20 @@
|
||||
<script setup>
|
||||
import {computed, h, onBeforeMount, onBeforeUnmount, onMounted, reactive, ref} from 'vue'
|
||||
import {
|
||||
Follow, GetConfig,
|
||||
Follow,
|
||||
GetAIResponseResult,
|
||||
GetConfig,
|
||||
GetFollowList,
|
||||
GetStockList,
|
||||
Greet, SaveAIResponseResult, NewChatStream,
|
||||
SendDingDingMessage, SendDingDingMessageByType,
|
||||
GetVersionInfo,
|
||||
Greet,
|
||||
NewChatStream,
|
||||
SaveAIResponseResult,
|
||||
SendDingDingMessageByType,
|
||||
SetAlarmChangePercent,
|
||||
SetCostPriceAndVolume, SetStockSort,
|
||||
UnFollow, GetAIResponseResult, GetVersionInfo
|
||||
SetCostPriceAndVolume,
|
||||
SetStockSort,
|
||||
UnFollow
|
||||
} from '../../wailsjs/go/main/App'
|
||||
import {
|
||||
NAvatar,
|
||||
@ -18,17 +24,18 @@ import {
|
||||
NFormItem,
|
||||
NInputNumber,
|
||||
NText,
|
||||
useMessage,
|
||||
useDialog,
|
||||
useMessage,
|
||||
useModal,
|
||||
useNotification
|
||||
} from 'naive-ui'
|
||||
import {EventsEmit, EventsOn, WindowFullscreen, WindowReload, WindowUnfullscreen} from '../../wailsjs/runtime'
|
||||
import {Add, Search,StarOutline} from '@vicons/ionicons5'
|
||||
import { MdPreview } from 'md-editor-v3';
|
||||
import {Add} from '@vicons/ionicons5'
|
||||
import {MdPreview} from 'md-editor-v3';
|
||||
// preview.css相比style.css少了编辑器那部分样式
|
||||
import 'md-editor-v3/lib/preview.css';
|
||||
import html2canvas from "html2canvas";
|
||||
|
||||
const mdPreviewRef = ref(null)
|
||||
const message = useMessage()
|
||||
const modal = useModal()
|
||||
@ -162,20 +169,25 @@ EventsOn("refreshFollowList",(data)=>{
|
||||
EventsOn("newChatStream",async (msg) => {
|
||||
//console.log("newChatStream:->",data.airesult)
|
||||
data.loading = false
|
||||
//console.log(msg)
|
||||
if (msg === "DONE") {
|
||||
SaveAIResponseResult(data.code, data.name, data.airesult, data.chatId,data.question)
|
||||
message.info("AI分析完成!")
|
||||
message.destroyAll()
|
||||
} else {
|
||||
if(msg.code===1){
|
||||
if(msg.chatId){
|
||||
data.chatId = msg.chatId
|
||||
}
|
||||
if(msg.question){
|
||||
data.question = msg.question
|
||||
}
|
||||
data.airesult = data.airesult + (msg.content||msg.extraContent)
|
||||
}
|
||||
if(msg.content){
|
||||
data.airesult = data.airesult + msg.content
|
||||
}
|
||||
if(msg.extraContent){
|
||||
data.airesult = data.airesult + msg.extraContent
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
@ -530,8 +542,7 @@ function aiCheckStock(stock,stockCode){
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
data.time=formattedDate
|
||||
data.time=`${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
||||
}else{
|
||||
data.modelName=""
|
||||
data.airesult=""
|
||||
|
Loading…
x
Reference in New Issue
Block a user