Skip to content

Commit

Permalink
feature: add prompt to image search
Browse files Browse the repository at this point in the history
  • Loading branch information
densumesh authored and cdxker committed Jan 8, 2025
1 parent 00a64ac commit 5531e2c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion server/src/data/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7656,7 +7656,10 @@ impl From<(ParsedQuery, f32)> for MultiQuery {
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone, PartialEq)]
#[serde(untagged)]
pub enum SearchModalities {
Image { image_url: String },
Image {
image_url: String,
llm_prompt: Option<String>,
},
Text(String),
}

Expand Down
8 changes: 4 additions & 4 deletions server/src/operators/message_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ pub async fn get_topic_string(

pub async fn get_text_from_image(
image_url: String,
prompt: Option<String>,
dataset: &Dataset,
) -> Result<String, ServiceError> {
let dataset_config = DatasetConfiguration::from_json(dataset.server_configuration.clone());
Expand Down Expand Up @@ -1286,12 +1287,11 @@ pub async fn get_text_from_image(
},
};

let default_system_prompt = "Please describe the image and turn the description into a search query. DO NOT INCLUDE ANY OTHER CONTEXT OR INFORMATION. JUST OUTPUT THE SEARCH QUERY AND NOTHING ELSE".to_string();

let messages = vec![
ChatMessage::System {
content: ChatMessageContent::Text(
"Please describe the image and turn the description into a search query. DO NOT INCLUDE ANY OTHER CONTEXT OR INFORMATION. JUST OUTPUT THE SEARCH QUERY AND NOTHING ELSE"
.to_string(),
),
content: ChatMessageContent::Text(prompt.unwrap_or(default_system_prompt)),
name: None,
},
ChatMessage::User {
Expand Down
5 changes: 4 additions & 1 deletion server/src/operators/search_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,10 @@ pub async fn parse_query(
let stop_words = get_stop_words();
let query = match query {
SearchModalities::Text(query) => query,
SearchModalities::Image { image_url } => get_text_from_image(image_url, dataset).await?,
SearchModalities::Image {
image_url,
llm_prompt,
} => get_text_from_image(image_url, llm_prompt, dataset).await?,
};

let query = match remove_stop_words {
Expand Down

0 comments on commit 5531e2c

Please sign in to comment.