(ep Endpoint, epName string, getenv func(string) string)
| 309 | } |
| 310 | |
| 311 | func runListModelsCmd(ep Endpoint, epName string, getenv func(string) string) ([]string, error) { |
| 312 | ctx, cancel := context.WithTimeout(context.Background(), modelDiscoveryTimeout) |
| 313 | defer cancel() |
| 314 | |
| 315 | name, args := discoveryShell(ep.ListModelsCmd) |
| 316 | cmd := exec.CommandContext(ctx, name, args...) |
| 317 | cmd.Env = buildDiscoveryEnv(ep, getenv) |
| 318 | |
| 319 | out, err := cmd.Output() |
| 320 | if ctx.Err() == context.DeadlineExceeded { |
| 321 | return nil, fmt.Errorf("providers: list_models_cmd for %s timed out after %s", epName, modelDiscoveryTimeout) |
| 322 | } |
| 323 | if err != nil { |
| 324 | if exit, ok := err.(*exec.ExitError); ok { |
| 325 | return nil, fmt.Errorf("providers: list_models_cmd for %s exited %d: %s", |
| 326 | epName, exit.ExitCode(), strings.TrimSpace(string(exit.Stderr))) |
| 327 | } |
| 328 | return nil, fmt.Errorf("providers: list_models_cmd for %s: %w", epName, err) |
| 329 | } |
| 330 | |
| 331 | models := parseModelsOutput(string(out)) |
| 332 | if len(models) == 0 { |
| 333 | return nil, ErrEmptyModelList |
| 334 | } |
| 335 | return models, nil |
| 336 | } |
| 337 | |
| 338 | // parseModelsOutput splits stdout on \n and drops empty/whitespace lines. |
| 339 | // Each surviving line is trimmed. |
no test coverage detected