| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- /*
- Copyright 2026 LocoStack.
- 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 llamacpp
- import (
- "fmt"
- "github.com/LocoStack/loco-operator/api/v1alpha1"
- corev1 "k8s.io/api/core/v1"
- "k8s.io/utils/ptr"
- )
- const (
- LLAMA_CPP_MODEL_PATH = "/models"
- LLAMA_CPP_TEMPLATE_PATH = "/templates"
- )
- var LlamaCPPTemplate = v1alpha1.Template{
- Name: "llama.cpp",
- Spec: v1alpha1.TemplateSpec{
- Runtime: v1alpha1.RuntimeSpec{
- Name: "llama.cpp",
- Image: "ghcr.io/ggml-org/llama.cpp:server",
- Args: []string{
- "--model", fmt.Sprintf("%s/$(spec.modelName)", LLAMA_CPP_MODEL_PATH),
- "--host", "0.0.0.0",
- "--port", "$(spec.runtime.port)",
- "--jinja",
- },
- ConditionalArgs: []v1alpha1.ConditionalArgs{
- {
- When: "$(spec.runtimeInferenceParameters.chatTemplateFilePath)",
- Args: []string{
- "--chat-template-file",
- "$(spec.runtimeInferenceParameters.chatTemplateFilePath)",
- },
- },
- {
- When: "$(spec.runtimeInferenceParameters.contextWindow)",
- Args: []string{
- "--ctx-size",
- "$(spec.runtimeInferenceParameters.contextWindow)",
- },
- },
- {
- When: "$(spec.runtimeInferenceParameters.temperature)",
- Args: []string{
- "--temperature",
- "$(spec.runtimeInferenceParameters.temperature)",
- },
- },
- {
- When: "$(spec.runtimeInferenceParameters.topK)",
- Args: []string{
- "--top-k",
- "$(spec.runtimeInferenceParameters.topK)",
- },
- },
- {
- When: "$(spec.runtimeInferenceParameters.topP)",
- Args: []string{
- "--top-p",
- "$(spec.runtimeInferenceParameters.topP)",
- },
- },
- },
- VolumeMounts: []corev1.VolumeMount{
- {Name: "model", MountPath: LLAMA_CPP_MODEL_PATH},
- {Name: "chat-template", MountPath: LLAMA_CPP_TEMPLATE_PATH},
- },
- Port: 8080,
- },
- Volumes: []corev1.Volume{
- {
- Name: "model",
- VolumeSource: corev1.VolumeSource{
- PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
- ClaimName: "$(spec.pvcName)",
- },
- },
- },
- {
- Name: "chat-template",
- VolumeSource: corev1.VolumeSource{
- ConfigMap: &corev1.ConfigMapVolumeSource{
- LocalObjectReference: corev1.LocalObjectReference{
- Name: "$(spec.chatTemplateConfigMapName)",
- },
- Optional: ptr.To(true),
- },
- },
- },
- },
- },
- }
- var LlamaCPPEmbeddingRuntime = v1alpha1.RuntimeSpec{
- Name: "llama.cpp-embedding",
- Image: "ghcr.io/ggml-org/llama.cpp:server",
- Args: []string{
- "--model", fmt.Sprintf("%s/$(spec.modelName)", LLAMA_CPP_MODEL_PATH),
- "--host", "0.0.0.0",
- "--port", "$(spec.runtime.port)",
- "--ctx-size", "$(spec.runtimeInferenceParameters.contextWindow)",
- "--embedding",
- },
- VolumeMounts: []corev1.VolumeMount{
- {Name: "model", MountPath: LLAMA_CPP_MODEL_PATH},
- },
- Port: 8080,
- }
- var LlamaCPPRerankerRuntime = v1alpha1.RuntimeSpec{
- Name: "llama.cpp-reranker",
- Image: "ghcr.io/ggml-org/llama.cpp:server",
- Args: []string{
- "--model", fmt.Sprintf("%s/$(spec.modelName)", LLAMA_CPP_MODEL_PATH),
- "--host", "0.0.0.0",
- "--port", "$(spec.runtime.port)",
- "--ctx-size", "$(spec.runtimeInferenceParameters.contextWindow)",
- "--reranking",
- },
- VolumeMounts: []corev1.VolumeMount{
- {Name: "model", MountPath: LLAMA_CPP_MODEL_PATH},
- },
- Port: 8080,
- }
|