The three On this machine presets were pinned to localhost and their default port: one started on another port, or on another computer on the LAN, had to be rebuilt as a custom provider or typed URL by URL in the CLI. They now take an Address (scheme, host and port), and each of their URLs keeps its own path there (provider.AtAddress, AddressOf; no scheme means http, only http/https, port 1-65535, a pasted path is dropped, anything else refused with nothing changed). - GUI: the add and edit editors have a Server address section under the key, folded unless the saved address isn't the preset's, opened and focused on a refused one. The Endpoints, Test and Refresh follow what is typed; URLs are sent only when the address changed, so ones set apart (an import, the CLI) are left alone. zh, zh-TW, ja, de. - TUI: adding a local preset asks for its address before the key (Enter keeps the default), and w edits it. - CLI: the usage shows provider add ollama url=... anthropic=.... - LM Studio's and oMLX's notes say "port N by default". timonwong's PR head e63cf18e, merged onto main, which had given oMLX a decision API (#1641) since: presets.go keeps main's oMLX Decide; app.js keeps both the Vertex block and the address one; the docs row and -run list take both. Run: see the next commit.
111 lines
3.6 KiB
Go
111 lines
3.6 KiB
Go
package tui
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// A local server's preset (Ollama, LM Studio, oMLX, MLX-Serve) is asked
|
|
// its address before its key, as the app's editor asks it: Enter alone keeps the
|
|
// default, another port or computer moves each API there, and w changes
|
|
// it later.
|
|
func TestTUIAddsALocalServerAtItsAddress(t *testing.T) {
|
|
home(t)
|
|
at := func(m model, id string) model {
|
|
m.reloadProviders()
|
|
for i, q := range m.provs {
|
|
if q.ID == id {
|
|
m.prow = i
|
|
}
|
|
}
|
|
return m
|
|
}
|
|
|
|
// Enter alone: the preset's own address
|
|
m := press(t, model{w: 120, h: 40}, "2", "a")
|
|
m = typeIn(m, "lmstudio")
|
|
m = press(t, m, "enter")
|
|
if m.mode != modeAsk || m.ask.input.Placeholder != "http://localhost:1234" {
|
|
t.Fatalf("picking LM Studio asked %q (mode %v), not its address", m.ask.input.Placeholder, m.mode)
|
|
}
|
|
m = press(t, m, "enter")
|
|
if m.mode != modeAsk || m.ask.input.Placeholder != "the API key" {
|
|
t.Fatalf("after the address it asked %q (mode %v), not the key", m.ask.input.Placeholder, m.mode)
|
|
}
|
|
m = press(t, m, "enter")
|
|
if p, err := provider.Find("lmstudio"); err != nil || p.Chat != "http://localhost:1234/v1" {
|
|
t.Fatalf("lmstudio: %v %+v", err, p)
|
|
}
|
|
|
|
// a refused address: said, nothing added
|
|
m = press(t, m, "a")
|
|
m = typeIn(m, "omlx")
|
|
m = press(t, m, "enter")
|
|
m = typeIn(m, "ftp://box")
|
|
m = press(t, m, "enter")
|
|
wantFlash(t, m, false, "is not an address like http://localhost:11434")
|
|
if _, err := provider.Find("omlx"); err == nil {
|
|
t.Fatal("added at a refused address")
|
|
}
|
|
|
|
// another port: each API keeps its path
|
|
m = press(t, m, "a")
|
|
m = typeIn(m, "omlx")
|
|
m = press(t, m, "enter")
|
|
m = typeIn(m, "127.0.0.1:1")
|
|
m = press(t, m, "enter")
|
|
m = press(t, m, "enter")
|
|
p, err := provider.Find("omlx")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if p.Chat != "http://127.0.0.1:1/v1" || p.Responses != "http://127.0.0.1:1/v1" || p.Anthropic != "http://127.0.0.1:1" {
|
|
t.Fatalf("omlx at %q %q %q", p.Chat, p.Responses, p.Anthropic)
|
|
}
|
|
|
|
// w: the address now, and changed
|
|
m = at(m, "omlx")
|
|
m = press(t, m, "w")
|
|
if m.mode != modeAsk || m.ask.input.Value() != "http://127.0.0.1:1" {
|
|
t.Fatalf("w opened %q (mode %v), not the address now", m.ask.input.Value(), m.mode)
|
|
}
|
|
m = press(t, m, "ctrl+u")
|
|
m = typeIn(m, "127.0.0.1:2")
|
|
m = press(t, m, "enter")
|
|
wantFlash(t, m, true, "address http://127.0.0.1:2")
|
|
p, _ = provider.Find("omlx")
|
|
if p.Chat != "http://127.0.0.1:2/v1" || p.Responses != "http://127.0.0.1:2/v1" || p.Anthropic != "http://127.0.0.1:2" {
|
|
t.Fatalf("after w: %q %q %q", p.Chat, p.Responses, p.Anthropic)
|
|
}
|
|
// a refused one leaves it
|
|
m = press(t, m, "w", "ctrl+u")
|
|
m = typeIn(m, "no such thing")
|
|
m = press(t, m, "enter")
|
|
wantFlash(t, m, false, "is not an address like")
|
|
if p, _ := provider.Find("omlx"); p.Chat != "http://127.0.0.1:2/v1" {
|
|
t.Fatalf("a refused w left %q", p.Chat)
|
|
}
|
|
|
|
// URLs set apart stay when the address is left as it opened, or typed
|
|
// again in another form
|
|
p, _ = provider.Find("omlx")
|
|
p.Chat, p.Responses, p.Anthropic = "http://10.0.0.2:8000/v1", "http://10.0.0.2:8000/v1", "http://10.0.0.3:9000"
|
|
if err := provider.Save(*p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, typed := range []string{"", "10.0.0.2:8000/v1"} {
|
|
m = at(m, "omlx")
|
|
m = press(t, m, "w")
|
|
if typed != "" {
|
|
m = press(t, m, "ctrl+u")
|
|
m = typeIn(m, typed)
|
|
}
|
|
m = press(t, m, "enter")
|
|
wantFlash(t, m, true, "address unchanged")
|
|
if p, _ := provider.Find("omlx"); p.Chat != "http://10.0.0.2:8000/v1" || p.Anthropic != "http://10.0.0.3:9000" {
|
|
t.Fatalf("w, %q, enter moved them: %q %q", typed, p.Chat, p.Anthropic)
|
|
}
|
|
}
|
|
}
|