Skip to content

Commit 80bd721

Browse files
committed
renamed RawText to Text and added a RawText field within enum TextContext and fixed the handling inside Desearlizer() right below the enum
1 parent 7636b2e commit 80bd721

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

tensorzero-core/src/endpoints/openai_compatible.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,10 @@ struct OpenAICompatibleFile {
689689
#[derive(Debug)]
690690
// Two mutually exclusive modes - the standard OpenAI text, and our special TensorZero mode
691691
pub enum TextContent {
692+
/// "content": [{"type": "tensorzero::raw_text", "value": "Write a haiku about artificial intelligence"}]
693+
RawText { value: String },
692694
/// A normal openai text content block: `{"type": "text", "text": "Some content"}`. The `type` key comes from the parent `OpenAICompatibleContentBlock`
693-
RawText { text: String },
695+
Text { text: String },
694696
/// A special TensorZero mode: `{"type": "text", "tensorzero::arguments": {"custom_key": "custom_val"}}`.
695697
TensorZeroArguments {
696698
tensorzero_arguments: Map<String, Value>,
@@ -701,29 +703,42 @@ impl<'de> Deserialize<'de> for TextContent {
701703
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
702704
let mut object: Map<String, Value> = Map::deserialize(de)?;
703705
let text = object.remove("text");
706+
let raw_text = object.remove("tensorzero::raw_text");
704707
let arguments = object.remove("tensorzero::arguments");
705-
match (text, arguments) {
706-
(Some(text), None) => Ok(TextContent::RawText {
708+
match (text, raw_text, arguments) {
709+
(Some(text), None, None) => Ok(TextContent::Text {
707710
text: match text {
708711
Value::String(text) => text,
709712
_ => return Err(serde::de::Error::custom(
710713
"`text` must be a string when using `\"type\": \"text\"`",
711714
)),
712715
},
713716
}),
714-
(None, Some(arguments)) => Ok(TextContent::TensorZeroArguments {
717+
(None, Some(arguments), None) => Ok(TextContent::RawText {
718+
value: match arguments {
719+
Value::String(value) => value,
720+
_ => return Err(serde::de::Error::custom(
721+
"`tensorzero::raw_text` must be a string when using `\"type\": \"text\"`",
722+
)),
723+
},
724+
}),
725+
(None, None, Some(arguments)) => Ok(TextContent::TensorZeroArguments {
715726
tensorzero_arguments: match arguments {
716727
Value::Object(arguments) => arguments,
717728
_ => return Err(serde::de::Error::custom(
718729
"`tensorzero::arguments` must be an object when using `\"type\": \"text\"`",
719730
)),
720731
},
721732
}),
722-
(Some(_), Some(_)) => Err(serde::de::Error::custom(
733+
(Some(_), None, Some(_)) => Err(serde::de::Error::custom(
723734
"Only one of `text` or `tensorzero::arguments` can be set when using `\"type\": \"text\"`",
724735
)),
725-
(None, None) => Err(serde::de::Error::custom(
726-
"Either `text` or `tensorzero::arguments` must be set when using `\"type\": \"text\"`",
736+
(None, None, None) => Err(serde::de::Error::custom(
737+
"Either `text` or `tensorzero::arguments` must be set when using `\"type\": \"text\"` or
738+
`tensorzero::raw_text` must be set when using `\"type\": \"tensorzero::raw_text\"`",
739+
)),
740+
_ => Err(serde::de::Error::custom(
741+
"Invalid content block: must be one of `text`, `tensorzero::raw_text`, or `tensorzero::arguments`",
727742
)),
728743
}
729744
}

0 commit comments

Comments
 (0)