|
@@ -4,28 +4,33 @@ import (
|
|
|
"aiChat/api/aiSearch/v1"
|
|
|
"aiChat/internal/model"
|
|
|
"aiChat/internal/model/bidSearch"
|
|
|
+ "aiChat/utility"
|
|
|
"context"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
- "github.com/gogf/gf/v2/util/gconv"
|
|
|
-
|
|
|
. "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
|
"github.com/gogf/gf/v2/encoding/gjson"
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
)
|
|
|
|
|
|
func (c *ControllerV1) Chat(ctx context.Context, req *v1.ChatReq) (res *v1.ChatRes, err error) {
|
|
|
- res = &v1.ChatRes{ErrorCode: 0}
|
|
|
+ res = &v1.ChatRes{Status: 0}
|
|
|
sid := gconv.Int64(SE.Decode4HexByCheck(req.SId))
|
|
|
if sid == 0 {
|
|
|
g.Log().Error(ctx, "无效的sid参数", req.SId)
|
|
|
return
|
|
|
}
|
|
|
+ sess, sessErr := model.GetSession(g.RequestFromCtx(ctx))
|
|
|
+ if sessErr != nil {
|
|
|
+ g.Log().Error(ctx, "获取session出错", sessErr)
|
|
|
+ return
|
|
|
+ }
|
|
|
startTime := gtime.Now().Format("Y-m-d h:m:s.u")
|
|
|
success := 0
|
|
|
prompt := fmt.Sprintf(g.Cfg("ai_search.yaml").MustGet(ctx, "doubaoPrompt").String(), gtime.Now().Format("Ymd"), req.Question)
|
|
@@ -40,6 +45,7 @@ func (c *ControllerV1) Chat(ctx context.Context, req *v1.ChatReq) (res *v1.ChatR
|
|
|
large_model_success = 0
|
|
|
}
|
|
|
callLogs = append(callLogs, g.Map{
|
|
|
+ "position_id": sess.PositionId,
|
|
|
"large_model": large_model,
|
|
|
"large_model_reply": largeModelReply,
|
|
|
"large_model_starttime": startTime,
|
|
@@ -59,6 +65,7 @@ func (c *ControllerV1) Chat(ctx context.Context, req *v1.ChatReq) (res *v1.ChatR
|
|
|
large_model_success = 0
|
|
|
}
|
|
|
callLogs = append(callLogs, g.Map{
|
|
|
+ "position_id": sess.PositionId,
|
|
|
"large_model": large_model,
|
|
|
"large_model_reply": largeModelReply,
|
|
|
"large_model_starttime": startTime,
|
|
@@ -73,16 +80,30 @@ func (c *ControllerV1) Chat(ctx context.Context, req *v1.ChatReq) (res *v1.ChatR
|
|
|
} else {
|
|
|
large_model = ""
|
|
|
}
|
|
|
- sess, sessErr := model.GetSession(g.RequestFromCtx(ctx))
|
|
|
- if sessErr != nil {
|
|
|
- return
|
|
|
- }
|
|
|
bs, bsErr := bidSearch.NewBidSearch(ctx, sess.PersonId, content)
|
|
|
if bsErr != nil {
|
|
|
return
|
|
|
}
|
|
|
query, list := bs.Search()
|
|
|
answer := ""
|
|
|
+ var bestBids []*v1.ResBidding
|
|
|
+ if len(list) > 0 {
|
|
|
+ if bestBidListMaxLen := g.Cfg("ai_search.yaml").MustGet(ctx, "bestBidListMaxLen").Int(); len(list) > bestBidListMaxLen {
|
|
|
+ bestBids = make([]*v1.ResBidding, bestBidListMaxLen)
|
|
|
+ copy(bestBids, list[:bestBidListMaxLen])
|
|
|
+ } else {
|
|
|
+ bestBids = make([]*v1.ResBidding, len(list))
|
|
|
+ copy(bestBids, list[:])
|
|
|
+ }
|
|
|
+ answer = gconv.String(bestBids)
|
|
|
+ collection := utility.GetMyBidCollect(ctx, sess.PositionId)
|
|
|
+ for _, v := range bestBids {
|
|
|
+ if collection[v.InfoId] {
|
|
|
+ v.Collect = 1
|
|
|
+ }
|
|
|
+ v.InfoId = EncodeArticleId2ByCheck(v.InfoId)
|
|
|
+ }
|
|
|
+ }
|
|
|
if err := g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
|
|
chatId, chatErr := tx.InsertAndGetId("ai_search_chat", g.Map{
|
|
|
"position_id": sess.PositionId,
|
|
@@ -105,22 +126,47 @@ func (c *ControllerV1) Chat(ctx context.Context, req *v1.ChatReq) (res *v1.ChatR
|
|
|
return chatErr
|
|
|
}
|
|
|
//
|
|
|
- // bids := g.List{}
|
|
|
- // for _, v := range list {
|
|
|
- // bids = append(bids, g.Map{
|
|
|
- // "position_id": sess.PositionId,
|
|
|
- // "chat_id": chatId,
|
|
|
- // })
|
|
|
- // }
|
|
|
+ bids := g.List{}
|
|
|
+ for _, v := range list {
|
|
|
+ bids = append(bids, g.Map{
|
|
|
+ "position_id": sess.PositionId,
|
|
|
+ "chat_id": chatId,
|
|
|
+ "infoid": v.InfoId,
|
|
|
+ "title": v.Title,
|
|
|
+ "area": v.Area,
|
|
|
+ "city": v.City,
|
|
|
+ "district": v.District,
|
|
|
+ "subtype": v.Subtype,
|
|
|
+ "industry": v.Industry,
|
|
|
+ "annex": v.Annex,
|
|
|
+ "buyerclass": v.Buyerclass,
|
|
|
+ "budget": v.Budget,
|
|
|
+ "bidamount": v.Bidamount,
|
|
|
+ "publishtime": v.Publishtime,
|
|
|
+ "create_time": gtime.Datetime(),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if len(bids) > 0 {
|
|
|
+ if _, bidsErr := tx.Insert("ai_search_bidding", bids, 200); bidsErr != nil {
|
|
|
+ g.Log().Error(ctx, "ai_search_bidding保存出错", bidsErr)
|
|
|
+ return bidsErr
|
|
|
+ }
|
|
|
+ }
|
|
|
//
|
|
|
for _, v := range callLogs {
|
|
|
v["chat_id"] = chatId
|
|
|
v["create_time"] = gtime.Datetime()
|
|
|
}
|
|
|
+ if len(callLogs) > 0 {
|
|
|
+ if _, callLogsErr := tx.Insert("ai_search_log", callLogs); callLogsErr != nil {
|
|
|
+ g.Log().Error(ctx, "ai_search_log保存出错", callLogsErr)
|
|
|
+ return callLogsErr
|
|
|
+ }
|
|
|
+ }
|
|
|
return nil
|
|
|
}); err == nil {
|
|
|
- res.ErrorCode = 1
|
|
|
- res.List = list
|
|
|
+ res.Status = 1
|
|
|
+ res.List = bestBids
|
|
|
} else {
|
|
|
g.Log().Error(ctx, sess.PositionId, "保存数据库出错", err)
|
|
|
}
|