添加doubao日志输出
This commit is contained in:
parent
4ade987de6
commit
4d974e4eab
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateAIStreamMsg(userID, modelID, sessionID int, msg interface{}, t string) {
|
func CreateAIStreamMsg(userID, modelID, sessionID int, msg interface{}, t string) (uint, error) {
|
||||||
msgStr, err := json.Marshal(msg)
|
msgStr, err := json.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ai stream msg Error parsing JSON:", err)
|
log.Println("ai stream msg Error parsing JSON:", err)
|
||||||
|
|
@ -15,4 +15,5 @@ func CreateAIStreamMsg(userID, modelID, sessionID int, msg interface{}, t string
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
log.Println("ai stream msg insert error")
|
log.Println("ai stream msg insert error")
|
||||||
}
|
}
|
||||||
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ func doubao(modelParam proto.ModelParam, question, channel string, SessionID, Us
|
||||||
req := model.CreateChatCompletionRequest{
|
req := model.CreateChatCompletionRequest{
|
||||||
Model: modelParam.Model,
|
Model: modelParam.Model,
|
||||||
Messages: messages,
|
Messages: messages,
|
||||||
|
StreamOptions: &model.StreamOptions{
|
||||||
|
IncludeUsage: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
stream, err := doubaoClient.CreateChatCompletionStream(ctx, req)
|
stream, err := doubaoClient.CreateChatCompletionStream(ctx, req)
|
||||||
|
|
@ -122,8 +125,15 @@ func DouBaoV2(modelParam proto.ModelParam, imCtx *proto.IMParamContext) {
|
||||||
fmt.Printf("doubao Stream chat error: %v\n", err)
|
fmt.Printf("doubao Stream chat error: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go CreateAIStreamMsg(imCtx.UserID, imCtx.ModelID, imCtx.SessionID, recv, modelParam.Model)
|
aiStream_id, err3 := CreateAIStreamMsg(imCtx.UserID, imCtx.ModelID, imCtx.SessionID, recv, modelParam.Model)
|
||||||
|
if err3 != nil {
|
||||||
|
log.Println("create ai stream message error:", err3)
|
||||||
|
}
|
||||||
doubaoToGeneralMassageAndSendMsgQueue(&recv, imCtx.Channel, imCtx.SessionID, imCtx.UserID)
|
doubaoToGeneralMassageAndSendMsgQueue(&recv, imCtx.Channel, imCtx.SessionID, imCtx.UserID)
|
||||||
|
if recv.Choices == nil {
|
||||||
|
log.Println("doubao stream recv choices is nil:", recv, "\t aiStream_id:", aiStream_id)
|
||||||
|
continue
|
||||||
|
}
|
||||||
choices := recv.Choices[0]
|
choices := recv.Choices[0]
|
||||||
if choices.FinishReason == proto.FinishReasonStop {
|
if choices.FinishReason == proto.FinishReasonStop {
|
||||||
answer += choices.Delta.Content
|
answer += choices.Delta.Content
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue