Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"

"github.com/docker/model-runner/pkg/distribution/transport/resumable"
Expand All @@ -22,6 +21,7 @@ import (
"github.com/docker/model-runner/pkg/inference/scheduling"
"github.com/docker/model-runner/pkg/metrics"
"github.com/docker/model-runner/pkg/routing"
"github.com/docker/model-runner/pkg/utils"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -255,7 +255,7 @@ func createLlamaCppConfigFromEnv() config.BackendConfig {
}

// Split the string by spaces, respecting quoted arguments
args := splitArgs(argsStr)
args := utils.SplitArgs(argsStr)

// Check for disallowed arguments
disallowedArgs := []string{"--model", "--host", "--embeddings", "--mmproj"}
Expand All @@ -272,30 +272,3 @@ func createLlamaCppConfigFromEnv() config.BackendConfig {
Args: args,
}
}

// splitArgs splits a string into arguments, respecting quoted arguments
func splitArgs(s string) []string {
var args []string
var currentArg strings.Builder
inQuotes := false

for _, r := range s {
switch {
case r == '"' || r == '\'':
inQuotes = !inQuotes
case r == ' ' && !inQuotes:
if currentArg.Len() > 0 {
args = append(args, currentArg.String())
currentArg.Reset()
}
default:
currentArg.WriteRune(r)
}
}

if currentArg.Len() > 0 {
args = append(args, currentArg.String())
}

return args
}
Loading