Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use system client to list&delete knowledgebase for conversation #1002

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions apiserver/pkg/chat/chat_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"github.com/kubeagi/arcadia/apiserver/config"
"github.com/kubeagi/arcadia/apiserver/pkg/auth"
"github.com/kubeagi/arcadia/apiserver/pkg/chat/storage"
"github.com/kubeagi/arcadia/apiserver/pkg/client"
"github.com/kubeagi/arcadia/apiserver/pkg/common"
"github.com/kubeagi/arcadia/pkg/appruntime"
"github.com/kubeagi/arcadia/pkg/appruntime/base"
Expand Down Expand Up @@ -194,24 +193,24 @@ func (cs *ChatServer) DeleteConversation(ctx context.Context, conversationID str
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)
// when delete is successful, it means currentuser is the creator of this conversation
err := cs.Storage().Delete(storage.WithConversationID(conversationID), storage.WithUser(currentUser))
if err != nil {
return fmt.Errorf("failed to get a client: %w", err)
return err
}
kbList := &v1alpha1.KnowledgeBaseList{}
if err = runtimeclient.IgnoreNotFound(c.List(ctx, kbList, runtimeclient.MatchingFields(map[string]string{"metadata.name": conversationID}))); err != nil {
if err = runtimeclient.IgnoreNotFound(cs.systemCli.List(ctx, kbList, runtimeclient.MatchingFields(map[string]string{"metadata.name": conversationID}))); err != nil {
return err
}
// delete when conversation knowledgebase found(only one conversation knowledgebase at most)
if len(kbList.Items) == 1 {
kb := &kbList.Items[0]
if err = c.Delete(ctx, kb); err != nil {
return err
if err = cs.systemCli.Delete(ctx, kb); err != nil {
klog.Errorf("conversation %s deleted but knowledgebase for this conversation failed to delete: %s", conversationID, err.Error())
return fmt.Errorf("failed to delete conversation knowledgebase:%s", err.Error())
}
} else if len(kbList.Items) > 1 {
return fmt.Errorf("multiple conversation knowledgebases found")
}
return cs.Storage().Delete(storage.WithConversationID(conversationID), storage.WithUser(currentUser))
return nil
}

func (cs *ChatServer) ListMessages(ctx context.Context, req ConversationReqBody) (storage.Conversation, error) {
Expand Down
Loading