pub struct MarkdownToParts<'a> { /* private fields */ }Expand description
Converts markdown to parts considering  means Gemini will be see the images too. link can be URL or file path.
Implementations§
Source§impl<'a> MarkdownToParts<'a>
impl<'a> MarkdownToParts<'a>
pub fn base64s(&self) -> &Vec<MatchedFiles>
Source§impl<'a> MarkdownToParts<'a>
impl<'a> MarkdownToParts<'a>
pub fn builder() -> MarkdownToPartsBuilder
Sourcepub async fn from_regex_checked(
markdown: &'a str,
regex: Regex,
guess_mime_type: fn(url: &str) -> Mime,
decide_download: fn(headers: &HeaderMap) -> bool,
) -> Self
pub async fn from_regex_checked( markdown: &'a str, regex: Regex, guess_mime_type: fn(url: &str) -> Mime, decide_download: fn(headers: &HeaderMap) -> bool, ) -> Self
§Panics
regex must have a Regex with only 1 capture group with file URL as first capture
group, else it PANICS.
§Arguments
guess_mime_type is used to detect mimi_type of URL pointing to file system or web resource
with no “Content-Type” header.
decide_download is used to decide if to download. If it returns false, resource will not
be fetched and won’t be in parts
§Example
from_regex("Your markdown string...", Regex::new(r"(?s)!\[.*?].?\((.*?)\)").unwrap(), |_| mime::IMAGE_PNG, |_| true)Sourcepub async fn from_regex(
markdown: &'a str,
regex: Regex,
guess_mime_type: fn(url: &str) -> Mime,
) -> Self
pub async fn from_regex( markdown: &'a str, regex: Regex, guess_mime_type: fn(url: &str) -> Mime, ) -> Self
§Panics
regex must have a Regex with only 1 capture group with file URL as first capture
group, else it PANICS.
§Arguments
guess_mime_type is used to detect mimi_type of URL pointing to file system or web resource
with no “Content-Type” header.
§Example
from_regex("Your markdown string...", Regex::new(r"(?s)!\[.*?].?\((.*?)\)").unwrap(), |_|
mime::IMAGE_PNG)Sourcepub async fn new_checked(
markdown: &'a str,
guess_mime_type: fn(url: &str) -> Mime,
decide_download: fn(headers: &HeaderMap) -> bool,
) -> Self
pub async fn new_checked( markdown: &'a str, guess_mime_type: fn(url: &str) -> Mime, decide_download: fn(headers: &HeaderMap) -> bool, ) -> Self
§Arguments
guess_mime_type is used to detect mimi_type of URL pointing to file system or web resource
with no “Content-Type” header.
decide_download is used to decide if to download. If it returns false, resource will not
be fetched and won’t be in parts
§Example
new("Your markdown string...", |_| mime::IMAGE_PNG, |_| true)Sourcepub async fn new(
markdown: &'a str,
guess_mime_type: fn(url: &str) -> Mime,
) -> Self
pub async fn new( markdown: &'a str, guess_mime_type: fn(url: &str) -> Mime, ) -> Self
§Arguments
guess_mime_type is used to detect mimi_type of URL pointing to file system or web resource
with no “Content-Type” header.
§Example
new("Your markdown string...", |_| mime::IMAGE_PNG)Examples found in repository?
18async fn main() {
19 let mut session = Session::new(6);
20 let api_key = env::var("GEMINI_API_KEY").expect("GEMINI_API_KEY must be set");
21 let ai = Gemini::new(api_key, "gemini-2.5-flash", None);
22
23 println!("--- Multimodal (Images/Files) Example ---");
24
25 // Use MarkdownToParts to easily parse a string with image/file markers
26 // It supports both URLs and local file paths!
27 let content = "Describe this image: ";
28 println!("Processing: {}", content);
29
30 let parts = MarkdownToParts::new(content, |_| mime::IMAGE_PNG)
31 .await
32 .process();
33
34 let response = ai.ask(session.ask(parts)).await.unwrap();
35
36 println!("\nGemini: {}", response.get_chat().get_text_no_think(""));
37}Sourcepub fn process(self) -> Vec<Part>
pub fn process(self) -> Vec<Part>
Examples found in repository?
18async fn main() {
19 let mut session = Session::new(6);
20 let api_key = env::var("GEMINI_API_KEY").expect("GEMINI_API_KEY must be set");
21 let ai = Gemini::new(api_key, "gemini-2.5-flash", None);
22
23 println!("--- Multimodal (Images/Files) Example ---");
24
25 // Use MarkdownToParts to easily parse a string with image/file markers
26 // It supports both URLs and local file paths!
27 let content = "Describe this image: ";
28 println!("Processing: {}", content);
29
30 let parts = MarkdownToParts::new(content, |_| mime::IMAGE_PNG)
31 .await
32 .process();
33
34 let response = ai.ask(session.ask(parts)).await.unwrap();
35
36 println!("\nGemini: {}", response.get_chat().get_text_no_think(""));
37}Trait Implementations§
Source§impl<'a> Clone for MarkdownToParts<'a>
impl<'a> Clone for MarkdownToParts<'a>
Source§fn clone(&self) -> MarkdownToParts<'a>
fn clone(&self) -> MarkdownToParts<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more