use gadk_genai::{Content, Part};
use crate::Event;
#[doc(hidden)]
pub fn content(ev: &Event) -> Option<&Content> {
ev.response.content.as_ref()
}
#[doc(hidden)]
pub fn is_prose_part(p: &Part) -> bool {
!p.text.is_empty()
&& !p.thought
&& p.function_call.is_none()
&& p.function_response.is_none()
&& p.executable_code.is_none()
&& p.code_execution_result.is_none()
&& p.file_data.is_none()
&& p.inline_data.is_none()
&& p.tool_call.is_none()
&& p.tool_response.is_none()
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod tests {
use super::*;
use gadk_genai::{Blob, FunctionCall};
use gadk_model::LlmResponse;
#[test]
fn content_is_the_response_content() {
let mut ev = Event::default();
assert!(content(&ev).is_none());
ev.response = LlmResponse {
content: Some(Content::from_text("hi", "user")),
..Default::default()
};
assert_eq!(content(&ev).unwrap().parts[0].text, "hi");
}
#[test]
fn is_prose_part_matches_go() {
assert!(is_prose_part(&Part::from_text("hello")));
assert!(!is_prose_part(&Part::default()), "empty text is not prose");
assert!(
!is_prose_part(&Part {
thought: true,
..Part::from_text("thinking")
}),
"a thought is not prose"
);
assert!(!is_prose_part(&Part {
function_call: Some(FunctionCall {
name: "f".into(),
..Default::default()
}),
..Part::from_text("text beside a call")
}));
assert!(!is_prose_part(&Part {
inline_data: Some(Blob::default()),
..Part::from_text("caption")
}));
}
}