Skip to content

Commit

Permalink
Merge pull request #559 from Abirdcfly/apichain
Browse files Browse the repository at this point in the history
feat: add apichain
  • Loading branch information
nkwangleiGIT authored Jan 17, 2024
2 parents c36cbe1 + 0d6e83d commit 27b2085
Show file tree
Hide file tree
Showing 26 changed files with 1,038 additions and 11 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,13 @@ resources:
kind: RAG
path: github.com/kubeagi/arcadia/api/evaluation/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: arcadia.kubeagi.k8s.com.cn
group: chain
kind: APIChain
path: github.com/kubeagi/arcadia/api/app-node/chain/v1alpha1
version: v1alpha1
version: "3"
80 changes: 80 additions & 0 deletions api/app-node/chain/v1alpha1/apichain_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright 2024 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"

node "github.com/kubeagi/arcadia/api/app-node"
"github.com/kubeagi/arcadia/api/base/v1alpha1"
)

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

CommonChainConfig `json:",inline"`
// APIDoc is the api doc for this chain, "api_docs"
APIDoc string `json:"apiDoc"`
}

// APIChainStatus defines the observed state of APIChain
type APIChainStatus 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

// APIChain is a chain that makes API calls and summarizes the responses to answer a question.
type APIChain struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec APIChainSpec `json:"spec,omitempty"`
Status APIChainStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&APIChain{}, &APIChainList{})
}

var _ node.Node = (*APIChain)(nil)

func (c *APIChain) SetRef() {
annotations := node.SetRefAnnotations(c.GetAnnotations(), []node.Ref{node.LLMRef.Len(1), node.PromptRef.Len(1)}, []node.Ref{node.OutputRef.Len(1)})
if c.GetAnnotations() == nil {
c.SetAnnotations(annotations)
}
for k, v := range annotations {
c.Annotations[k] = v
}
}
92 changes: 92 additions & 0 deletions api/app-node/chain/v1alpha1/zz_generated.deepcopy.go

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

166 changes: 166 additions & 0 deletions config/crd/bases/chain.arcadia.kubeagi.k8s.com.cn_apichains.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: apichains.chain.arcadia.kubeagi.k8s.com.cn
spec:
group: chain.arcadia.kubeagi.k8s.com.cn
names:
kind: APIChain
listKind: APIChainList
plural: apichains
singular: apichain
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: APIChain is a chain that makes API calls and summarizes the responses
to answer a question.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: APIChainSpec defines the desired state of APIChain
properties:
apiDoc:
description: APIDoc is the api doc for this chain, "api_docs"
type: string
creator:
description: Creator defines datasource creator (AUTO-FILLED by webhook)
type: string
description:
description: Description defines datasource description
type: string
displayName:
description: DisplayName defines datasource display name
type: string
maxLength:
default: 1024
description: MaxLength is the maximum length of the generated text
in a llm call.
maximum: 4096
minimum: 10
type: integer
maxTokens:
description: MaxTokens is the maximum number of tokens to generate
to use in a llm call.
type: integer
memory:
description: for memory
properties:
conversionWindowSize:
default: 5
description: ConversionWindowSize is the maximum number of conversation
rounds in memory.Can only use MaxTokenLimit or ConversionWindowSize.
maximum: 30
minimum: 0
type: integer
maxTokenLimit:
description: MaxTokenLimit is the maximum number of tokens to
keep in memory. Can only use MaxTokenLimit or ConversionWindowSize.
type: integer
type: object
minLength:
description: MinLength is the minimum length of the generated text
in a llm call.
type: integer
model:
description: Model is the model to use in an llm call.like `gpt-3.5-turbo`
or `chatglm_turbo` Usually this value is just empty
type: string
repetitionPenalty:
description: RepetitionPenalty is the repetition penalty for sampling
in a llm call.
type: number
seed:
description: Seed is a seed for deterministic sampling in a llm call.
type: integer
stopWords:
description: StopWords is a list of words to stop on to use in a llm
call.
items:
type: string
type: array
temperature:
default: 0.7
description: Temperature is the temperature for sampling to use in
a llm call, between 0 and 1.
maximum: 1
minimum: 0
type: number
topK:
description: TopK is the number of tokens to consider for top-k sampling
in a llm call.
type: integer
topP:
description: TopP is the cumulative probability for top-p sampling
in a llm call.
type: number
required:
- apiDoc
type: object
status:
description: APIChainStatus defines the observed state of APIChain
properties:
conditions:
description: Conditions of the resource.
items:
description: A Condition that may apply to a resource.
properties:
lastSuccessfulTime:
description: LastSuccessfulTime is repository Last Successful
Update Time
format: date-time
type: string
lastTransitionTime:
description: LastTransitionTime is the last time this condition
transitioned from one status to another.
format: date-time
type: string
message:
description: A Message containing details about this condition's
last transition from one status to another, if any.
type: string
reason:
description: A Reason for this condition's last transition from
one status to another.
type: string
status:
description: Status of this condition; is it currently True,
False, or Unknown
type: string
type:
description: Type of this condition. At most one of each condition
type may apply to a resource at any point in time.
type: string
required:
- lastTransitionTime
- reason
- status
- type
type: object
type: array
observedGeneration:
description: ObservedGeneration is the last observed generation.
format: int64
type: integer
type: object
type: object
served: true
storage: true
subresources:
status: {}
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ resources:
- bases/prompt.arcadia.kubeagi.k8s.com.cn_prompts.yaml
- bases/retriever.arcadia.kubeagi.k8s.com.cn_knowledgebaseretrievers.yaml
- bases/evaluation.arcadia.kubeagi.k8s.com.cn_rags.yaml
- bases/chain.kubeagi.k8s.com.cn_apichains.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -35,6 +36,7 @@ patchesStrategicMerge:
#- patches/webhook_in_models.yaml
#- patches/webhook_in_applications.yaml
#- patches/webhook_in_rags.yaml
#- patches/webhook_in_apichains.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand All @@ -51,6 +53,7 @@ patchesStrategicMerge:
#- patches/cainjection_in_vectorstores.yaml
#- patches/cainjection_in_applications.yaml
#- patches/cainjection_in_rags.yaml
#- patches/cainjection_in_apichains.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_chain_apichains.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: apichains.chain.kubeagi.k8s.com.cn
Loading

0 comments on commit 27b2085

Please sign in to comment.