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)?;
|
||||
match value {
|
||||
Value::String(s) => Ok(s),
|
||||
Value::Array(arr) => arr
|
||||
.first()
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.to_string())
|
||||
.ok_or_else(|| {
|
||||
serde::de::Error::custom("array is empty or contains non-string elements")
|
||||
}),
|
||||
Value::Array(arr) => {
|
||||
if arr.len() == 1 {
|
||||
match arr[0].as_str() {
|
||||
Some(s) => Ok(s.to_string()),
|
||||
None => Err(serde::de::Error::custom(
|
||||
"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(
|
||||
"expected a string or an array of strings",
|
||||
"Expected a string or an array of strings",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user