You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dynamic parsing enables flexible handling of structured outputs from LLM responses. This feature is particularly useful when reasoning models are used (e.g. DeepSeek R1).
8
+
9
+
## Overview
10
+
11
+
The dynamic parsing feature can be enabled using the `set_dynamic()` method on your LLM instance. When enabled, the LLM will:
12
+
13
+
1. Attempt to parse and validate JSON responses
14
+
2. Include structured thinking process in the output
15
+
3. Handle complex response models dynamically
16
+
17
+
## Usage
18
+
19
+
### Here's how to enable dynamic parsing:
20
+
21
+
```python
22
+
from extract_thinker importLLM
23
+
24
+
# Initialize LLM
25
+
llm = LLM("ollama/deepseek-r1:1.5b")
26
+
27
+
# Enable dynamic parsing
28
+
llm.set_dynamic(True)
29
+
```
30
+
31
+
### Uses this template structure:
32
+
```python
33
+
Please provide your thinking process within <think> tags, followed by your JSON output.
34
+
35
+
JSON structure:
36
+
{your_structure}
37
+
38
+
OUTPUT example:
39
+
<think>
40
+
Your step-by-step reasoning and analysis goes here...
41
+
</think>
42
+
43
+
##JSON OUTPUT
44
+
{
45
+
...
46
+
}
47
+
```
48
+
49
+
## Example: Invoice Extraction
50
+
51
+
Here's a complete example of using dynamic parsing for invoice extraction:
52
+
53
+
```python
54
+
from extract_thinker importLLM, Extractor
55
+
from extract_thinker.document_loader import DocumentLoaderPyPdf
This component is currently under active development. The API might change in future releases.
5
-
6
3
The LLM component in ExtractThinker acts as a bridge between your document processing pipeline and various Language Model providers. It handles request formatting, response parsing, and provider-specific optimizations.
The default stack combines instructor for structured outputs and litellm for model interfacing. It leverages [LiteLLM's unified API](https://docs.litellm.ai/docs/#litellm-python-sdk) for consistent model access:
44
+
45
+
```python
46
+
llm = LLM("gpt-4o", backend=LLMEngine.DEFAULT)
47
+
```
48
+
49
+
### Pydantic AI Stack (Beta)
50
+
An alternative all-in-one solution for model integration powered by [Pydantic AI](https://ai.pydantic.dev/):
0 commit comments