pub struct Vector<T> { /* private fields */ }
Expand description
A vector that contains a vectorized data and the original data. This struct pairs the original data with its vector representation and type information.
Implementations§
Source§impl<DynamicImage> Vector<DynamicImage>
impl<DynamicImage> Vector<DynamicImage>
Sourcepub fn from_image(data: DynamicImage) -> Self
pub fn from_image(data: DynamicImage) -> Self
Initialize a new vector from image data
§Arguments
data
- The image data to be vectorized
§Returns
A new Vector instance containing the image data
Examples found in repository?
examples/vectorize_images.rs (line 22)
16async fn main() -> Result<(), Error> {
17 // Load image
18 let image_path: &str = "./examples/images/54e2c8ea-58ef-4871-ae3f-75eabd9a2c6c.jpg";
19 let test_image: DynamicImage = image::open(image_path).unwrap();
20
21 // Create a Vector object from the image
22 let mut vector: Vector<DynamicImage> = Vector::from_image(test_image);
23
24 // Initialize client
25 let client: Client<OpenAIConfig> = Client::with_config(
26 OpenAIConfig::new()
27 .with_api_base("http://192.168.0.101:11434/v1") // comment this out if you use OpenAI instead of Ollama
28 .with_api_key("your_api_key")
29 );
30
31 // Initialize prompts
32 let prompts: Vec<String> = vec![
33 "output in json. Rate the image's offensiveness from 0.0 to 10.0. {'offensiveness': your score}".to_string(),
34 "output in json. Rate the image's friendliness from 0.0 to 10.0. {'friendliness': your score}".to_string(),
35 ];
36
37 // Initialize model parameters
38 let model_parameters = ModelParameters::new(
39 "minicpm-v".to_string(),
40 Some(0.7),
41 None
42 );
43
44 // Vectorize image
45 vectorize_image_concurrently(
46 prompts,
47 &mut vector,
48 client,
49 model_parameters
50 ).await?;
51
52 // Print vectorized result
53 println!("Vector: {:?}", vector.get_vector());
54 println!("Vector Length: {:?}", vector.get_vector().len());
55
56 Ok(())
57}
Source§impl<String> Vector<String>
impl<String> Vector<String>
Sourcepub fn from_text(data: String) -> Self
pub fn from_text(data: String) -> Self
Initialize a new vector from text data
§Arguments
data
- The text data to be vectorized
§Returns
A new Vector instance containing the text data
Examples found in repository?
examples/vectorize_texts.rs (lines 13-15)
7async fn main() -> Result<(), Error> {
8 // Load text
9 let test_text: String = "Hi, this is dim. I am here to vectorize whatever your want."
10 .to_string();
11
12 // Create a Vector object from the image
13 let mut vector: Vector<String> = Vector::from_text(
14 test_text
15 );
16
17 // Initialize client
18 let client: async_openai::Client<async_openai::config::OpenAIConfig> = async_openai::Client::with_config(
19 async_openai::config::OpenAIConfig::new()
20 .with_api_base("http://192.168.0.101:11434/v1") // comment this out if you use OpenAI instead of Ollama
21 .with_api_key("your_api_key")
22 );
23
24 // Initialize prompts
25 let prompts: Vec<String> = vec![
26 "Score the sentiment intensity of the text from 1 (extremely negative) to 9 (extremely positive). Consider emotional language, tone, and context. Format your response exactly like this example: {'sentiment_score': 7}".to_string(),
27 "Rate the formality of the text from 1 (highly informal, slang-heavy) to 9 (highly formal, academic/professional). Format your response exactly like this example: {'formality_score': 4}".to_string(),
28 "Assess the emotional intensity of the text from 1 (neutral/clinical) to 9 (highly emotional, passionate, or provocative). Format your response exactly like this example: {'emotional_score': 8}".to_string(),
29 "Score how subjective the text is from 1 (purely factual/objective) to 9 (heavily opinionated/subjective). Format your response exactly like this example: {'subjectivity_score': 6}".to_string(),
30 "Rate the linguistic complexity of the text from 1 (simple vocabulary/short sentences) to 9 (dense jargon/long, intricate sentences). Format your response exactly like this example: {'complexity_score': 3}".to_string(),
31 "Score the dominant intent: 1-3 (informative/educational), 4-6 (persuasive/argumentative), 7-9 (narrative/storytelling). Format your response exactly like this example: {'intent_score': 5}".to_string(),
32 "Rate how urgent or time-sensitive the text feels from 1 (no urgency) to 9 (immediate action required). Format your response exactly like this example: {'urgency_score': 2}".to_string(),
33 "Score the specificity of details from 1 (vague/abstract) to 9 (highly specific/concrete examples). Format your response exactly like this example: {'specificity_score': 7}".to_string(),
34 "Rate the politeness of the tone from 1 (rude/confrontational) to 9 (extremely polite/deferential). Format your response exactly like this example: {'politeness_score': 8}".to_string(),
35 "Categorize the text's primary domain: 1-3 (technical/scientific), 4-6 (casual/everyday), 7-9 (artistic/creative). Format your response exactly like this example: {'domain_score': 4}".to_string(),
36 ];
37
38 // Vectorize image
39 let model_parameters = ModelParameters::new("minicpm-v".to_string(), None, None);
40 vectorize_string_concurrently(
41 prompts,
42 &mut vector,
43 client,
44 model_parameters
45 ).await?;
46
47 // Print vectorized result
48 println!("Vector: {:?}", vector.get_vector());
49 println!("Vector Length: {:?}", vector.get_vector().len());
50
51 Ok(())
52}
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Vector<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Vector<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T> VectorOperations<T> for Vector<T>
impl<T> VectorOperations<T> for Vector<T>
Auto Trait Implementations§
impl<T> Freeze for Vector<T>where
T: Freeze,
impl<T> RefUnwindSafe for Vector<T>where
T: RefUnwindSafe,
impl<T> Send for Vector<T>where
T: Send,
impl<T> Sync for Vector<T>where
T: Sync,
impl<T> Unpin for Vector<T>where
T: Unpin,
impl<T> UnwindSafe for Vector<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more