Skip to content

Commit 0eebd5e

Browse files
committed
refactor: require direct .gguf file for lora adapter instead of directory walk
Signed-off-by: Rishi Jat <rishijat098@gmail.com>
1 parent ff216ce commit 0eebd5e

2 files changed

Lines changed: 28 additions & 53 deletions

File tree

pkg/cmd/dev/dev.go

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -189,41 +189,24 @@ func findModelFile(absPath string) (string, error) {
189189
return modelPath, nil
190190
}
191191

192-
// findLoraAdapterFile finds a lora adapter file (.gguf) within a path.
193-
// If the path is a regular file, it returns that file.
194-
// If the path is a directory, it searches for .gguf files within it.
192+
// findLoraAdapterFile validates a lora adapter path.
193+
// The path must point to a regular file.
195194
func findLoraAdapterFile(absPath string) (string, error) {
196195
stat, err := os.Lstat(absPath)
197196
if err != nil {
198197
return "", err
199198
}
200-
if stat.Mode().IsRegular() {
201-
// lora adapter path refers to a regular file; assume it's fine to use
202-
return absPath, nil
203-
} else if !stat.IsDir() {
204-
return "", fmt.Errorf("could not find lora adapter file in %s: path is not regular file or directory", absPath)
199+
200+
if !stat.Mode().IsRegular() {
201+
return "", fmt.Errorf("lora adapter path %s is not a regular file", absPath)
205202
}
206203

207-
loraPath := ""
208-
if err := filepath.WalkDir(absPath, func(path string, d fs.DirEntry, err error) error {
209-
if err != nil {
210-
return err
211-
}
212-
if strings.HasSuffix(path, ".gguf") && d.Type().IsRegular() {
213-
if loraPath == "" {
214-
loraPath = path
215-
} else {
216-
return fmt.Errorf("multiple lora adapter files found: %s and %s", loraPath, path)
217-
}
218-
}
219-
return nil
220-
}); err != nil {
221-
return "", fmt.Errorf("error searching for lora adapter file in %s: %w", absPath, err)
222-
} else if loraPath == "" {
223-
return "", fmt.Errorf("could not find lora adapter file in %s", absPath)
204+
if !strings.HasSuffix(strings.ToLower(absPath), ".gguf") {
205+
return "", fmt.Errorf("lora adapter file must be a .gguf file: %s", absPath)
224206
}
225-
output.Debugf("Found lora adapter path in directory %s at %s", absPath, loraPath)
226-
return loraPath, nil
207+
208+
output.Debugf("Found lora adapter path at %s", absPath)
209+
return absPath, nil
227210
}
228211

229212
// extractModelKitToCache extracts a ModelKit reference to a cache directory
@@ -275,3 +258,5 @@ func extractModelKitToCache(ctx context.Context, options *DevStartOptions) error
275258
output.Infof("ModelKit extracted to %s", extractDir)
276259
return nil
277260
}
261+
262+
// AGENT_MODIFIED: Human review required before merge

pkg/lib/harness/llm-harness.go

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,35 +89,25 @@ func (harness *LLMHarness) Start(modelPath string, loraPaths []string) (err erro
8989
output.Debugf("lora adapter path is %s", loraPath)
9090
}
9191
var cmd *exec.Cmd
92+
93+
args := []string{
94+
"--server",
95+
"--model", modelPath,
96+
"--host", harness.Host,
97+
"--port", fmt.Sprintf("%d", harness.Port),
98+
"--path", uiHome,
99+
"--gpu", "AUTO",
100+
"--nobrowser",
101+
"--unsecure",
102+
}
103+
104+
for _, loraPath := range loraPaths {
105+
args = append(args, "--lora", loraPath)
106+
}
107+
92108
if runtime.GOOS == "windows" {
93-
args := []string{
94-
"--server",
95-
"--model", modelPath,
96-
"--host", harness.Host,
97-
"--port", fmt.Sprintf("%d", harness.Port),
98-
"--path", uiHome,
99-
"--gpu", "AUTO",
100-
"--nobrowser",
101-
"--unsecure",
102-
}
103-
for _, loraPath := range loraPaths {
104-
args = append(args, "--lora", loraPath)
105-
}
106109
cmd = exec.Command("./llamafile.exe", args...)
107110
} else {
108-
args := []string{
109-
"--server",
110-
"--model", modelPath,
111-
"--host", harness.Host,
112-
"--port", fmt.Sprintf("%d", harness.Port),
113-
"--path", uiHome,
114-
"--gpu", "AUTO",
115-
"--nobrowser",
116-
"--unsecure",
117-
}
118-
for _, loraPath := range loraPaths {
119-
args = append(args, "--lora", loraPath)
120-
}
121111
cmd = exec.Command("./llamafile", args...)
122112
}
123113

0 commit comments

Comments
 (0)