From 7c679399d5020aa36be713f651ab5a7207fd65f5 Mon Sep 17 00:00:00 2001 From: Miquel Farre Date: Wed, 13 Nov 2024 12:42:11 +0000 Subject: [PATCH] router changes --- router/src/lib.rs | 1 + router/src/validation.rs | 41 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/router/src/lib.rs b/router/src/lib.rs index 84e9bc48..6a975bba 100644 --- a/router/src/lib.rs +++ b/router/src/lib.rs @@ -1173,6 +1173,7 @@ pub struct Url { pub enum MessageChunk { Text { text: String }, ImageUrl { image_url: Url }, + Video { video_url: Url }, } #[derive(Clone, Deserialize, ToSchema, Serialize, Debug, PartialEq)] diff --git a/router/src/validation.rs b/router/src/validation.rs index 8137ac58..082f2ee7 100644 --- a/router/src/validation.rs +++ b/router/src/validation.rs @@ -580,6 +580,14 @@ fn fetch_image(input: &str) -> Result<(Vec, String, usize, usize), Validatio } } +fn fetch_video(input: &str) -> Result { + if input.starts_with("http://") || input.starts_with("https://") { + Ok(input.to_string()) + } else { + Err(ValidationError::InvalidVideoContent(input.to_string())) + } +} + fn image_tokens( config: &Config, preprocessor_config: Option<&HubPreprocessorConfig>, @@ -645,6 +653,9 @@ fn prepare_input( ) -> Result<(tokenizers::Encoding, Vec), ValidationError> { use Config::*; static RE: Lazy = Lazy::new(|| Regex::new(r"!\[\]\([^\)]*\)").unwrap()); + // Add video regex + static VIDEO_RE: Lazy = Lazy::new(|| Regex::new(r"