File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -277,15 +277,23 @@ mod prompt_serde {
277277 let value = Value :: deserialize ( deserializer) ?;
278278 match value {
279279 Value :: String ( s) => Ok ( s) ,
280- Value :: Array ( arr) => arr
281- . first ( )
282- . and_then ( |v| v. as_str ( ) )
283- . map ( |s| s. to_string ( ) )
284- . ok_or_else ( || {
285- serde:: de:: Error :: custom ( "array is empty or contains non-string elements" )
286- } ) ,
280+ Value :: Array ( arr) => {
281+ if arr. len ( ) == 1 {
282+ match arr[ 0 ] . as_str ( ) {
283+ Some ( s) => Ok ( s. to_string ( ) ) ,
284+ None => Err ( serde:: de:: Error :: custom (
285+ "Array contains non-string elements" ,
286+ ) ) ,
287+ }
288+ } else {
289+ Err ( serde:: de:: Error :: custom (
290+ "Array contains non-string element. Expected string. In general arrays should not be used for prompts. Please use a string instead if possible." ,
291+ ) )
292+ }
293+ }
294+
287295 _ => Err ( serde:: de:: Error :: custom (
288- "expected a string or an array of strings" ,
296+ "Expected a string or an array of strings" ,
289297 ) ) ,
290298 }
291299 }
You can’t perform that action at this time.
0 commit comments