Skip to content

Commit

Permalink
Merge pull request kubeagi#920 from Abirdcfly/prompt-start-1
Browse files Browse the repository at this point in the history
fix: zhipu embedding error with empty string
  • Loading branch information
bjwswang authored Mar 22, 2024
2 parents 9a02939 + 026a3d2 commit c1065ab
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions apiserver/pkg/chat/chat_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (cs *ChatServer) ListPromptStarters(ctx context.Context, req APPMetadata, l
content := bytes.Buffer{}
// if there is a knowledgebase, use it to generate prompt starter
if kb != nil {
outArg, finish, err := retriever.GenerateKnowledgebaseRetriever(ctx, c, kb.Name, kb.Namespace, apiretriever.CommonRetrieverConfig{NumDocuments: limit}, map[string]any{"question": ""})
outArg, finish, err := retriever.GenerateKnowledgebaseRetriever(ctx, c, kb.Name, kb.Namespace, apiretriever.CommonRetrieverConfig{NumDocuments: limit * 2}, map[string]any{"question": "开始"})
if err != nil {
return nil, err
}
Expand All @@ -314,14 +314,13 @@ func (cs *ChatServer) ListPromptStarters(ctx context.Context, req APPMetadata, l
question := strings.TrimSuffix(d.PageContent, "\na: "+answer)
promptStarters = append(promptStarters, strings.TrimPrefix(question, "q: "))
hasAnswer = true
if len(promptStarters) == limit {
break
}
}
}
if !hasAnswer {
content.WriteString(d.PageContent + "\n")
// if content is too long, may cause llm error
if content.Len() > 500 {
break
}
}
}
}
Expand All @@ -339,7 +338,12 @@ func (cs *ChatServer) ListPromptStarters(ctx context.Context, req APPMetadata, l
if content.Len() > 0 {
klog.V(3).Infoln("app has knowlegebase with chunk information, let llm generate some question")
p = prompts.NewPromptTemplate(PromptForGeneratePromptStartersByChunk, []string{"limit", "information"})
predictArg["information"] = content.String()
contentStr := content.String()
// if content is too long, may cause llm error
if len(contentStr) > 500 {
contentStr = contentStr[0:500]
}
predictArg["information"] = contentStr
} else {
klog.V(3).Infoln("app has no knowlegebase, let llm generate some question")
p = prompts.NewPromptTemplate(PromptForGeneratePromptStartersByAppInfo, []string{"limit", "displayName", "description"})
Expand Down

0 comments on commit c1065ab

Please sign in to comment.