修复敏感词问题导致deepseek无法分析

This commit is contained in:
spark 2025-02-17 21:53:50 +08:00
parent d504dc6d13
commit 17a234f679
6 changed files with 27 additions and 8 deletions

View File

@ -147,7 +147,7 @@ func (o OpenAi) NewChatStream(stock, stockCode, userQuestion string) <-chan map[
defer wg.Done()
endDate := time.Now().Format("20060102")
startDate := time.Now().Add(-time.Hour * 24 * 365).Format("20060102")
K := NewTushareApi(getConfig()).GetDaily(ConvertStockCodeToTushareCode(stockCode), startDate, endDate)
K := NewTushareApi(getConfig()).GetDaily(ConvertStockCodeToTushareCode(stockCode), startDate, endDate, o.CrawlTimeOut)
msg = append(msg, map[string]interface{}{
"role": "assistant",
"content": stock + "日K数据如下\n" + K,
@ -454,7 +454,7 @@ func SearchGuShiTongStockInfo(stock string, crawlTimeOut int64) *[]string {
}
document.Find("div.finance-hover,div.list-date").Each(func(i int, selection *goquery.Selection) {
text := strutil.RemoveWhiteSpace(selection.Text(), false)
messages = append(messages, text)
messages = append(messages, ReplaceSensitiveWords(text))
logger.SugaredLogger.Infof("SearchGuShiTongStockInfo搜索到消息-%s: %s", "", text)
})
logger.SugaredLogger.Infof("messages:%d", len(messages))
@ -566,7 +566,7 @@ func GetTelegraphList(crawlTimeOut int64) *[]string {
var telegraph []string
document.Find("div.telegraph-content-box").Each(func(i int, selection *goquery.Selection) {
logger.SugaredLogger.Info(selection.Text())
telegraph = append(telegraph, selection.Text())
telegraph = append(telegraph, ReplaceSensitiveWords(selection.Text()))
})
return &telegraph
}
@ -588,7 +588,7 @@ func GetTopNewsList(crawlTimeOut int64) *[]string {
var telegraph []string
document.Find("div.home-article-title a,div.home-article-rec a").Each(func(i int, selection *goquery.Selection) {
logger.SugaredLogger.Info(selection.Text())
telegraph = append(telegraph, selection.Text())
telegraph = append(telegraph, ReplaceSensitiveWords(selection.Text()))
})
return &telegraph
}

View File

@ -628,7 +628,7 @@ func SearchStockInfo(stock, msgType string, crawlTimeOut int64) *[]string {
var messages []string
document.Find(waitVisible).Each(func(i int, selection *goquery.Selection) {
text := strutil.RemoveNonPrintable(selection.Text())
messages = append(messages, text)
messages = append(messages, ReplaceSensitiveWords(text))
logger.SugaredLogger.Infof("搜索到消息-%s: %s", msgType, text)
})
return &messages

View File

@ -5,6 +5,7 @@ import (
"github.com/duke-git/lancet/v2/slice"
"github.com/go-resty/resty/v2"
"go-stock/backend/logger"
"time"
)
// @Author spark
@ -25,11 +26,11 @@ func NewTushareApi(config *Settings) *TushareApi {
}
// GetDaily tushare A股日线行情
func (receiver TushareApi) GetDaily(tsCode, startDate, endDate string) string {
func (receiver TushareApi) GetDaily(tsCode, startDate, endDate string, crawlTimeOut int64) string {
logger.SugaredLogger.Debugf("tushare daily request: ts_code=%s, start_date=%s, end_date=%s", tsCode, startDate, endDate)
fields := "ts_code,trade_date,open,high,low,close,pre_close,change,pct_chg,vol,amount"
resp := &TushareStockBasicResponse{}
_, err := receiver.client.R().
_, err := receiver.client.SetTimeout(time.Duration(crawlTimeOut)*time.Second).R().
SetHeader("content-type", "application/json").
SetBody(&TushareRequest{
ApiName: "daily",

View File

@ -12,7 +12,7 @@ import (
func TestGetDaily(t *testing.T) {
db.Init("../../data/stock.db")
tushareApi := NewTushareApi(getConfig())
res := tushareApi.GetDaily("000802.SZ", "20250101", "20250217")
res := tushareApi.GetDaily("000802.SZ", "20250101", "20250217", 30)
t.Log(res)
}

File diff suppressed because one or more lines are too long

View File

@ -36,3 +36,8 @@ func TestConvertStockCodeToTushareCode(t *testing.T) {
logger.SugaredLogger.Infof("ConvertStockCodeToTushareCode(%s)", ConvertStockCodeToTushareCode("sz000802"))
logger.SugaredLogger.Infof("ConvertTushareCodeToStockCode(%s)", ConvertTushareCodeToStockCode("000802.SZ"))
}
func TestReplaceSensitiveWords(t *testing.T) {
txt := "新 希 望习近平"
txt2 := ReplaceSensitiveWords(txt)
logger.SugaredLogger.Infof("ReplaceSensitiveWords(%s)", txt2)
}