fix(image): 图片生成 - 打通分辨率选择并补充回归测试
This commit is contained in:
1 parent
6a118ae93b
commit
db8a301474
9 files changed
+125
-20
No files matched your search
@@ -158,7 +158,7 @@ func TestWorkbenchTaskRejectsUnknownParametersAndClientConfig(t *testing.T) {
|
||||
|
||||
func TestWorkbenchTaskCanBeCreatedWithoutTool(t *testing.T) {
|
||||
s, _, _ := newWorkbenchTest(t)
|
||||
request := TaskInput{Kind: KindImage, Prompt: "A glass greenhouse at sunrise", Model: "image-model", LogicalModelID: "logical", Parameters: map[string]any{"size": "1024x1024", "count": 1}}
|
||||
request := TaskInput{Kind: KindImage, Prompt: "A glass greenhouse at sunrise", Model: "image-model", LogicalModelID: "logical", Parameters: map[string]any{"size": "1024x1024", "imageResolution": "2k", "count": 1}}
|
||||
resolved, err := s.ResolveTask("user", request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -174,7 +174,8 @@ func TestWorkbenchTaskCanBeCreatedWithoutTool(t *testing.T) {
|
||||
t.Fatalf("tool-less task contains a tool id: %#v", metadata)
|
||||
}
|
||||
snapshot := metadata["workbench"].(map[string]any)
|
||||
if snapshot["kind"] != KindImage || snapshot["parameters"].(map[string]any)["count"] != 1 {
|
||||
parameters := snapshot["parameters"].(map[string]any)
|
||||
if snapshot["kind"] != KindImage || parameters["count"] != 1 || parameters["imageResolution"] != "2k" {
|
||||
t.Fatalf("workbench parameters not snapshotted: %#v", snapshot)
|
||||
}
|
||||
if resolved.TaskType != "canvas_image" || resolved.Operation != "image" {
|
||||
|
||||
@@ -194,7 +194,7 @@ func (s *Service) ResolveTask(userID string, req TaskInput) (*TaskResolution, er
|
||||
|
||||
func normalizeTaskParameters(kind string, params map[string]any) (map[string]any, error) {
|
||||
allowed := map[string]map[string]bool{
|
||||
KindImage: {"size": true, "quality": true, "count": true},
|
||||
KindImage: {"size": true, "quality": true, "imageResolution": true, "count": true},
|
||||
KindVideo: {"seconds": true, "ratio": true, "resolution": true, "generateAudio": true, "watermark": true},
|
||||
}[kind]
|
||||
if allowed == nil {
|
||||
@@ -206,7 +206,7 @@ func normalizeTaskParameters(kind string, params map[string]any) (map[string]any
|
||||
return nil, kernel.BadAuthRequest("生成参数包含不支持字段: " + key)
|
||||
}
|
||||
switch key {
|
||||
case "size", "quality", "ratio", "resolution":
|
||||
case "size", "quality", "imageResolution", "ratio", "resolution":
|
||||
text, ok := value.(string)
|
||||
text = strings.TrimSpace(text)
|
||||
if !ok || len(text) > 64 || strings.Contains(text, "://") || strings.HasPrefix(strings.ToLower(text), "data:") {
|
||||
|
||||
Reference in new issue
Block a user