mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-09-21 17:38:00 +00:00
feat: LuaJIT worker-pool VM, multimodal/disable-thinking passthrough, WebUI redesign, DeepSeek V4
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package lua
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@ -85,3 +86,110 @@ func TestBuildHeadersCustomHook(t *testing.T) {
|
||||
t.Fatalf("timestamp = %q", hdrs["X-Timestamp"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisableThinkingPassthrough(t *testing.T) {
|
||||
vm := NewVM(t.TempDir())
|
||||
if err := vm.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer vm.Stop()
|
||||
body := `{"model":"x","disable_thinking":true,"messages":[{"role":"user","content":"hi"}]}`
|
||||
out, err := vm.Transform("deepseek", "transform_request", body)
|
||||
if err != nil {
|
||||
t.Fatalf("deepseek transform: %v", err)
|
||||
}
|
||||
var req struct {
|
||||
ExtraBody map[string]interface{} `json:"extra_body"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(out), &req); err != nil {
|
||||
t.Fatalf("unmarshal: %v (%s)", err, out)
|
||||
}
|
||||
thinking, ok := req.ExtraBody["thinking"].(map[string]interface{})
|
||||
if !ok {
|
||||
t.Fatalf("deepseek should emit extra_body.thinking on disable_thinking: %s", out)
|
||||
}
|
||||
if thinking["type"] != "disabled" {
|
||||
t.Fatalf("thinking.type = %v", thinking["type"])
|
||||
}
|
||||
|
||||
// anthropic: disable_thinking removes the thinking block
|
||||
out2, err := vm.Transform("anthropic", "transform_request", body)
|
||||
if err != nil {
|
||||
t.Fatalf("anthropic transform: %v", err)
|
||||
}
|
||||
if strings.Contains(out2, "thinking") {
|
||||
t.Fatalf("anthropic should drop thinking when disable_thinking: %s", out2)
|
||||
}
|
||||
out3, err := vm.Transform("anthropic", "transform_request", `{"model":"x","messages":[{"role":"user","content":"hi"}]}`)
|
||||
if err != nil {
|
||||
t.Fatalf("anthropic transform: %v", err)
|
||||
}
|
||||
if !strings.Contains(out3, "enabled") {
|
||||
t.Fatalf("anthropic should enable thinking by default: %s", out3)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultimodalTransform(t *testing.T) {
|
||||
vm := NewVM(t.TempDir())
|
||||
if err := vm.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer vm.Stop()
|
||||
body := `{"model":"x","messages":[{"role":"user","content":[
|
||||
{"type":"text","text":"what is this?"},
|
||||
{"type":"image_url","image_url":{"url":"data:image/png;base64,QUJD"}},
|
||||
{"type":"image_url","image_url":{"url":"https://ex.com/a.png"}}
|
||||
]}]}`
|
||||
|
||||
// anthropic: image_url -> image block (base64/url), text preserved
|
||||
out, err := vm.Transform("anthropic", "transform_request", body)
|
||||
if err != nil {
|
||||
t.Fatalf("anthropic: %v", err)
|
||||
}
|
||||
for _, want := range []string{`"media_type":"image/png"`, `"data":"QUJD"`, `"type":"url","url":"https://ex.com/a.png"`, `"what is this?"`} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("anthropic multimodal missing %s: %s", want, out)
|
||||
}
|
||||
}
|
||||
|
||||
// gemini: image_url -> inline_data
|
||||
gout, err := vm.Transform("gemini", "transform_request", body)
|
||||
if err != nil {
|
||||
t.Fatalf("gemini: %v", err)
|
||||
}
|
||||
var g struct {
|
||||
Contents []struct {
|
||||
Parts []map[string]interface{} `json:"parts"`
|
||||
} `json:"contents"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(gout), &g); err != nil {
|
||||
t.Fatalf("gemini unmarshal: %v", err)
|
||||
}
|
||||
if len(g.Contents) == 0 {
|
||||
t.Fatalf("gemini no contents")
|
||||
}
|
||||
var found bool
|
||||
for _, p := range g.Contents[0].Parts {
|
||||
if v, ok := p["inline_data"].(map[string]interface{}); ok && v["data"] == "QUJD" && v["mime_type"] == "image/png" {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("gemini missing inline_data image: %s", gout)
|
||||
}
|
||||
|
||||
// ollama: image_url -> images base64 array
|
||||
out, err = vm.Transform("ollama", "transform_request", body)
|
||||
if err != nil {
|
||||
t.Fatalf("ollama: %v", err)
|
||||
}
|
||||
if !strings.Contains(out, `"images":["QUJD"]`) {
|
||||
t.Fatalf("ollama multimodal missing images: %s", out)
|
||||
}
|
||||
|
||||
// openai passthrough keeps the content array intact
|
||||
po, _ := vm.Transform("openai", "transform_request", body)
|
||||
if !strings.Contains(po, `"image_url"`) || !strings.Contains(po, `,QUJD"`) {
|
||||
t.Fatalf("openai passthrough lost multimodal content: %s", po)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user