@@ -670,6 +670,8 @@ enum OpenAICompatibleContentBlock {
670670 Text ( TextContent ) ,
671671 ImageUrl { image_url : OpenAICompatibleImageUrl } ,
672672 File { file : OpenAICompatibleFile } ,
673+ #[ serde( rename = "tensorzero::raw_text" ) ]
674+ RawText { value : String } ,
673675}
674676
675677#[ derive( Deserialize , Debug ) ]
@@ -689,8 +691,6 @@ struct OpenAICompatibleFile {
689691#[ derive( Debug ) ]
690692// Two mutually exclusive modes - the standard OpenAI text, and our special TensorZero mode
691693pub enum TextContent {
692- /// "content": [{"type": "tensorzero::raw_text", "value": "Write a haiku about artificial intelligence"}]
693- RawText { value : String } ,
694694 /// A normal openai text content block: `{"type": "text", "text": "Some content"}`. The `type` key comes from the parent `OpenAICompatibleContentBlock`
695695 Text { text : String } ,
696696 /// A special TensorZero mode: `{"type": "text", "tensorzero::arguments": {"custom_key": "custom_val"}}`.
@@ -703,42 +703,29 @@ impl<'de> Deserialize<'de> for TextContent {
703703 fn deserialize < D : Deserializer < ' de > > ( de : D ) -> Result < Self , D :: Error > {
704704 let mut object: Map < String , Value > = Map :: deserialize ( de) ?;
705705 let text = object. remove ( "text" ) ;
706- let raw_text = object. remove ( "tensorzero::raw_text" ) ;
707706 let arguments = object. remove ( "tensorzero::arguments" ) ;
708- match ( text, raw_text , arguments) {
709- ( Some ( text) , None , None ) => Ok ( TextContent :: Text {
707+ match ( text, arguments) {
708+ ( Some ( text) , None ) => Ok ( TextContent :: Text {
710709 text : match text {
711710 Value :: String ( text) => text,
712711 _ => return Err ( serde:: de:: Error :: custom (
713712 "`text` must be a string when using `\" type\" : \" text\" `" ,
714713 ) ) ,
715714 } ,
716715 } ) ,
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 {
716+ ( None , Some ( arguments) ) => Ok ( TextContent :: TensorZeroArguments {
726717 tensorzero_arguments : match arguments {
727718 Value :: Object ( arguments) => arguments,
728719 _ => return Err ( serde:: de:: Error :: custom (
729720 "`tensorzero::arguments` must be an object when using `\" type\" : \" text\" `" ,
730721 ) ) ,
731722 } ,
732723 } ) ,
733- ( Some ( _) , None , Some ( _) ) => Err ( serde:: de:: Error :: custom (
724+ ( Some ( _) , Some ( _) ) => Err ( serde:: de:: Error :: custom (
734725 "Only one of `text` or `tensorzero::arguments` can be set when using `\" type\" : \" text\" `" ,
735726 ) ) ,
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`" ,
727+ ( None , None ) => Err ( serde:: de:: Error :: custom (
728+ "Either `text` or `tensorzero::arguments` must be set when using `\" type\" : \" text\" `" ,
742729 ) ) ,
743730 }
744731 }
@@ -771,7 +758,8 @@ fn convert_openai_message_content(content: Value) -> Result<Vec<InputMessageCont
771758 for val in a {
772759 let block = serde_json:: from_value :: < OpenAICompatibleContentBlock > ( val. clone ( ) ) ;
773760 let output = match block {
774- Ok ( OpenAICompatibleContentBlock :: Text ( TextContent :: RawText { text } ) ) => InputMessageContent :: Text ( TextKind :: Text { text } ) ,
761+ Ok ( OpenAICompatibleContentBlock :: RawText { value } ) => InputMessageContent :: RawText { value } ,
762+ Ok ( OpenAICompatibleContentBlock :: Text ( TextContent :: Text { text } ) ) => InputMessageContent :: Text ( TextKind :: Text { text } ) ,
775763 Ok ( OpenAICompatibleContentBlock :: Text ( TextContent :: TensorZeroArguments { tensorzero_arguments } ) ) => InputMessageContent :: Text ( TextKind :: Arguments { arguments : tensorzero_arguments } ) ,
776764 Ok ( OpenAICompatibleContentBlock :: ImageUrl { image_url } ) => {
777765 if image_url. url . scheme ( ) == "data" {
0 commit comments