Skip to main content

synaptic_parsers/
str_parser.rs

1use async_trait::async_trait;
2use synaptic_core::{Message, RunnableConfig, SynapticError};
3use synaptic_runnables::Runnable;
4
5use crate::FormatInstructions;
6
7/// Extracts the text content from a Message.
8pub struct StrOutputParser;
9
10impl FormatInstructions for StrOutputParser {
11    fn get_format_instructions(&self) -> String {
12        String::new()
13    }
14}
15
16#[async_trait]
17impl Runnable<Message, String> for StrOutputParser {
18    async fn invoke(
19        &self,
20        input: Message,
21        _config: &RunnableConfig,
22    ) -> Result<String, SynapticError> {
23        Ok(input.content().to_string())
24    }
25}