From e21ba1b800e661e8acf98246e109f70aa4018682 Mon Sep 17 00:00:00 2001 From: spark Date: Tue, 18 Feb 2025 12:32:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend/backend):=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=97=A5K=E7=BA=BF=E6=95=B0=E6=8D=AE=E5=A4=A9=E6=95=B0?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在前端设置页面添加日 K 线数据天数配置选项 - 在后端 OpenAI 配置中添加 KDays 字段 - 调整股票数据分析时的历史数据时间范围 --- backend/data/openai_api.go | 7 ++++++- backend/data/settings_api.go | 15 +++++++++++++++ frontend/src/components/settings.vue | 9 ++++++++- frontend/src/components/stock.vue | 2 +- frontend/wailsjs/go/models.ts | 2 ++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/backend/data/openai_api.go b/backend/data/openai_api.go index 7cc0f36..e4f3dd4 100644 --- a/backend/data/openai_api.go +++ b/backend/data/openai_api.go @@ -33,6 +33,7 @@ type OpenAi struct { TimeOut int `json:"time_out"` QuestionTemplate string `json:"question_template"` CrawlTimeOut int64 `json:"crawl_time_out"` + KDays int64 `json:"kDays"` } func NewDeepSeekOpenAi(ctx context.Context) *OpenAi { @@ -44,6 +45,9 @@ func NewDeepSeekOpenAi(ctx context.Context) *OpenAi { if config.CrawlTimeOut <= 0 { config.CrawlTimeOut = 60 } + if config.KDays < 30 { + config.KDays = 30 + } } return &OpenAi{ ctx: ctx, @@ -56,6 +60,7 @@ func NewDeepSeekOpenAi(ctx context.Context) *OpenAi { TimeOut: config.OpenAiApiTimeOut, QuestionTemplate: config.QuestionTemplate, CrawlTimeOut: config.CrawlTimeOut, + KDays: config.KDays, } } @@ -146,7 +151,7 @@ func (o OpenAi) NewChatStream(stock, stockCode, userQuestion string) <-chan map[ go func() { defer wg.Done() endDate := time.Now().Format("20060102") - startDate := time.Now().Add(-time.Hour * 24 * 365).Format("20060102") + startDate := time.Now().Add(-time.Hour * time.Duration(24*o.KDays)).Format("20060102") K := NewTushareApi(getConfig()).GetDaily(ConvertStockCodeToTushareCode(stockCode), startDate, endDate, o.CrawlTimeOut) msg = append(msg, map[string]interface{}{ "role": "assistant", diff --git a/backend/data/settings_api.go b/backend/data/settings_api.go index 71c1ca1..e8ad404 100644 --- a/backend/data/settings_api.go +++ b/backend/data/settings_api.go @@ -27,6 +27,7 @@ type Settings struct { CheckUpdate bool `json:"checkUpdate"` QuestionTemplate string `json:"questionTemplate"` CrawlTimeOut int64 `json:"crawlTimeOut"` + KDays int64 `json:"kDays"` } func (receiver Settings) TableName() string { @@ -65,6 +66,7 @@ func (s SettingsApi) UpdateConfig() string { "open_ai_api_time_out": s.Config.OpenAiApiTimeOut, "question_template": s.Config.QuestionTemplate, "crawl_time_out": s.Config.CrawlTimeOut, + "k_days": s.Config.KDays, }) } else { logger.SugaredLogger.Infof("未找到配置,创建默认配置:%+v", s.Config) @@ -86,6 +88,7 @@ func (s SettingsApi) UpdateConfig() string { OpenAiApiTimeOut: s.Config.OpenAiApiTimeOut, QuestionTemplate: s.Config.QuestionTemplate, CrawlTimeOut: s.Config.CrawlTimeOut, + KDays: s.Config.KDays, }) } return "保存成功!" @@ -93,6 +96,18 @@ func (s SettingsApi) UpdateConfig() string { func (s SettingsApi) GetConfig() *Settings { var settings Settings db.Dao.Model(&Settings{}).First(&settings) + + if settings.OpenAiEnable { + if settings.OpenAiApiTimeOut <= 0 { + settings.OpenAiApiTimeOut = 60 * 5 + } + if settings.CrawlTimeOut <= 0 { + settings.CrawlTimeOut = 60 + } + if settings.KDays < 30 { + settings.KDays = 30 + } + } return &settings } diff --git a/frontend/src/components/settings.vue b/frontend/src/components/settings.vue index 10320a3..f25b75e 100644 --- a/frontend/src/components/settings.vue +++ b/frontend/src/components/settings.vue @@ -31,6 +31,7 @@ const formValue = ref({ timeout: 5, questionTemplate: "{{stockName}}分析和总结", crawlTimeOut:30, + kDays:30, } }) @@ -58,6 +59,7 @@ onMounted(()=>{ timeout:res.openAiApiTimeOut, questionTemplate:res.questionTemplate?res.questionTemplate:'{{stockName}}分析和总结', crawlTimeOut:res.crawlTimeOut, + kDays:res.kDays, } console.log(res) }) @@ -84,6 +86,7 @@ function saveConfig(){ openAiApiTimeOut:formValue.value.openAI.timeout, questionTemplate:formValue.value.openAI.questionTemplate, crawlTimeOut:formValue.value.openAI.crawlTimeOut, + kDays:formValue.value.openAI.kDays }) //console.log("Settings",config) @@ -152,6 +155,7 @@ function importConfig(){ timeout:config.openAiApiTimeOut, questionTemplate:config.questionTemplate, crawlTimeOut:config.crawlTimeOut, + kDays:config.kDays } // formRef.value.resetFields() }; @@ -240,9 +244,12 @@ window.onerror = function (event, source, lineno, colno, error) { - + + + + -