mirror of
https://github.com/vegu-ai/talemate.git
synced 2026-09-02 20:20:40 +02:00
294 lines
9.7 KiB
Markdown
294 lines
9.7 KiB
Markdown
|
|
# Response Parsing Nodes
|
||
|
|
|
||
|
|
Extract structured data from LLM responses. A **Response Spec** describes the expected format; extractors pull out anchored sections, code blocks, lists or regex matches from the raw response text.
|
||
|
|
|
||
|
|
<!-- glossary:generated - everything below this line is generated by `python -m talemate.game.engine.nodes.tools glossary --write` - do not edit -->
|
||
|
|
|
||
|
|
|
||
|
|
_9 nodes._
|
||
|
|
|
||
|
|
| Node | Registry path |
|
||
|
|
| --- | --- |
|
||
|
|
| [After Anchor Extractor](#after-anchor-extractor) | `response/AfterAnchorExtractor` |
|
||
|
|
| [Anchor Extractor](#anchor-extractor) | `response/AnchorExtractor` |
|
||
|
|
| [AsIs Extractor](#asis-extractor) | `response/AsIsExtractor` |
|
||
|
|
| [Code Block Extractor](#code-block-extractor) | `response/CodeBlockExtractor` |
|
||
|
|
| [Complex Anchor Extractor](#complex-anchor-extractor) | `response/ComplexAnchorExtractor` |
|
||
|
|
| [Complex Code Block Extractor](#complex-code-block-extractor) | `response/ComplexCodeBlockExtractor` |
|
||
|
|
| [Regex Extractor](#regex-extractor) | `response/RegexExtractor` |
|
||
|
|
| [Response Spec](#response-spec) | `response/ResponseSpec` |
|
||
|
|
| [Strip Prefix Extractor](#strip-prefix-extractor) | `response/StripPrefixExtractor` |
|
||
|
|
|
||
|
|
## After Anchor Extractor
|
||
|
|
|
||
|
|
`response/AfterAnchorExtractor`
|
||
|
|
|
||
|
|
Creates an AfterAnchorExtractor that extracts everything after a start marker.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | (optional) Optional override for name property |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | The extractor name (pass-through) |
|
||
|
|
| `value` | `response/extractor` | The AfterAnchorExtractor instance |
|
||
|
|
| `spec` | `response/spec` | A ResponseSpec containing just this extractor |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `name` | `str` | `""` | Extractor name (key for dict collector) |
|
||
|
|
| `start` | `str` | `""` | Start marker to search for |
|
||
|
|
| `stop_at` | `str` | `""` | Optional end marker (empty = no stop) |
|
||
|
|
| `fallback_to_full` | `bool` | `False` | Return full response if start marker not found |
|
||
|
|
| `trim` | `bool` | `True` | Trim whitespace from result |
|
||
|
|
|
||
|
|
## Anchor Extractor
|
||
|
|
|
||
|
|
`response/AnchorExtractor`
|
||
|
|
|
||
|
|
Creates an AnchorExtractor that extracts content between anchor tags.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | (optional) Optional override for name property |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | The extractor name (pass-through) |
|
||
|
|
| `value` | `response/extractor` | The AnchorExtractor instance |
|
||
|
|
| `spec` | `response/spec` | A ResponseSpec containing just this extractor |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `name` | `str` | `""` | Extractor name (key for dict collector) |
|
||
|
|
| `left` | `str` | `""` | Left anchor tag (e.g., <MESSAGE>) |
|
||
|
|
| `right` | `str` | `""` | Right anchor tag (e.g., </MESSAGE>) |
|
||
|
|
| `fallback_to_full` | `bool` | `False` | Return full response if anchors not found |
|
||
|
|
| `trim` | `bool` | `True` | Trim whitespace from result |
|
||
|
|
|
||
|
|
## AsIs Extractor
|
||
|
|
|
||
|
|
`response/AsIsExtractor`
|
||
|
|
|
||
|
|
Creates an AsIsExtractor that returns the entire response as-is.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | (optional) Optional override for name property |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | The extractor name (pass-through) |
|
||
|
|
| `value` | `response/extractor` | The AsIsExtractor instance |
|
||
|
|
| `spec` | `response/spec` | A ResponseSpec containing just this extractor |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `name` | `str` | `""` | Extractor name (key for dict collector) |
|
||
|
|
| `trim` | `bool` | `True` | Trim whitespace from result |
|
||
|
|
|
||
|
|
## Code Block Extractor
|
||
|
|
|
||
|
|
`response/CodeBlockExtractor`
|
||
|
|
|
||
|
|
Creates a CodeBlockExtractor that extracts code blocks from tagged sections.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | (optional) Optional override for name property |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | The extractor name (pass-through) |
|
||
|
|
| `value` | `response/extractor` | The CodeBlockExtractor instance |
|
||
|
|
| `spec` | `response/spec` | A ResponseSpec containing just this extractor |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `name` | `str` | `""` | Extractor name (key for dict collector) |
|
||
|
|
| `left` | `str` | `""` | Left anchor tag (e.g., <ACTIONS>) |
|
||
|
|
| `right` | `str` | `""` | Right anchor tag (e.g., </ACTIONS>) |
|
||
|
|
| `validate_structured` | `bool` | `True` | Validate content as JSON/YAML for no-fence fallback |
|
||
|
|
| `fallback_to_full` | `bool` | `False` | Return full response if anchors not found |
|
||
|
|
| `trim` | `bool` | `True` | Trim whitespace from result |
|
||
|
|
|
||
|
|
## Complex Anchor Extractor
|
||
|
|
|
||
|
|
`response/ComplexAnchorExtractor`
|
||
|
|
|
||
|
|
Creates a ComplexAnchorExtractor with nesting awareness.
|
||
|
|
|
||
|
|
Tracks multiple tags and only extracts target blocks when at root level.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | (optional) Optional override for name property |
|
||
|
|
| `tracked_tags` | `list` | (optional) Optional override for tracked_tags property |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | The extractor name (pass-through) |
|
||
|
|
| `value` | `response/extractor` | The ComplexAnchorExtractor instance |
|
||
|
|
| `spec` | `response/spec` | A ResponseSpec containing just this extractor |
|
||
|
|
| `tracked_tags` | `list` | The tracked tags list (pass-through) |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `name` | `str` | `""` | Extractor name (key for dict collector) |
|
||
|
|
| `left` | `str` | `""` | Left anchor tag (e.g., <MESSAGE>) |
|
||
|
|
| `right` | `str` | `""` | Right anchor tag (e.g., </MESSAGE>) |
|
||
|
|
| `tracked_tags` | `list` | `[]` | Tags to track for nesting awareness |
|
||
|
|
| `fallback_to_full` | `bool` | `False` | Return full response if anchors not found |
|
||
|
|
| `trim` | `bool` | `True` | Trim whitespace from result |
|
||
|
|
|
||
|
|
## Complex Code Block Extractor
|
||
|
|
|
||
|
|
`response/ComplexCodeBlockExtractor`
|
||
|
|
|
||
|
|
Creates a ComplexCodeBlockExtractor with nesting awareness for code blocks.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | (optional) Optional override for name property |
|
||
|
|
| `tracked_tags` | `list` | (optional) Optional override for tracked_tags property |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | The extractor name (pass-through) |
|
||
|
|
| `value` | `response/extractor` | The ComplexCodeBlockExtractor instance |
|
||
|
|
| `spec` | `response/spec` | A ResponseSpec containing just this extractor |
|
||
|
|
| `tracked_tags` | `list` | The tracked tags list (pass-through) |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `name` | `str` | `""` | Extractor name (key for dict collector) |
|
||
|
|
| `left` | `str` | `""` | Left anchor tag (e.g., <ACTIONS>) |
|
||
|
|
| `right` | `str` | `""` | Right anchor tag (e.g., </ACTIONS>) |
|
||
|
|
| `tracked_tags` | `list` | `[]` | Tags to track for nesting awareness |
|
||
|
|
| `validate_structured` | `bool` | `True` | Validate content as JSON/YAML for no-fence fallback |
|
||
|
|
| `fallback_to_full` | `bool` | `False` | Return full response if anchors not found |
|
||
|
|
| `trim` | `bool` | `True` | Trim whitespace from result |
|
||
|
|
|
||
|
|
## Regex Extractor
|
||
|
|
|
||
|
|
`response/RegexExtractor`
|
||
|
|
|
||
|
|
Creates a RegexExtractor that extracts content using regex patterns.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | (optional) Optional override for name property |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | The extractor name (pass-through) |
|
||
|
|
| `value` | `response/extractor` | The RegexExtractor instance |
|
||
|
|
| `spec` | `response/spec` | A ResponseSpec containing just this extractor |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `name` | `str` | `""` | Extractor name (key for dict collector) |
|
||
|
|
| `pattern` | `str` | `""` | Regex pattern with capture group |
|
||
|
|
| `case_insensitive` | `bool` | `False` | Ignore case when matching |
|
||
|
|
| `group` | `int` | `1` | Capture group to extract |
|
||
|
|
| `all_matches` | `bool` | `False` | Return list of all matches |
|
||
|
|
| `trim` | `bool` | `True` | Trim whitespace from result |
|
||
|
|
|
||
|
|
## Response Spec
|
||
|
|
|
||
|
|
`response/ResponseSpec`
|
||
|
|
|
||
|
|
Creates a ResponseSpec from a dictionary of extractors.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `extractors` | `dict` | Dictionary of name -> Extractor (from DictCollector) |
|
||
|
|
| `required` | `list` | (optional) Optional override for required property |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `spec` | `response/spec` | The ResponseSpec instance |
|
||
|
|
| `extractors` | `dict` | Pass-through of the extractors dict |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `required` | `list` | `[]` | List of required field names |
|
||
|
|
|
||
|
|
## Strip Prefix Extractor
|
||
|
|
|
||
|
|
`response/StripPrefixExtractor`
|
||
|
|
|
||
|
|
Creates a StripPrefixExtractor that strips patterns using regex substitution.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | (optional) Optional override for name property |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `name` | `str` | The extractor name (pass-through) |
|
||
|
|
| `value` | `response/extractor` | The StripPrefixExtractor instance |
|
||
|
|
| `spec` | `response/spec` | A ResponseSpec containing just this extractor |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `name` | `str` | `""` | Extractor name (key for dict collector) |
|
||
|
|
| `pattern` | `str` | `""` | Regex pattern to strip |
|
||
|
|
| `replacement` | `str` | `""` | Replacement string |
|
||
|
|
| `trim` | `bool` | `True` | Trim whitespace from result |
|