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

feat(catalog): sort the chunk #74

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions pkg/acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ func (c *ACLClient) SetOwner(ctx context.Context, objectType string, objectUID u
ownerType = "user"
} else if ownerType == "organizations" {
ownerType = "organization"
} else {
return fmt.Errorf("invalid owner type")
}
data, err := c.getClient(ctx, ReadMode).Read(ctx, &openfga.ReadRequest{
StoreId: c.storeID,
Expand Down
5 changes: 5 additions & 0 deletions pkg/handler/chunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"context"
"fmt"
"sort"

"github.com/gofrs/uuid"
"github.com/instill-ai/artifact-backend/pkg/customerror"
Expand Down Expand Up @@ -65,6 +66,10 @@ func (ph *PublicHandler) ListChunks(ctx context.Context, req *artifactpb.ListChu
return nil, fmt.Errorf("failed to get text chunks by source: %w ", err)

}
// reorder the chunks by order
sort.Slice(chunks, func(i, j int) bool {
return chunks[i].InOrder < chunks[j].InOrder
})

res := make([]*artifactpb.Chunk, 0, len(chunks))
for _, chunk := range chunks {
Expand Down
1 change: 1 addition & 0 deletions pkg/handler/knowledgebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ func (ph *PublicHandler) DeleteCatalog(ctx context.Context, req *artifactpb.Dele
return nil, fmt.Errorf(ErrorDeleteKnowledgeBaseMsg, customerror.ErrNoPermission)
}

// delete acl
err = ph.service.ACLClient.Purge(ctx, "knowledgebase", kb.UID)
if err != nil {
log.Error("failed to purge catalog", zap.Error(err))
Expand Down
Loading