mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
修复敏感词问题导致deepseek无法分析
This commit is contained in:
parent
d504dc6d13
commit
17a234f679
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user