fix bug
This commit is contained in:
@@ -37,15 +37,16 @@ func main() {
|
|||||||
|
|
||||||
// 过滤无需AI分析
|
// 过滤无需AI分析
|
||||||
if model.StScore > 0 && model.IndustryScore > 0 && model.GtPrice > 0 && model.GtAmount > 0 && model.GtRoe > 0 && model.ScoreRsi > 0 {
|
if model.StScore > 0 && model.IndustryScore > 0 && model.GtPrice > 0 && model.GtAmount > 0 && model.GtRoe > 0 && model.ScoreRsi > 0 {
|
||||||
stratRule.RunAi(code)
|
model.AiScore = 0 // 待分析
|
||||||
} else {
|
} else {
|
||||||
model.AiScore = -2
|
model.AiScore = -2
|
||||||
model.AddDesc("无需AI分析")
|
model.AddDesc("无需AI分析")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
model.Save()
|
model.Save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strategy.BootAiStart("selector", models.GetYmd())
|
||||||
}
|
}
|
||||||
|
|
||||||
func ai() {
|
func ai() {
|
||||||
@@ -53,11 +54,6 @@ func ai() {
|
|||||||
config.New(ServiceKey)
|
config.New(ServiceKey)
|
||||||
impl.NewImpl()
|
impl.NewImpl()
|
||||||
|
|
||||||
code := "601899.SH"
|
|
||||||
model := models.NewStratModel("selector", code)
|
|
||||||
stratRule := rule.NewRule(model)
|
|
||||||
stratRule.RunAi(code)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main3() {
|
func main3() {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package rule
|
package strategy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -17,19 +18,15 @@ var (
|
|||||||
MarkdataPath = "./markdata/"
|
MarkdataPath = "./markdata/"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *RuleFactory) RunAi(code string) {
|
func AiAnalysis(code string) (map[string]any, error) {
|
||||||
mdPath := MarkdataPath + code + ".md"
|
mdPath := MarkdataPath + code + ".md"
|
||||||
if !utils.PathExists(mdPath) {
|
if !utils.PathExists(mdPath) {
|
||||||
r.Model.AiScore = -1
|
return nil, errors.New(fmt.Sprintf("%s markdown 文件未找友", mdPath))
|
||||||
r.Model.AddDesc(fmt.Sprintf("%s markdown 文件未找友", mdPath))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := os.ReadFile(mdPath)
|
content, err := os.ReadFile(mdPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Model.AiScore = -1
|
return nil, errors.New(fmt.Sprintf("%s markdown 读取错误,%v", mdPath, err))
|
||||||
r.Model.AddDesc(fmt.Sprintf("%s markdown 读取错误,%v", mdPath, err))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client, _ := deepseek.NewClient(config.Spec.DeepSeekApiKey)
|
client, _ := deepseek.NewClient(config.Spec.DeepSeekApiKey)
|
||||||
@@ -51,9 +48,7 @@ func (r *RuleFactory) RunAi(code string) {
|
|||||||
|
|
||||||
chatResp, err := client.CallChatCompletionsChat(context.Background(), chatReq)
|
chatResp, err := client.CallChatCompletionsChat(context.Background(), chatReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Model.AiScore = -1
|
return nil, errors.New(fmt.Sprintf("处理失败: %v", err))
|
||||||
r.Model.AddDesc(fmt.Sprintf("处理失败: %v", err))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 输出JSON格式的结果
|
// 输出JSON格式的结果
|
||||||
@@ -63,21 +58,19 @@ func (r *RuleFactory) RunAi(code string) {
|
|||||||
var result map[string]any
|
var result map[string]any
|
||||||
err = json.Unmarshal([]byte(jsonBodys), &result)
|
err = json.Unmarshal([]byte(jsonBodys), &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Model.AiScore = -1
|
return nil, errors.New(fmt.Sprintf("Unmarshal: %v", err))
|
||||||
r.Model.AddDesc(fmt.Sprintf("Unmarshal: %v", err))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Model.AiSummary = result["summary"].(string)
|
// r.Model.AiSummary = result["summary"].(string)
|
||||||
r.Model.AiSummary2025 = result["summary_2025"].(string)
|
// r.Model.AiSummary2025 = result["summary_2025"].(string)
|
||||||
r.Model.AiSummaryBase = result["summary_base"].(string)
|
// r.Model.AiSummaryBase = result["summary_base"].(string)
|
||||||
r.Model.AiSummaryTech = result["summary_tech"].(string)
|
// r.Model.AiSummaryTech = result["summary_tech"].(string)
|
||||||
r.Model.AiScore = int(result["score"].(float64))
|
// r.Model.AiScore = int(result["score"].(float64))
|
||||||
r.Model.AiSupportLevel = result["support_level"].(float64)
|
// r.Model.AiSupportLevel = result["support_level"].(float64)
|
||||||
r.Model.AiResisLevel = result["resis_level"].(float64)
|
// r.Model.AiResisLevel = result["resis_level"].(float64)
|
||||||
r.Model.AiAction = result["action"].(string)
|
// r.Model.AiAction = result["action"].(string)
|
||||||
r.Model.AiRisk = result["risk"].(string)
|
// r.Model.AiRisk = result["risk"].(string)
|
||||||
|
|
||||||
return
|
return result, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,32 @@
|
|||||||
package strategy
|
package strategy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"git.apinb.com/quant/gostock/internal/impl"
|
||||||
|
"git.apinb.com/quant/gostock/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
func Boot() {
|
func Boot() {
|
||||||
InitCacheByAll()
|
InitCacheByAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BootAiStart(key string, ymd int) {
|
||||||
|
var datas []models.StratModel
|
||||||
|
err := impl.DBService.Where("strat_key=? and ymd=? and ai_score=0", key, ymd).Find(&datas).Error
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
for _, row := range datas {
|
||||||
|
go BootAiTask(row.ID, row.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BootAiTask(id uint, code string) {
|
||||||
|
result, err := AiAnalysis(code)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("ERROR BootAiTask", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
impl.DBService.Model(&models.StratModel{}).Where("id=?", id).Updates(result)
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,7 +34,12 @@ func GetFullData(code string) *StockData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetStocks() (stocks []string) {
|
func GetStocks() (stocks []string) {
|
||||||
impl.DBService.Model(&models.StockBasic{}).Group("ts_code").Pluck("ts_code", &stocks)
|
impl.DBService.Model(&models.StockBasic{}).Pluck("ts_code", &stocks)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetStocksByCond(key string, val int) (stocks []string) {
|
||||||
|
impl.DBService.Model(&models.StockBasic{}).Where(key+"=?", val).Pluck("ts_code", &stocks)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user