Skip to content

Commit

Permalink
Merge pull request #899 from Abirdcfly/deleteconversation
Browse files Browse the repository at this point in the history
fix: delete conversation with documents
  • Loading branch information
bjwswang committed Mar 20, 2024
2 parents 5f713bd + 7adef69 commit 632f2f2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
19 changes: 19 additions & 0 deletions apiserver/pkg/chat/chat_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,25 @@ func (cs *ChatServer) ListConversations(ctx context.Context, req APPMetadata) ([

func (cs *ChatServer) DeleteConversation(ctx context.Context, conversationID string) error {
currentUser, _ := ctx.Value(auth.UserNameContextKey).(string)
// Note: in pg table, this data is marked as deleted, deleted_at column is not null. the pdf in minio is not deleted. we only delete the conversation knowledgebase.
// delete conversation knowledgebase if it exists
token := auth.ForOIDCToken(ctx)
c, err := client.GetClient(token)
if err != nil {
return fmt.Errorf("failed to get a client: %w", err)
}
kbList := &v1alpha1.KnowledgeBaseList{}
if err = runtimeclient.IgnoreNotFound(c.List(ctx, kbList, runtimeclient.MatchingFields(map[string]string{"metadata.name": conversationID}))); err != nil {
return err
}
if len(kbList.Items) == 1 {
kb := &kbList.Items[0]
if err = c.Delete(ctx, kb); err != nil {
return err
}
} else if len(kbList.Items) > 1 {
return fmt.Errorf("multiple conversation knowledgebases found")
}
return cs.Storage().Delete(storage.WithConversationID(conversationID), storage.WithUser(currentUser))
}

Expand Down
2 changes: 1 addition & 1 deletion apiserver/pkg/chat/storage/storage_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (p *PostgreSQLStorage) Delete(opts ...SearchOption) error {
if searchOpt.Debug != nil {
c.Debug = *searchOpt.Debug
}
tx := p.db.Select("Messages").Delete(c)
tx := p.db.Select("Messages").Select("Documents").Delete(c)
if tx.Error != nil {
return tx.Error
}
Expand Down
Binary file added pkg/documentloaders/testdata/arcadia-readme.pdf
Binary file not shown.
Binary file removed pkg/documentloaders/testdata/llava.pdf
Binary file not shown.
8 changes: 4 additions & 4 deletions tests/example-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,8 @@ done
info "8.4.6 chat with document"
kubectl apply -f config/samples/app_llmchain_abstract.yaml
waitCRDStatusReady "Application" "arcadia" "base-chat-document-assistant"
fileUploadSummarise "base-chat-document-assistant" "arcadia" "./pkg/documentloaders/testdata/llava.pdf"
getRespInAppChat "base-chat-document-assistant" "arcadia" "what is LLaVA?" ${resp_conversation_id} "false"
fileUploadSummarise "base-chat-document-assistant" "arcadia" "./pkg/documentloaders/testdata/arcadia-readme.pdf"
getRespInAppChat "base-chat-document-assistant" "arcadia" "what is arcadia?" ${resp_conversation_id} "false"

# There is uncertainty in the AI replies, most of the time, it will pass the test, a small percentage of the time, the AI will call names in each reply, causing the test to fail, therefore, temporarily disable the following tests
#getRespInAppChat "base-chat-with-bot" "arcadia" "What is your model?" ${resp_conversation_id} "false"
Expand Down Expand Up @@ -779,7 +779,7 @@ if [[ $ai_data != *"1000"* ]]; then
exit 1
fi
# info "8.6.1 bingsearch test"
# getRespInAppChat "base-chat-with-bot-tool" "arcadia" "用30字介绍一下时速云" "" "true"
# getRespInAppChat "base-chat-with-bot-tool" "arcadia" "用30字介绍一下云原生" "" "true"
# if [ -z "$references" ] || [ "$references" = "null" ]; then
# echo $resp
# exit 1
Expand Down Expand Up @@ -807,7 +807,7 @@ waitCRDStatusReady "Application" "arcadia" "base-chat-with-knowledgebase-pgvecto
kubectl patch KnowledgeBaseRetriever -n arcadia base-chat-with-knowledgebase -p '{"spec":{"scoreThreshold":0.9}}' --type='merge'
sleep 3
# info "8.7.1 bingsearch test"
# getRespInAppChat "base-chat-with-knowledgebase-pgvector-tool" "arcadia" "用30字介绍一下时速云" "" "true"
# getRespInAppChat "base-chat-with-knowledgebase-pgvector-tool" "arcadia" "用30字介绍一下云原生" "" "true"
# if [ -z "$references" ] || [ "$references" = "null" ]; then
# echo $resp
# exit 1
Expand Down

0 comments on commit 632f2f2

Please sign in to comment.