pub struct CommaSeparatedListOutputParser;Expand description
逗号分隔列表输出解析器
将 LLM 输出的逗号分隔文本解析为字符串列表。 支持中文逗号(,)和英文逗号(,)。 自动去除每个项目的空白字符和空项目。
相当于 Python LangChain 的 CommaSeparatedListOutputParser。
§示例
ⓘ
use langchainrust::output_parsers::CommaSeparatedListOutputParser;
let parser = CommaSeparatedListOutputParser::new();
let result = parser.parse("apple, banana, cherry").await?;
assert_eq!(result, vec!["apple", "banana", "cherry"]);Implementations§
Trait Implementations§
Source§impl BaseOutputParser<Vec<String>> for CommaSeparatedListOutputParser
impl BaseOutputParser<Vec<String>> for CommaSeparatedListOutputParser
Source§fn parse<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = OutputParserResult<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn parse<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = OutputParserResult<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
将原始 LLM 输出文本解析为目标类型
Source§fn get_format_instructions(&self) -> String
fn get_format_instructions(&self) -> String
获取格式指令(用于提示 LLM 按指定格式输出)
Source§fn parse_with_retry<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
_max_retries: usize,
) -> Pin<Box<dyn Future<Output = OutputParserResult<Output>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn parse_with_retry<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
_max_retries: usize,
) -> Pin<Box<dyn Future<Output = OutputParserResult<Output>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
带重试的解析(默认实现:不重试)
Source§impl Runnable<String, Vec<String>> for CommaSeparatedListOutputParser
impl Runnable<String, Vec<String>> for CommaSeparatedListOutputParser
Source§type Error = OutputParserError
type Error = OutputParserError
Error type.
Source§fn invoke<'life0, 'async_trait>(
&'life0 self,
input: String,
_config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: String,
_config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<String>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Transforms single input to output. Read more
Source§fn stream<'life0, 'async_trait>(
&'life0 self,
input: String,
_config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Vec<String>, Self::Error>> + Send>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream<'life0, 'async_trait>(
&'life0 self,
input: String,
_config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<Vec<String>, Self::Error>> + Send>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Streaming output - for real-time responses (LLM, etc). Read more
Source§fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Input>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Output>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<Input>,
config: Option<RunnableConfig>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Output>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Batch processing - transforms multiple inputs to outputs. Read more
Auto Trait Implementations§
impl Freeze for CommaSeparatedListOutputParser
impl RefUnwindSafe for CommaSeparatedListOutputParser
impl Send for CommaSeparatedListOutputParser
impl Sync for CommaSeparatedListOutputParser
impl Unpin for CommaSeparatedListOutputParser
impl UnsafeUnpin for CommaSeparatedListOutputParser
impl UnwindSafe for CommaSeparatedListOutputParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more