Skip to content

Commit

Permalink
Merge pull request #244 from bjwswang/charts-dev
Browse files Browse the repository at this point in the history
feat: create embedder&llm for worker based on model type
  • Loading branch information
bjwswang authored Nov 24, 2023
2 parents f111fe0 + 35f464c commit ccf38ef
Show file tree
Hide file tree
Showing 22 changed files with 559 additions and 118 deletions.
32 changes: 32 additions & 0 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@ const (
Finalizer = Group + "/finalizer"
)

type ProviderType string

const (
ProviderTypeUnknown ProviderType = "unknown"
ProviderType3rdParty ProviderType = "3rd_party"
ProviderTypeWorker ProviderType = "worker"
)

// Provider defines how to prvoide the service
type Provider struct {
// Enpoint defines connection info
Enpoint *Endpoint `json:"endpoint,omitempty"`

// Worker defines the worker info
// Means this LLM is provided by a arcadia worker
Worker *TypedObjectReference `json:"worker,omitempty"`
}

// GetType returnes the type of this provider
func (p Provider) GetType() ProviderType {
// if endpoint provided,then 3rd_party
if p.Enpoint != nil {
return ProviderType3rdParty
}
// if worker provided,then worker
if p.Worker != nil {
return ProviderTypeWorker
}

return ProviderTypeUnknown
}

// After we use k8s.io/api v1.26.0, we can remove this types to use corev1.TypedObjectReference
// that types is introduced in https://github.com/kubernetes/kubernetes/pull/113186

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/embedder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type EmbedderSpec struct {
// ServiceType indicates the source type of embedding service
ServiceType embeddings.EmbeddingType `json:"serviceType,omitempty"`

// Enpoint defines connection info
Enpoint *Endpoint `json:"endpoint,omitempty"`
// Provider defines the provider info which provide this embedder service
Provider `json:"provider,omitempty"`
}

// EmbeddingsStatus defines the observed state of Embedder
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/llm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type LLMSpec struct {
// Type defines the type of llm
Type llms.LLMType `json:"type"`

// Enpoint defines connection info
Enpoint *Endpoint `json:"endpoint,omitempty"`
// Provider defines the provider info which provide this llm service
Provider `json:"provider,omitempty"`
}

// LLMStatus defines the observed state of LLM
Expand Down
28 changes: 22 additions & 6 deletions api/v1alpha1/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,35 @@ package v1alpha1

import (
"fmt"
"strings"
)

const (
// LabelModelTypes keeps the spec.types field
LabelModelTypes = Group + "/model-types"
// LabelModelEmbedding indicates this is a embedding model
LabelModelEmbedding = Group + "/embedding"
// LabelModelLLM indicates this is a llm model
LabelModelLLM = Group + "/llm"
LabelModelFullPath = Group + "/full-path"
)

func (model Model) ModelTypes() string {
if model.Spec.Types == "" {
return "unknown"
// IsLLMModel checks whether this model is a llm model
func (model Model) IsLLMModel() bool {
for _, t := range strings.Split(model.Spec.Types, ",") {
if strings.ToLower(t) == "llm" {
return true
}
}
return model.Spec.Types
return false
}

// IsLLMModel checks whether this model is a embedding model
func (model Model) IsEmbeddingModel() bool {
for _, t := range strings.Split(model.Spec.Types, ",") {
if strings.ToLower(t) == "embedding" {
return true
}
}
return false
}

// FullPath with bucket and object path
Expand Down
68 changes: 68 additions & 0 deletions api/v1alpha1/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ limitations under the License.
package v1alpha1

import (
"crypto/sha256"
"encoding/hex"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kubeagi/arcadia/pkg/embeddings"
"github.com/kubeagi/arcadia/pkg/llms"
)

type WorkerType string
Expand Down Expand Up @@ -72,3 +78,65 @@ func (worker Worker) ErrorCondition(msg string) Condition {
LastSuccessfulTime: metav1.Now(),
}
}

func (worker Worker) generateUniqueName() string {
// Create a new SHA-256 hasher
hasher := sha256.New()

// Write the input string to the hasher
hasher.Write([]byte(worker.Name))

// Calculate the hash sum
hashSum := hasher.Sum(nil)

// Convert the hash sum to a hexadecimal string
hashString := hex.EncodeToString(hashSum)

return hashString[:10]
}

func (worker Worker) BuildEmbedder() *Embedder {
return &Embedder{
ObjectMeta: metav1.ObjectMeta{
Namespace: worker.Namespace,
Name: worker.generateUniqueName() + "-worker",
},
Spec: EmbedderSpec{
CommonSpec: CommonSpec{
Creator: worker.Spec.Creator,
Description: "Embedder created by Worker(OpenAI compatible)",
},
ServiceType: embeddings.OpenAI,
Provider: Provider{
Worker: &TypedObjectReference{
Kind: "Worker",
Namespace: &worker.Namespace,
Name: worker.Name,
},
},
},
}
}

func (worker Worker) BuildLLM() *LLM {
return &LLM{
ObjectMeta: metav1.ObjectMeta{
Namespace: worker.Namespace,
Name: worker.generateUniqueName() + "-worker",
},
Spec: LLMSpec{
CommonSpec: CommonSpec{
Creator: worker.Spec.Creator,
Description: "LLM created by Worker(OpenAI compatible)",
},
Type: llms.OpenAI,
Provider: Provider{
Worker: &TypedObjectReference{
Kind: "Worker",
Namespace: &worker.Namespace,
Name: worker.Name,
},
},
},
}
}
37 changes: 27 additions & 10 deletions api/v1alpha1/zz_generated.deepcopy.go

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

53 changes: 41 additions & 12 deletions config/crd/bases/arcadia.kubeagi.k8s.com.cn_embedders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,48 @@ spec:
displayName:
description: DisplayName defines datasource display name
type: string
endpoint:
description: Enpoint defines connection info
provider:
description: Provider defines the provider info which provide this
embedder service
properties:
authSecret:
description: AuthSecret if the chart repository requires auth
authentication, set the username and password to secret, with
the field user and password respectively.
endpoint:
description: Enpoint defines connection info
properties:
authSecret:
description: AuthSecret if the chart repository requires auth
authentication, set the username and password to secret,
with the field user and password respectively.
properties:
apiGroup:
description: APIGroup is the group for the resource being
referenced. If APIGroup is not specified, the specified
Kind must be in the core API group. For any other third-party
types, APIGroup is required.
type: string
kind:
description: Kind is the type of resource being referenced
type: string
name:
description: Name is the name of resource being referenced
type: string
namespace:
description: Namespace is the namespace of resource being
referenced
type: string
required:
- kind
- name
type: object
insecure:
description: Insecure if the endpoint needs a secure connection
type: boolean
url:
description: URL chart repository address
type: string
type: object
worker:
description: Worker defines the worker info Means this LLM is
provided by a arcadia worker
properties:
apiGroup:
description: APIGroup is the group for the resource being
Expand All @@ -76,12 +111,6 @@ spec:
- kind
- name
type: object
insecure:
description: Insecure if the endpoint needs a secure connection
type: boolean
url:
description: URL chart repository address
type: string
type: object
serviceType:
description: ServiceType indicates the source type of embedding service
Expand Down
53 changes: 41 additions & 12 deletions config/crd/bases/arcadia.kubeagi.k8s.com.cn_llms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,48 @@ spec:
displayName:
description: DisplayName defines datasource display name
type: string
endpoint:
description: Enpoint defines connection info
provider:
description: Provider defines the provider info which provide this
llm service
properties:
authSecret:
description: AuthSecret if the chart repository requires auth
authentication, set the username and password to secret, with
the field user and password respectively.
endpoint:
description: Enpoint defines connection info
properties:
authSecret:
description: AuthSecret if the chart repository requires auth
authentication, set the username and password to secret,
with the field user and password respectively.
properties:
apiGroup:
description: APIGroup is the group for the resource being
referenced. If APIGroup is not specified, the specified
Kind must be in the core API group. For any other third-party
types, APIGroup is required.
type: string
kind:
description: Kind is the type of resource being referenced
type: string
name:
description: Name is the name of resource being referenced
type: string
namespace:
description: Namespace is the namespace of resource being
referenced
type: string
required:
- kind
- name
type: object
insecure:
description: Insecure if the endpoint needs a secure connection
type: boolean
url:
description: URL chart repository address
type: string
type: object
worker:
description: Worker defines the worker info Means this LLM is
provided by a arcadia worker
properties:
apiGroup:
description: APIGroup is the group for the resource being
Expand All @@ -72,12 +107,6 @@ spec:
- kind
- name
type: object
insecure:
description: Insecure if the endpoint needs a secure connection
type: boolean
url:
description: URL chart repository address
type: string
type: object
type:
description: Type defines the type of llm
Expand Down
Loading

0 comments on commit ccf38ef

Please sign in to comment.