async_openai/types/responses/
sdk.rs1use crate::types::responses::{OutputItem, OutputMessageContent, Response};
2
3impl Response {
4 pub fn output_text(&self) -> Option<String> {
7 let output = self
8 .output
9 .iter()
10 .filter_map(|item| match item {
11 OutputItem::Message(msg) => Some(
12 msg.content
13 .iter()
14 .filter_map(|content| match content {
15 OutputMessageContent::OutputText(ot) => Some(ot.text.clone()),
16 _ => None,
17 })
18 .collect::<Vec<String>>(),
19 ),
20 _ => None,
21 })
22 .flatten()
23 .collect::<Vec<String>>()
24 .join("");
25 if output.is_empty() {
26 None
27 } else {
28 Some(output)
29 }
30 }
31}