切换到kvstore
This commit is contained in:
@@ -157,6 +157,10 @@ func (a *app) countMessageTokens(role, content string) (int, error) {
|
||||
return tokenizer.GetTokens(&message, a.openaiConf.Model)
|
||||
}
|
||||
|
||||
func (a *app) buildZeroUsage() *proto.Usage {
|
||||
return &proto.Usage{}
|
||||
}
|
||||
|
||||
func (a *app) buildUsage(promptTokens int, answer string) (*proto.Usage, error) {
|
||||
completionTokens := 0
|
||||
if answer != "" {
|
||||
|
||||
@@ -83,12 +83,7 @@ func (s *chatService) ChatCompletion(ctx context.Context, in *proto.ChatCompleti
|
||||
questionEmbedding, cachedRecord := s.searchCachedAnswer(ctx, in.Message)
|
||||
if cachedRecord != nil {
|
||||
res := app.buildChatCompletionResponse(cachedRecord.Answer)
|
||||
usage, tokenErr := app.buildUsage(currTokens, cachedRecord.Answer)
|
||||
if tokenErr != nil {
|
||||
s.log.Error(tokenErr)
|
||||
} else {
|
||||
res.Usage = usage
|
||||
}
|
||||
res.Usage = app.buildZeroUsage()
|
||||
res.Source = replySourceSemanticMatch
|
||||
return res, nil
|
||||
}
|
||||
@@ -194,12 +189,7 @@ func (s *chatService) ChatCompletionStream(in *proto.ChatCompletionRequest, stre
|
||||
}
|
||||
final := app.buildChatCompletionStreamResponse(cachedRecord.ID, "", "stop")
|
||||
final.Source = replySourceSemanticMatch
|
||||
usage, tokenErr := app.buildUsage(currTokens, cachedRecord.Answer)
|
||||
if tokenErr != nil {
|
||||
s.log.Error(tokenErr)
|
||||
} else {
|
||||
final.Usage = usage
|
||||
}
|
||||
final.Usage = app.buildZeroUsage()
|
||||
return stream.Send(final)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user