Spaces:
Running on Zero

File size: 2,049 Bytes
7defe51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
--- a/engine/src/yue2/yue2-request.h
+++ b/engine/src/yue2/yue2-request.h
@@ -363,9 +363,10 @@
         yyjson_doc_free(doc);
         return false;
     }
-    if ((!present || out->style.empty()) && !yyjson_obj_get(root, "songs")) {
+    const bool style_present = present;
+    if (!style_present && (yyjson_obj_get(root, "style") || !yyjson_obj_get(root, "songs"))) {
         if (err) {
-            *err = "\"style\" is required and must be non-empty";
+            *err = "\"style\" is required and must be a string";
         }
         yyjson_doc_free(doc);
         return false;
@@ -575,14 +576,16 @@
             }
             Yue2SongSpec spec;
             bool         sp = false;
-            if (!yue2_req_str(sv, "style", &spec.style, &sp, err) || !yue2_req_str(sv, "lyrics", &spec.lyrics, &sp, err) ||
+            bool         song_style_present = false;
+            if (!yue2_req_str(sv, "style", &spec.style, &song_style_present, err) ||
+                !yue2_req_str(sv, "lyrics", &spec.lyrics, &sp, err) ||
                 !yue2_req_str(sv, "abc", &spec.abc, &sp, err)) {
                 yyjson_doc_free(doc);
                 return false;
             }
             spec.abc_provided = !spec.abc.empty();
-            if (spec.style.empty()) {
-                if (err) *err = "\"songs\" entry " + std::to_string(idx) + " needs a non-empty \"style\"";
+            if (!song_style_present) {
+                if (err) *err = "\"songs\" entry " + std::to_string(idx) + " needs a \"style\" string";
                 yyjson_doc_free(doc);
                 return false;
             }
@@ -605,7 +608,7 @@
         out->lm_batch_size = (int) out->songs.size();
         // The top-level prompt is what /yue2/props-style validators and the
         // log lines read; the first song stands in for it when absent.
-        if (out->style.empty()) out->style = out->songs[0].style;
+        if (!style_present) out->style = out->songs[0].style;
         if (out->lyrics.empty()) out->lyrics = out->songs[0].lyrics;
     }