Skip to content

Commit

Permalink
feat: Add api to support copying existing rag
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy committed Feb 23, 2024
1 parent 1536dbb commit 4223161
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 6 deletions.
222 changes: 219 additions & 3 deletions apiserver/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions apiserver/graph/generated/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions apiserver/graph/impl/rag.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions apiserver/graph/schema/rag.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ input UpdateRAGInput {
suspend: Boolean
}

input DuplicateRAGInput {
name: String!
namespace: String!
displayName: String
}

input DeleteRAGInput {
name: String!
namespace: String!
Expand Down Expand Up @@ -185,6 +191,7 @@ type RAGMutation {
createRAG(input: CreateRAGInput!): RAG!
updateRAG(input: UpdateRAGInput!): RAG!
deleteRAG(input: DeleteRAGInput!): Void
duplicateRAG(input: DuplicateRAGInput!): RAG!
}

type RAGQuery {
Expand Down
26 changes: 26 additions & 0 deletions apiserver/pkg/rag/rag.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,29 @@ func DeleteRAG(ctx context.Context, kubeClient client.Client, input *generated.D
}
return kubeClient.DeleteAllOf(ctx, &evav1alpha1.RAG{}, opts...)
}

func DuplicateRAG(ctx context.Context, kubeClient client.Client, input *generated.DuplicateRAGInput) (*generated.Rag, error) {
currentUser, _ := ctx.Value(auth.UserNameContextKey).(string)
rag := &evav1alpha1.RAG{}
err := kubeClient.Get(ctx, types.NamespacedName{Namespace: input.Namespace, Name: input.Name}, rag)
if err != nil {
return nil, err
}
rag.Name = generateKubernetesResourceName("rag", 10)
if input.DisplayName != nil {
rag.Spec.DisplayName = *input.DisplayName
}
labels := rag.Labels
if labels == nil {
labels = make(map[string]string)
}
labels["duplication"] = fmt.Sprintf("%s_%s", input.Namespace, input.Name)
rag.SetLabels(labels)
rag.ResourceVersion = ""
rag.Spec.Creator = currentUser
err = kubeClient.Create(ctx, rag)
if err != nil {
return nil, err
}
return rag2model(rag)
}
Loading

0 comments on commit 4223161

Please sign in to comment.