切换到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)
|
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) {
|
func (a *app) buildUsage(promptTokens int, answer string) (*proto.Usage, error) {
|
||||||
completionTokens := 0
|
completionTokens := 0
|
||||||
if answer != "" {
|
if answer != "" {
|
||||||
|
|||||||
@@ -83,12 +83,7 @@ func (s *chatService) ChatCompletion(ctx context.Context, in *proto.ChatCompleti
|
|||||||
questionEmbedding, cachedRecord := s.searchCachedAnswer(ctx, in.Message)
|
questionEmbedding, cachedRecord := s.searchCachedAnswer(ctx, in.Message)
|
||||||
if cachedRecord != nil {
|
if cachedRecord != nil {
|
||||||
res := app.buildChatCompletionResponse(cachedRecord.Answer)
|
res := app.buildChatCompletionResponse(cachedRecord.Answer)
|
||||||
usage, tokenErr := app.buildUsage(currTokens, cachedRecord.Answer)
|
res.Usage = app.buildZeroUsage()
|
||||||
if tokenErr != nil {
|
|
||||||
s.log.Error(tokenErr)
|
|
||||||
} else {
|
|
||||||
res.Usage = usage
|
|
||||||
}
|
|
||||||
res.Source = replySourceSemanticMatch
|
res.Source = replySourceSemanticMatch
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
@@ -194,12 +189,7 @@ func (s *chatService) ChatCompletionStream(in *proto.ChatCompletionRequest, stre
|
|||||||
}
|
}
|
||||||
final := app.buildChatCompletionStreamResponse(cachedRecord.ID, "", "stop")
|
final := app.buildChatCompletionStreamResponse(cachedRecord.ID, "", "stop")
|
||||||
final.Source = replySourceSemanticMatch
|
final.Source = replySourceSemanticMatch
|
||||||
usage, tokenErr := app.buildUsage(currTokens, cachedRecord.Answer)
|
final.Usage = app.buildZeroUsage()
|
||||||
if tokenErr != nil {
|
|
||||||
s.log.Error(tokenErr)
|
|
||||||
} else {
|
|
||||||
final.Usage = usage
|
|
||||||
}
|
|
||||||
return stream.Send(final)
|
return stream.Send(final)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,18 +13,18 @@ services:
|
|||||||
- FAISS_DIM=1024
|
- FAISS_DIM=1024
|
||||||
- APP_PORT=8000
|
- APP_PORT=8000
|
||||||
|
|
||||||
redis:
|
# redis:
|
||||||
image: redis:7-alpine
|
# image: redis:7-alpine
|
||||||
container_name: ai-chat-redis
|
# container_name: ai-chat-redis
|
||||||
command:
|
# command:
|
||||||
- redis-server
|
# - redis-server
|
||||||
- --save
|
# - --save
|
||||||
- ""
|
# - ""
|
||||||
- --appendonly
|
# - --appendonly
|
||||||
- "no"
|
# - "no"
|
||||||
ports:
|
# ports:
|
||||||
- "8888:6379"
|
# - "8888:6379"
|
||||||
restart: unless-stopped
|
# restart: unless-stopped
|
||||||
|
|
||||||
tokenizer:
|
tokenizer:
|
||||||
build:
|
build:
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ chat:
|
|||||||
bot_desc: "你是一个AI助手,我需要你模拟一名资深的软件工程师来回答我的问题"
|
bot_desc: "你是一个AI助手,我需要你模拟一名资深的软件工程师来回答我的问题"
|
||||||
min_response_tokens: 600
|
min_response_tokens: 600
|
||||||
redis:
|
redis:
|
||||||
host: "redis"
|
host: "127.0.0.1"
|
||||||
port: 6379
|
port: 8888
|
||||||
pwd: ""
|
pwd: ""
|
||||||
dependOn:
|
dependOn:
|
||||||
sensitive:
|
sensitive:
|
||||||
|
|||||||
Reference in New Issue
Block a user