From 6280f5ab4b476882f779b4359df2514399823ac5 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 20 Dec 2023 11:29:52 +0800 Subject: feat: qianwen vision models support embeded images (#277) --- src/config/input.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/config') diff --git a/src/config/input.rs b/src/config/input.rs index b1cf6c3..fc29c49 100644 --- a/src/config/input.rs +++ b/src/config/input.rs @@ -3,6 +3,8 @@ use crate::utils::sha256sum; use anyhow::{bail, Context, Result}; use base64::{self, engine::general_purpose::STANDARD, Engine}; +use fancy_regex::Regex; +use lazy_static::lazy_static; use mime_guess::from_path; use std::{ collections::HashMap, @@ -13,6 +15,10 @@ use std::{ const IMAGE_EXTS: [&str; 5] = ["png", "jpeg", "jpg", "webp", "gif"]; +lazy_static! { + static ref URL_RE: Regex = Regex::new(r"^[A-Za-z0-9_-]{2,}:/").unwrap(); +} + #[derive(Debug, Clone)] pub struct Input { text: String, @@ -128,10 +134,7 @@ pub fn resolve_data_url(data_urls: &HashMap, data_url: String) - } fn resolve_path(file: &str) -> Option { - if ["https://", "http://", "data:"] - .iter() - .any(|v| file.starts_with(v)) - { + if let Ok(true) = URL_RE.is_match(file) { return None; } let path = if let (Some(file), Some(home)) = (file.strip_prefix('~'), dirs::home_dir()) { -- cgit v1.2.3