🐛 fix: Repair will cache errors or empty messages
This commit is contained in:
parent
763c8883da
commit
755dbf79be
@ -70,7 +70,10 @@ func (r *relayChat) send() (err *types.OpenAIErrorWithStatusCode, done bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = responseJsonClient(r.c, response)
|
err = responseJsonClient(r.c, response)
|
||||||
r.cache.SetResponse(response)
|
|
||||||
|
if err == nil && response.GetContent() != "" {
|
||||||
|
r.cache.SetResponse(response)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -146,6 +146,8 @@ func responseStreamClient(c *gin.Context, stream requester.StreamReaderInterface
|
|||||||
if !errors.Is(err, io.EOF) {
|
if !errors.Is(err, io.EOF) {
|
||||||
fmt.Fprint(w, "data: "+err.Error()+"\n\n")
|
fmt.Fprint(w, "data: "+err.Error()+"\n\n")
|
||||||
errWithOP = common.ErrorWrapper(err, "stream_error", http.StatusInternalServerError)
|
errWithOP = common.ErrorWrapper(err, "stream_error", http.StatusInternalServerError)
|
||||||
|
// 报错不应该缓存
|
||||||
|
cache.NoCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
streamData := "data: [DONE]\n"
|
streamData := "data: [DONE]\n"
|
||||||
|
@ -90,7 +90,16 @@ func (p *ChatCacheProps) SetResponse(response any) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Response = common.Marshal(response)
|
responseStr := common.Marshal(response)
|
||||||
|
if responseStr == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p.Response = responseStr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ChatCacheProps) NoCache() {
|
||||||
|
p.Cache = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ChatCacheProps) StoreCache(channelId, promptTokens, completionTokens int, modelName string) error {
|
func (p *ChatCacheProps) StoreCache(channelId, promptTokens, completionTokens int, modelName string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user