Skip to content

Commit

Permalink
feat: add custom model support
Browse files Browse the repository at this point in the history
  • Loading branch information
Apoorva64 committed Oct 20, 2024
1 parent 2f8c06c commit 56e6385
Show file tree
Hide file tree
Showing 20 changed files with 701 additions and 40 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ resources:
kind: Model
path: github.com/StartUpNationLabs/simple-ollama-operator/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: ollama.startupnation
group: ollama
kind: CustomModel
path: github.com/StartUpNationLabs/simple-ollama-operator/api/v1
version: v1
version: "3"
64 changes: 64 additions & 0 deletions api/v1/custommodel_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2024.
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 v1

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

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// CustomModelSpec defines the desired state of CustomModel
type CustomModelSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

ModelName string `json:"modelName"`
ModelFile string `json:"modelFile"`
}

// CustomModelStatus defines the observed state of CustomModel
type CustomModelStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

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

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

Spec CustomModelSpec `json:"spec,omitempty"`
Status CustomModelStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&CustomModel{}, &CustomModelList{})
}
89 changes: 89 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Model")
os.Exit(1)
}
if err = (&controller.CustomModelReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "CustomModel")
os.Exit(1)
}
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
57 changes: 57 additions & 0 deletions config/crd/bases/ollama.ollama.startupnation_custommodels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
name: custommodels.ollama.ollama.startupnation
spec:
group: ollama.ollama.startupnation
names:
kind: CustomModel
listKind: CustomModelList
plural: custommodels
singular: custommodel
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: CustomModel is the Schema for the custommodels API
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: CustomModelSpec defines the desired state of CustomModel
properties:
modelFile:
type: string
modelName:
type: string
required:
- modelFile
- modelName
type: object
status:
description: CustomModelStatus defines the observed state of CustomModel
type: object
type: object
served: true
storage: true
subresources:
status: {}
2 changes: 2 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# It should be run by config/default
resources:
- bases/ollama.ollama.startupnation_models.yaml
- bases/ollama.ollama.startupnation_custommodels.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patches:
Expand All @@ -13,6 +14,7 @@ patches:
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- path: patches/cainjection_in_models.yaml
#- path: patches/cainjection_in_custommodels.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# [WEBHOOK] To enable webhook, uncomment the following section
Expand Down
27 changes: 27 additions & 0 deletions config/rbac/custommodel_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to edit custommodels.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: simple-ollama-operator
app.kubernetes.io/managed-by: kustomize
name: custommodel-editor-role
rules:
- apiGroups:
- ollama.ollama.startupnation
resources:
- custommodels
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ollama.ollama.startupnation
resources:
- custommodels/status
verbs:
- get
23 changes: 23 additions & 0 deletions config/rbac/custommodel_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# permissions for end users to view custommodels.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: simple-ollama-operator
app.kubernetes.io/managed-by: kustomize
name: custommodel-viewer-role
rules:
- apiGroups:
- ollama.ollama.startupnation
resources:
- custommodels
verbs:
- get
- list
- watch
- apiGroups:
- ollama.ollama.startupnation
resources:
- custommodels/status
verbs:
- get
2 changes: 2 additions & 0 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ resources:
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
# if you do not want those helpers be installed with your Project.
- custommodel_editor_role.yaml
- custommodel_viewer_role.yaml
- model_editor_role.yaml
- model_viewer_role.yaml

3 changes: 3 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ rules:
- apiGroups:
- ollama.ollama.startupnation
resources:
- custommodels
- models
verbs:
- create
Expand All @@ -19,12 +20,14 @@ rules:
- apiGroups:
- ollama.ollama.startupnation
resources:
- custommodels/finalizers
- models/finalizers
verbs:
- update
- apiGroups:
- ollama.ollama.startupnation
resources:
- custommodels/status
- models/status
verbs:
- get
Expand Down
1 change: 1 addition & 0 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Append samples of your project ##
resources:
- ollama_v1_model.yaml
- ollama_v1_custommodel.yaml
# +kubebuilder:scaffold:manifestskustomizesamples
18 changes: 18 additions & 0 deletions config/samples/ollama_v1_custommodel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: ollama.ollama.startupnation/v1
kind: CustomModel
metadata:
labels:
app.kubernetes.io/name: simple-ollama-operator
app.kubernetes.io/managed-by: kustomize
name: mario-custommodel-sample
spec:
modelName: mario-custommodel-sample
modelFile: >-
FROM llama3.2
# sets the temperature to 1 [higher is more creative, lower is more coherent]
PARAMETER temperature 1
# sets the context window size to 4096, this controls how many tokens the LLM can use as context to generate the next token
PARAMETER num_ctx 4096
# sets a custom system message to specify the behavior of the chat assistant
SYSTEM You are Mario from super mario bros, acting as an assistant. You are in a conversation with Luigi, who is asking you for help. You are in a hurry to save Princess Peach from Bowser, so you are trying to be as helpful as possible while also being brief. You are in a good mood and are excited to help Luigi.
Loading

0 comments on commit 56e6385

Please sign in to comment.