agent: omp's image role lists magpie's image models (treeman_26897)
treeman_26897 on Discord: omp's ROLES -> IMAGE offered none of magpie's image models. omp's image role takes a model of kind image alone (pi-coding-agent model-roles.ts), and every model magpie wrote to ~/.omp/agent/models.yml was a chat model. magpie's image models (gateway.ImageModels: Settings > Images, as Pi's extension and the magpie-image MCP have them) now go into magpie's provider as kind: image on api openai-images. omp's generate_image posts those to baseUrl + /images/generations (or /images/edits), the gateway's /v1/images (pi-ai images/openai-images.ts). Only for omp 18.7.0 and later, the first whose models.yml takes kind and a runner api; 18.6.3's schema turns the whole file away over openai-images, and an omp whose version isn't known gets none, as ompTakesMax. An image id a chat model already has is left out. With an image model listed, the provider carries the gateway's key (apiKey: magpie) instead of auth: none: generate_image skips a keyless provider's model as "credentials unavailable" (isAuthenticated turns kNoAuth away), while chat goes without one. Without an image model the entry is as before. Run at this head (rebased onf3551387c), on mote: - go test ./internal/agent ./internal/library ./internal/sessions: ok - go test ./internal/gui -run 'Omp|omp|AgentConnect': ok - go test ./internal/cli: TestEveryRouteHasACommandOrIsNamed red on /api/usage/checkin-account, the same onf3551387c, filed as #4826 (frome87140242); nothing else red - go vet ./internal/agent for darwin, linux, windows; gofmt -l: clean Broken by hand: without the line adding the image models, TestOmpListsImageModelsForItsImageRole is red; with it, green. Real omp 18.15.0 in a sandbox HOME on mote (Bun 1.4.4 in the sandbox), against a stand-in gateway: `omp models magpie --kind image` lists art/gpt-image-2 (not among chat). `omp -p` with the image role on it: under auth: none the tool said "credentials unavailable"; with apiKey magpie it posted {"model":"art/gpt-image-2","prompt":"a red square.", "n":1} to /v1/images/generations and saved the PNG. Not tried: a real magpie gateway drawing with a real image provider through omp; omp 18.7 to 18.14 as binaries (source read only); omp's TUI Roles picker itself (its pool is the same registry --kind lists); /images/edits; an image model whose id is also a chat model (left out); a WSL omp (it already had a key).
This commit is contained in:
+51
-4
@@ -384,9 +384,10 @@ func ompAt(at place, dir string, entry func() ompProviderEntry) *Agent {
|
||||
// (commit/model-selection.ts), tiny names sessions and classifies
|
||||
// and takes smol's model, memory takes tiny's, else smol's
|
||||
// (ROLE_CONFIGURED_FALLBACK). omp's other roles (KIND_ROLE_IDS)
|
||||
// are for kinds of model other than the chat models magpie writes
|
||||
// for omp: image making, web search, speech, dictation, and the
|
||||
// judge its find tool turns on for a TypeSafe jev model
|
||||
// are for kinds of model other than chat: image making, web
|
||||
// search, speech, dictation, and the judge its find tool turns on
|
||||
// for a TypeSafe jev model. Of those magpie writes image models
|
||||
// for omp (ompImageModels), picked in omp's own Roles view
|
||||
role("commit", "commit", "commit", true),
|
||||
role("tiny", "tiny", "tiny", true),
|
||||
role("memory", "memory", "memory", true),
|
||||
@@ -562,6 +563,10 @@ type ompModel struct {
|
||||
Context int `yaml:"contextWindow,omitempty"`
|
||||
MaxTokens int `yaml:"maxTokens,omitempty"`
|
||||
Input []string `yaml:"input,omitempty"`
|
||||
// Kind is what the model is for when it isn't chat: "image" for one
|
||||
// that draws, which omp's image role takes and no chat role does
|
||||
// (ompImageModels)
|
||||
Kind string `yaml:"kind,omitempty"`
|
||||
// Cost is the model's price in USD per million tokens, the unit omp's
|
||||
// calculateUsageCost divides by (omp 18.9.1, pi-catalog
|
||||
// src/models.ts). omp's custom provider prices a call by it alone;
|
||||
@@ -700,6 +705,8 @@ func ompProviderAt(gw, version string) ompProviderEntry {
|
||||
}
|
||||
ms = append(ms, e)
|
||||
}
|
||||
images := ompImageModels(version, ms)
|
||||
ms = append(ms, images...)
|
||||
e := ompProviderEntry{BaseURL: gw + "/v1", API: "openai-completions", Auth: "none",
|
||||
Headers: map[string]string{"User-Agent": "omp"}, Models: ms}
|
||||
if version != "" && !Newer(ompSessionSince, version) {
|
||||
@@ -707,12 +714,52 @@ func ompProviderAt(gw, version string) ompProviderEntry {
|
||||
}
|
||||
// whqtian on Discord: a WSL omp under NAT asks Windows' address, where
|
||||
// the gateway turns a request without a named key away
|
||||
if key := keyAt(gw); key != gateway.Token {
|
||||
// on loopback too once an image model is listed: omp's generate_image
|
||||
// skips a model of a keyless provider as "credentials unavailable"
|
||||
// (image-gen.ts, isAuthenticated turns auth: none's kNoAuth away; omp
|
||||
// 18.15.0 run against a stand-in gateway), where chat goes without one
|
||||
if key := keyAt(gw); key != gateway.Token || len(images) > 0 {
|
||||
e.Auth, e.APIKey = "", key
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
// ompKindSince is the first omp whose models.yml takes a model's kind and
|
||||
// a runner API such as openai-images (pi-coding-agent 18.7.0,
|
||||
// models-config-schema-bundle.ts); 18.6.3's schema knows neither and turns
|
||||
// the whole file away over an api it doesn't list.
|
||||
const ompKindSince = "18.7.0"
|
||||
|
||||
// ompImageModels are magpie's image models (Settings › Images, as
|
||||
// generate_image offers them) as omp's image role takes them (treeman_26897
|
||||
// on Discord): kind image on openai-images, which omp's generate_image
|
||||
// posts to the provider's baseUrl + /images/generations, or /images/edits
|
||||
// with images to change (pi-ai images/openai-images.ts, omp 18.7.0 to
|
||||
// 18.15.0), the gateway's /v1/images. The role accepts a model of kind
|
||||
// image alone (model-roles.ts), and a chat model is of kind chat, so before
|
||||
// these the role listed none of magpie's. With one listed, the provider
|
||||
// takes the gateway's key in place of auth: none (ompProviderAt). None for
|
||||
// an omp before ompKindSince, or one whose version isn't known, as
|
||||
// ompTakesMax; nor one whose id a chat model in chat has already, which one
|
||||
// id can't be both.
|
||||
func ompImageModels(version string, chat []ompModel) []ompModel {
|
||||
if version == "" || Newer(ompKindSince, version) {
|
||||
return nil
|
||||
}
|
||||
var out []ompModel
|
||||
for _, m := range gateway.ImageModels() {
|
||||
if slices.ContainsFunc(chat, func(c ompModel) bool { return c.ID == m.ID }) {
|
||||
continue
|
||||
}
|
||||
in := []string{"text"}
|
||||
if m.Images {
|
||||
in = append(in, "image")
|
||||
}
|
||||
out = append(out, ompModel{ID: m.ID, Name: m.Name, API: "openai-images", Kind: "image", Input: in})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ompGeminiMode is how omp asks a Gemini model on google-generative-ai
|
||||
// to think. Gemini 3 and later take thinkingConfig.thinkingLevel
|
||||
// (google-level: omp sends minimal to high as MINIMAL to HIGH, xhigh and max
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// treeman_26897 on Discord: omp's Roles view had none of magpie's image
|
||||
// models under IMAGE. omp's image role takes a model of kind image alone
|
||||
// (model-roles.ts), and every model magpie wrote to models.yml was a chat
|
||||
// model. From omp 18.7.0 models.yml takes kind: image on openai-images,
|
||||
// which generate_image posts to the provider's baseUrl + /images/generations,
|
||||
// the gateway's /v1/images. Its generate_image skips a keyless provider's
|
||||
// model, so magpie's entry then carries the gateway's key. omp 18.15.0 was
|
||||
// run with this models.yml against a stand-in gateway: --kind image lists
|
||||
// art/gpt-image-2, and generate_image posted it to /v1/images/generations.
|
||||
func TestOmpListsImageModelsForItsImageRole(t *testing.T) {
|
||||
home := piExtensionHome(t)
|
||||
was := ompVersion
|
||||
ompVersion = func() string { return "18.15.0" }
|
||||
defer func() { ompVersion = was }()
|
||||
|
||||
a := omp(home)
|
||||
if err := a.Field("model").Set(magpieID + "/mixed/deepseek-v4.1-flash"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := filepath.Join(home, ".omp", "agent", "models.yml")
|
||||
var f struct {
|
||||
Providers map[string]ompProviderEntry `yaml:"providers"`
|
||||
}
|
||||
if err := yaml.Unmarshal([]byte(readFile(path)), &f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
e := f.Providers[magpieID]
|
||||
// omp's generate_image skips a model of a keyless provider
|
||||
if e.Auth != "" || e.APIKey != "magpie" {
|
||||
t.Errorf("auth %q, apiKey %q: want the gateway's key, not auth: none", e.Auth, e.APIKey)
|
||||
}
|
||||
if e.BaseURL != here(home).v1() {
|
||||
t.Errorf("baseUrl = %q, want %q: omp posts to it + /images/generations", e.BaseURL, here(home).v1())
|
||||
}
|
||||
var img *ompModel
|
||||
for i, m := range e.Models {
|
||||
switch {
|
||||
case m.ID == "art/gpt-image-2":
|
||||
img = &e.Models[i]
|
||||
case m.Kind != "":
|
||||
t.Errorf("%s is of kind %q, want chat (no kind)", m.ID, m.Kind)
|
||||
}
|
||||
}
|
||||
if img == nil {
|
||||
t.Fatalf("no art/gpt-image-2 in models.yml:\n%s", readFile(path))
|
||||
}
|
||||
if img.Kind != "image" || img.API != "openai-images" || strings.Join(img.Input, ",") != "text,image" || img.Name != "GPT Image 2 · Art" {
|
||||
t.Errorf("image model = %+v, want kind image on openai-images, input text,image", *img)
|
||||
}
|
||||
if img.Reasoning || img.Thinking != nil || img.Cost != nil {
|
||||
t.Errorf("image model has chat fields: %+v", *img)
|
||||
}
|
||||
|
||||
// omp before 18.7.0 turns the whole file away over openai-images, and
|
||||
// one whose version isn't known is taken for an older one
|
||||
// (and its chat stays keyless on loopback)
|
||||
for _, v := range []string{"18.6.3", ""} {
|
||||
e := ompProviderAt("http://127.0.0.1:3425", v)
|
||||
for _, m := range e.Models {
|
||||
if m.Kind != "" || m.API == "openai-images" {
|
||||
t.Errorf("omp %q got %s (%s, %s)", v, m.ID, m.Kind, m.API)
|
||||
}
|
||||
}
|
||||
if e.Auth != "none" || e.APIKey != "" {
|
||||
t.Errorf("omp %q: auth %q, apiKey %q, want auth: none", v, e.Auth, e.APIKey)
|
||||
}
|
||||
}
|
||||
got := 0
|
||||
for _, m := range ompProviderAt("http://127.0.0.1:3425", "18.7.0").Models {
|
||||
if m.Kind == "image" {
|
||||
got++
|
||||
}
|
||||
}
|
||||
if got != 1 {
|
||||
t.Errorf("omp 18.7.0: %d image models, want 1", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user