Skip to content

Commit

Permalink
feat: add CRDs for App
Browse files Browse the repository at this point in the history
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
  • Loading branch information
Abirdcfly committed Nov 22, 2023
1 parent a70c276 commit e7c4b35
Show file tree
Hide file tree
Showing 46 changed files with 3,906 additions and 22 deletions.
26 changes: 26 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ layout:
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
multigroup: true
projectName: arcadia
repo: github.com/kubeagi/arcadia
resources:
Expand Down Expand Up @@ -108,4 +109,29 @@ resources:
kind: VectorStore
path: github.com/kubeagi/arcadia/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: kubeagi.k8s.com.cn
group: arcadia
kind: Application
path: github.com/kubeagi/arcadia/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
controller: true
domain: arcadia.kubeagi.k8s.com.cn
group: chain
kind: LLMChain
path: github.com/kubeagi/arcadia/api/v1alpha1/node/chain
version: v1alpha1
- api:
crdVersion: v1
controller: true
domain: arcadia.kubeagi.k8s.com.cn
group: prompttemplate
kind: PromptTemplate
path: github.com/kubeagi/arcadia/api/v1alpha1/node/prompttemplate
version: v1alpha1
version: "3"
22 changes: 22 additions & 0 deletions api/v1alpha1/application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2023 KubeAGI.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

const (
InputNode = "Input"
OutputNode = "Output"
)
80 changes: 80 additions & 0 deletions api/v1alpha1/application_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright 2023 KubeAGI.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type NodeConfig struct {
// +kubebuilder:validation:Required
Name string `json:"name,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Description string `json:"description,omitempty"`
Ref *TypedObjectReference `json:"ref,omitempty"`
}

// ApplicationSpec defines the desired state of Application
type ApplicationSpec struct {
CommonSpec `json:",inline"`
// 开场白,只给客户看的内容,引导客户首次输入
Prologue string `json:"prologue,omitempty"`
// 节点
// +kubebuilder:validation:Required
// +kubebuilder:validation:UniqueItems=true
Nodes []Node `json:"nodes"`
}

type Node struct {
NodeConfig `json:",inline"`
NextNodeName []string `json:"nextNodeName,omitempty"`
}

// ApplicationStatus defines the observed state of Application
type ApplicationStatus struct {
// ObservedGeneration is the last observed generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// ConditionedStatus is the current status
ConditionedStatus `json:",inline"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Application is the Schema for the applications API
type Application struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ApplicationSpec `json:"spec,omitempty"`
Status ApplicationStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// ApplicationList contains a list of Application
type ApplicationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Application `json:"items"`
}

func init() {
SchemeBuilder.Register(&Application{}, &ApplicationList{})
}
32 changes: 32 additions & 0 deletions api/v1alpha1/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,35 @@ func (s *ConditionedStatus) Equal(other *ConditionedStatus) bool {
func (s *ConditionedStatus) IsReady() bool {
return s.GetCondition(TypeReady).Status == corev1.ConditionTrue
}

func (s *ConditionedStatus) WaitingCompleteCondition() []Condition {
return []Condition{{
Type: TypeReady,
Status: corev1.ConditionUnknown,
Reason: "Pending",
Message: "Waiting for user to complete",
LastTransitionTime: metav1.Now(),
LastSuccessfulTime: metav1.Now(),
}}
}

func (s *ConditionedStatus) ErrorCondition(msg string) []Condition {
return []Condition{{
Type: TypeReady,
Status: corev1.ConditionFalse,
Reason: "Error",
Message: msg,
LastTransitionTime: metav1.Now(),
LastSuccessfulTime: metav1.Now(),
}}
}

func (s *ConditionedStatus) ReadyCondition() []Condition {
return []Condition{{
Type: TypeReady,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.Now(),
LastSuccessfulTime: metav1.Now(),
Message: "Success",
}}
}
41 changes: 41 additions & 0 deletions api/v1alpha1/node/chain/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2023 KubeAGI.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the arcadia v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=chain.arcadia.kubeagi.k8s.com.cn
package chain

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

const (
Group = "chain.arcadia.kubeagi.k8s.com.cn"
Version = "v1alpha1"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: Group, Version: Version}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
87 changes: 87 additions & 0 deletions api/v1alpha1/node/chain/llmchain_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright 2023 KubeAGI.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package chain

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kubeagi/arcadia/api/v1alpha1"
"github.com/kubeagi/arcadia/api/v1alpha1/node"
)

// LLMChainSpec defines the desired state of LLMChain
type LLMChainSpec struct {
v1alpha1.CommonSpec `json:",inline"`

CommonChainConfig `json:",inline"`

Input Input `json:"input"`
Output Output `json:"output"`
}

type Input struct {
LLM node.LLMRef `json:"llm"`
PromptTemplate node.PromptTemplateRef `json:"promptTemplate"`
}
type Output struct {
node.CommonOrInPutOrOutputRef `json:",inline"`
}

type CommonChainConfig struct {
// 记忆相关参数
Memory Memory `json:"memory,omitempty"`
}

type Memory struct {
// 能记住的最大 token 数
MaxTokenLimit int `json:"maxTokenLimit,omitempty"`
}

// LLMChainStatus defines the observed state of LLMChain
type LLMChainStatus struct {
// ObservedGeneration is the last observed generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// ConditionedStatus is the current status
v1alpha1.ConditionedStatus `json:",inline"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// LLMChain is the Schema for the LLMChains API
type LLMChain struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec LLMChainSpec `json:"spec,omitempty"`
Status LLMChainStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// LLMChainList contains a list of LLMChain
type LLMChainList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []LLMChain `json:"items"`
}

func init() {
SchemeBuilder.Register(&LLMChain{}, &LLMChainList{})
}
Loading

0 comments on commit e7c4b35

Please sign in to comment.