Skip to content

Commit f5f5834

Browse files
committed
Improve AI Product detection
1 parent 52544cc commit f5f5834

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

engine/src/modules/intelligence/gemini/actor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ impl Actor for GeminiActor {
2121
) -> Result<CalculatedResponse, anyhow::Error> {
2222
let body = GeminiStructuredContentRequest::from_conversation(conversation, strategy);
2323

24+
tracing::info!("body: {}", serde_json::to_string(&body).unwrap());
25+
2426
let client = reqwest::Client::new();
2527
let api_key = intelligence.gemini.as_ref().unwrap().api_key.as_str();
2628

engine/src/modules/intelligence/gemini/structured.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl GeminiStructuredContentRequest {
5151
true => Some(GeminiStructuredContentRequestToolConfig {
5252
function_calling_config: GeminiStructuredContentRequestToolConfigFunctionCallingConfig {
5353
allowed_function_names: strategy.allowed_functions.clone(),
54-
mode: serde_json::to_string(strategy.function_mode.as_ref().unwrap_or(&FunctionMode::Auto)).unwrap()
54+
mode: strategy.function_mode.as_ref().unwrap_or(&FunctionMode::Auto).to_string()
5555
}
5656
}),
5757
false => None,

engine/src/modules/intelligence/structured/strategy.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::modules::intelligence::actions::{
33
SmartAction, SmartActionType,
44
};
55
use serde::{Deserialize, Serialize};
6+
use serde_with::SerializeDisplay;
67

78
use super::Conversation;
89

@@ -13,6 +14,8 @@ pub enum Strategy {
1314
UPCForcedSearch,
1415
/// 8 rounds max
1516
Basic,
17+
/// 8 rounds max
18+
ProductOptimized,
1619
}
1720

1821
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -25,6 +28,16 @@ pub enum FunctionMode {
2528
None,
2629
}
2730

31+
impl ToString for FunctionMode {
32+
fn to_string(&self) -> String {
33+
match self {
34+
FunctionMode::Any => "ANY".to_string(),
35+
FunctionMode::Auto => "AUTO".to_string(),
36+
FunctionMode::None => "NONE".to_string(),
37+
}
38+
}
39+
}
40+
2841
#[derive(Debug, Clone)]
2942
pub struct StrategyConfig {
3043
pub max_rounds: u8,
@@ -61,6 +74,30 @@ impl Strategy {
6174
_ => FunctionMode::None,
6275
}),
6376
}),
77+
Strategy::ProductOptimized => Ok(StrategyConfig {
78+
max_rounds: 8,
79+
tasks: vec![
80+
SmartActionType::SearchKagi,
81+
SmartActionType::SearchUPCEAN,
82+
SmartActionType::ExtractLDJSON,
83+
],
84+
allowed_functions: None,
85+
// allowed_functions: match conversation.index {
86+
// // less then 5
87+
// 0..8 => Some(vec![
88+
// SearchKagiTask::name(),
89+
// ExtractLDJsonTask::name(),
90+
// SearchUPCEANDatabaseTask::name(),
91+
// ]),
92+
// _ => None,
93+
// },
94+
function_mode: Some(match conversation.index {
95+
0..3 => FunctionMode::Any,
96+
3..7 => FunctionMode::Auto,
97+
_ => FunctionMode::None,
98+
}),
99+
// function_mode: Some(FunctionMode::Auto),
100+
}),
64101
Strategy::Basic => Ok(StrategyConfig {
65102
max_rounds: 8,
66103
tasks: vec![

engine/src/modules/intelligence/tasks/ingress_product.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl IngressProductTask {
2828
let actor = GeminiActor;
2929

3030
let conversation = Conversation {
31-
strategy: Strategy::Basic,
31+
strategy: Strategy::ProductOptimized,
3232
index: 0,
3333
messages: vec![ConversationMessage {
3434
role: "user".to_string(),

0 commit comments

Comments
 (0)