vectorize_texts/
vectorize_texts.rs1use dim_rs::{prelude::*, vectorization::ModelParameters};
2use tokio;
3use anyhow::{Error, Result};
4use async_openai;
5
6#[tokio::main]
7async fn main() -> Result<(), Error> {
8 let test_text: String = "Hi, this is dim. I am here to vectorize whatever your want."
10 .to_string();
11
12 let mut vector: Vector<String> = Vector::from_text(
14 test_text
15 );
16
17 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") .with_api_key("your_api_key")
22 );
23
24 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 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 println!("Vector: {:?}", vector.get_vector());
49 println!("Vector Length: {:?}", vector.get_vector().len());
50
51 Ok(())
52}