Align default space and Hunyuan 3 behavior with hygate

This commit is contained in:
Luxferre
2026-09-07 11:05:20 +03:00
parent 187edabadb
commit c5ea129b44
3 changed files with 149 additions and 51 deletions
+68 -8
View File
@@ -285,6 +285,19 @@ func TestParseGradioStreamOutput(t *testing.T) {
if !frame5.OK || frame5.Content != "msg answer" || frame5.Reasoning != "msg think" {
t.Errorf("unexpected frame5: %+v", frame5)
}
// 6. Hy3 with null content and reasoning
hy3NullContent := `[[null, "Thinking process...", null]]`
frame6 := ParseGradioStreamOutput(hy3NullContent)
if !frame6.OK || frame6.Content != "" || frame6.Reasoning != "Thinking process..." {
t.Errorf("unexpected frame6: %+v", frame6)
}
// 7. Hy3 with 3 elements (answer, reasoning, null tool calls)
hy3ThreeElem := `[["Mocked answer", "Mocked reasoning", null]]`
frame7 := ParseGradioStreamOutput(hy3ThreeElem)
if !frame7.OK || frame7.Content != "Mocked answer" || frame7.Reasoning != "Mocked reasoning" || len(frame7.ToolCalls) != 0 {
t.Errorf("unexpected frame7: %+v", frame7)
}
}
func TestHunyuan3BuildPayload(t *testing.T) {
@@ -338,9 +351,9 @@ func TestHunyuan3BuildPayload(t *testing.T) {
t.Fatalf("expected 9 payload items, got %d", len(data))
}
// Message parameter (0): should be prompt continuation since last was tool
if msg, ok := data[0].(string); !ok || msg != "Please proceed based on the tool results." {
t.Errorf("expected continuation prompt, got %v", data[0])
// Message parameter (0): should be tool result prompt matching hygate behavior
if msg, ok := data[0].(string); !ok || msg != "Tool result for c1: 4" {
t.Errorf("expected 'Tool result for c1: 4', got %v", data[0])
}
// System parameter (1)
@@ -348,16 +361,19 @@ func TestHunyuan3BuildPayload(t *testing.T) {
t.Errorf("expected 'Be helpful', got %v", data[1])
}
// History parameter (2): should contain all messages including the tool turn
// History parameter (2): should contain prior turns (user, assistant with tool calls)
hist, ok := data[2].([]map[string]interface{})
if !ok {
t.Fatalf("expected history slice of maps, got %T", data[2])
}
if len(hist) != 3 {
t.Fatalf("expected 3 history items (user, assistant, tool), got %d", len(hist))
if len(hist) != 2 {
t.Fatalf("expected 2 history items (user, assistant), got %d", len(hist))
}
if hist[2]["role"] != "tool" || hist[2]["content"] != "4" || hist[2]["tool_call_id"] != "c1" {
t.Errorf("unexpected tool history entry: %+v", hist[2])
if hist[0]["role"] != "user" || hist[0]["content"] != "2+2" {
t.Errorf("unexpected user history entry: %+v", hist[0])
}
if hist[1]["role"] != "assistant" || len(hist[1]["tool_calls"].([]ToolCall)) != 1 {
t.Errorf("unexpected assistant history entry: %+v", hist[1])
}
// ThinkLevel parameter (3)
@@ -375,6 +391,26 @@ func TestHunyuan3BuildPayload(t *testing.T) {
if !ok || !strings.Contains(fnStr, "calc") {
t.Errorf("expected functions_json_str to contain 'calc', got %v", data[8])
}
// Test multi-tool turn: 2 tool messages at the end
reqMulti := req
reqMulti.Messages = append(reqMulti.Messages, ChatMessage{Role: "tool", Name: "fetch", Content: "done"})
dataMulti, err := gw.BuildGradioPayload(disc, reqMulti)
if err != nil {
t.Fatalf("BuildGradioPayload failed on multi-tool: %v", err)
}
// The last tool message is data[0]
if msg, ok := dataMulti[0].(string); !ok || msg != "Tool result for fetch: done" {
t.Errorf("expected 'Tool result for fetch: done', got %v", dataMulti[0])
}
// The first tool message is in history
histMulti, _ := dataMulti[2].([]map[string]interface{})
if len(histMulti) != 3 {
t.Fatalf("expected 3 history items (user, assistant, tool 1), got %d", len(histMulti))
}
if histMulti[2]["role"] != "tool" || histMulti[2]["content"] != "4" {
t.Errorf("unexpected tool 1 in history: %+v", histMulti[2])
}
}
func TestHunyuan3MockServerCompletion(t *testing.T) {
@@ -1330,3 +1366,27 @@ func TestToolChoiceHandling(t *testing.T) {
t.Errorf("expected specific function directive in instruction, got: %s", instrFn)
}
}
func TestConfiguredModelName(t *testing.T) {
disc := &SpaceDiscovery{
PrimaryModel: "hy3",
Models: []string{"hy3", "hunyuan3"},
}
// Without override
ConfiguredModelName = ""
list1 := disc.GetModelList()
if len(list1) < 2 || list1[0].ID != "hy3" {
t.Errorf("expected default first model hy3, got %+v", list1)
}
// With override
ConfiguredModelName = "my-custom-hy3"
defer func() { ConfiguredModelName = "" }()
list2 := disc.GetModelList()
if len(list2) < 3 || list2[0].ID != "my-custom-hy3" {
t.Errorf("expected first model to be my-custom-hy3, got %+v", list2)
}
}