Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cmd/modelctl/commands/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Chat(ctx *common.Context) *cobra.Command {
}

func (cmd *chatCommand) run(_ *cobra.Command, _ []string) error {
chatBaseUrl, err := common.OpenAiEndpoint(cmd.Context)
chatBaseUrl, err := common.OpenAiBaseUrl(cmd.Context)
if err != nil {
return fmt.Errorf("getting OpenAI base URL: %v", err)
}
Expand Down
12 changes: 10 additions & 2 deletions cmd/modelctl/commands/export-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ func (cmd *exportStatusCommand) run(_ *cobra.Command, args []string) error {
return fmt.Errorf("getting status: %v", err)
}

// Convert Entrypoints to Endpoints (extract URLs) for backward compatibility

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a link to this PR for future reference

Suggested change
// Convert Entrypoints to Endpoints (extract URLs) for backward compatibility
// Convert Entrypoints to Endpoints (extract URLs) for backward compatibility,
// see https://github.com/canonical/inference-snaps-cli/pull/412

endpoints := make(map[string]string)
for name, entrypoint := range statusStr.Entrypoints {
if entrypoint.Url != "" {
endpoints[name] = entrypoint.Url
}
}

// Decouple internal status definition from shared one
sharedStatusStr := &exportedStatus{
Endpoints: statusStr.Endpoints,
Endpoints: endpoints,
Model: statusStr.Model,
}

Expand Down Expand Up @@ -87,7 +95,7 @@ func (cmd *exportStatusCommand) writeShareFiles(status *exportedStatus, shareDir

// Deprecated: Write openai.json for backwards compatibility while Open WebUI snap is not updated
openaiFilePath := filepath.Join(shareDir, "openai.json")
if endpoint, ok := status.Endpoints["openai"]; ok {
if endpoint, ok := status.Endpoints["openai"]; ok && endpoint != "" {
myOpenaiConfig := &exportedOpenai{
BaseUrl: endpoint,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/modelctl/commands/serve-webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (cmd *serveWebUiCommand) serveWebUi(_ *cobra.Command, args []string) error
return fmt.Errorf("waiting for component: %s", err)
}

baseURL, err := common.OpenAiEndpoint(cmd.Context)
baseURL, err := common.OpenAiBaseUrl(cmd.Context)
if err != nil {
return fmt.Errorf("getting OpenAI base URL: %v", err)
}
Expand Down
111 changes: 111 additions & 0 deletions cmd/modelctl/commands/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package commands

import (
"fmt"
"log"
"path/filepath"

"github.com/canonical/inference-snaps-cli/v2/cmd/modelctl/common"
"github.com/canonical/inference-snaps-cli/v2/pkg/snap"
"github.com/canonical/inference-snaps-cli/v2/pkg/storage"
)
Comment thread
farshidtz marked this conversation as resolved.

// createTestContextForStatus creates a test context for Example tests
func createTestContextForStatus() *common.Context {
testDataDir := "../../../test_data"
enginesDir := filepath.Join(testDataDir, "engines")
runtimesDir := filepath.Join(testDataDir, "runtimes")
modelsDir := filepath.Join(testDataDir, "models")

cache := storage.NewMockCache()
if err := cache.SetActiveEngine("cpu"); err != nil {
log.Fatalf("failed to set active engine: %v", err)
}
if err := cache.SetActiveModel("4b-it-int4-fq-ov"); err != nil {
log.Fatalf("failed to set active model: %v", err)
}

configs := map[string]string{
"http.port": "8080",
"http.host": "0.0.0.0",
"ws.unix-socket": "/run/whisper.sock",
// namespaced configurations
"logger.http.port": "8081",
"logger.http.host": "localhost",
}

config := storage.NewMockConfig()
for key, value := range configs {
if err := config.Set(key, value, storage.UserConfig); err != nil {
log.Fatalf("failed to set %s: %v", key, err)
}
}

return &common.Context{
EnginesDir: enginesDir,
RuntimesDir: runtimesDir,
ModelsDir: modelsDir,
Cache: cache,
Config: config,
Snap: snap.MockWithServiceStatuses(map[string]string{"llama-server": "active"}),
}
}

func Example_statusCommand_printStatusYaml() {
ctx := createTestContextForStatus()
cmd := statusCommand{Context: ctx}

statusText, err := cmd.statusYaml()
if err != nil {
log.Fatalf("failed to get status in yaml format: %v", err)
}
fmt.Print(statusText)

// Output:
// engine: cpu
// services:
// llama-server: active
// entrypoints:
// logger:
// url: http://localhost:8081/
// openai:
// url: http://0.0.0.0:8080/v1
// whisperlive:
// unix-socket: /run/whisper.sock (ws://unix/realtime)
// model:
// name: gemma-4-4b-it-int4-fq-ov
}
Comment thread
farshidtz marked this conversation as resolved.

func Example_statusCommand_printStatusJson() {
ctx := createTestContextForStatus()
cmd := statusCommand{Context: ctx}

statusText, err := cmd.statusJson()
if err != nil {
log.Fatalf("failed to get status in yaml format: %v", err)
}
fmt.Print(statusText)

// Output:
// {
// "engine": "cpu",
// "services": {
// "llama-server": "active"
// },
// "entrypoints": {
// "logger": {
// "url": "http://localhost:8081/"
// },
// "openai": {
// "url": "http://0.0.0.0:8080/v1"
// },
// "whisperlive": {
// "unix-socket": "/run/whisper.sock",
// "unix-socket-url": "ws://unix/realtime"
// }
// },
// "model": {
// "name": "gemma-4-4b-it-int4-fq-ov"
// }
// }
}
2 changes: 1 addition & 1 deletion cmd/modelctl/commands/webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (cmd *webUiCommand) run(_ *cobra.Command, _ []string) error {
}

// Wait until the openai server endpoint is ready to accept chat prompts. This should be handled in the webui in the future.
chatBaseUrl, err := common.OpenAiEndpoint(cmd.Context)
chatBaseUrl, err := common.OpenAiBaseUrl(cmd.Context)
if err != nil {
return fmt.Errorf("getting OpenAI base URL: %v", err)
}
Expand Down
Loading
Loading