Skip to content

Commit c94e367

Browse files
committed
Update handle_whole_doc_detection, add text_chat_detectors_with_tools test for chat completions streaming, impl FromIterator for DetectorParams
Signed-off-by: declark1 <[email protected]>
1 parent 1a10d15 commit c94e367

File tree

6 files changed

+417
-13
lines changed

6 files changed

+417
-13
lines changed

src/models.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ impl std::ops::DerefMut for DetectorParams {
7777
}
7878
}
7979

80+
impl<K, V> FromIterator<(K, V)> for DetectorParams
81+
where
82+
K: Into<String>,
83+
V: Into<serde_json::Value>,
84+
{
85+
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
86+
let map: BTreeMap<String, serde_json::Value> = iter
87+
.into_iter()
88+
.map(|(k, v)| (k.into(), v.into()))
89+
.collect();
90+
Self(map)
91+
}
92+
}
93+
8094
/// User request to orchestrator
8195
#[derive(Clone, Debug, Serialize, Deserialize)]
8296
#[serde(deny_unknown_fields)]

src/orchestrator/handlers/chat_completions_detection/streaming.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ async fn handle_whole_doc_detection(
463463
let mut warnings = Vec::new();
464464

465465
// Create vec of choice_index->message
466-
// NOTE: we create a message for text chat detectors
466+
// NOTE: we build a message from chat completion chunks as it is required for text chat detectors.
467+
// Text contents detectors only require the content text.
467468
let choices = completion_state
468469
.completions
469470
.iter()
@@ -472,9 +473,14 @@ async fn handle_whole_doc_detection(
472473
let chunks = entry.values().cloned().collect::<Vec<_>>();
473474
let tool_calls = merge_tool_calls(&chunks);
474475
let content_text = merge_content_text(&chunks);
476+
let content = if content_text.is_empty() {
477+
None
478+
} else {
479+
Some(Content::Text(content_text))
480+
};
475481
let message = Message {
476482
role: Role::Assistant,
477-
content: Some(Content::Text(content_text)),
483+
content,
478484
tool_calls,
479485
..Default::default()
480486
};

0 commit comments

Comments
 (0)