mirror of
https://github.com/huggingface/text-generation-inference.git
synced 2025-09-11 12:24:53 +00:00
feat: better error if array len >=1
This commit is contained in:
parent
424b24f5fa
commit
c1afdcc1cb
@ -291,15 +291,23 @@ mod prompt_serde {
|
|||||||
let value = Value::deserialize(deserializer)?;
|
let value = Value::deserialize(deserializer)?;
|
||||||
match value {
|
match value {
|
||||||
Value::String(s) => Ok(s),
|
Value::String(s) => Ok(s),
|
||||||
Value::Array(arr) => arr
|
Value::Array(arr) => {
|
||||||
.first()
|
if arr.len() == 1 {
|
||||||
.and_then(|v| v.as_str())
|
match arr[0].as_str() {
|
||||||
.map(|s| s.to_string())
|
Some(s) => Ok(s.to_string()),
|
||||||
.ok_or_else(|| {
|
None => Err(serde::de::Error::custom(
|
||||||
serde::de::Error::custom("array is empty or contains non-string elements")
|
"Array contains non-string elements",
|
||||||
}),
|
)),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(serde::de::Error::custom(
|
||||||
|
"Array contains non-string element. Expected string. In general arrays should not be used for prompts. Please use a string instead if possible.",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_ => Err(serde::de::Error::custom(
|
_ => Err(serde::de::Error::custom(
|
||||||
"expected a string or an array of strings",
|
"Expected a string or an array of strings",
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user