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
Copy file name to clipboardExpand all lines: .cursor/rules/pytest.mdc
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,8 @@ These rules apply when writing unit tests.
17
17
- More precisely, for `pipelex` and `pipelex.cogt` the async tests are placed inside subdirectories named `cogt_asynch` and `pipelex_asynch`
18
18
- Fixtures are defined in conftest.py modules at different levels of the hierarchy, their scope is handled by pytest
19
19
- Test data is placed inside test_data.py at different levels of the hierarchy, they must be imported with package paths from the root like `tests.pipelex.test_data`. Their content is all constants, regrouped inside classes to keep things tidy.
20
+
- Always put test inside Test classes.
21
+
- The pipelex pipelines should be stored in `tests/test_pipelines` as well as the related structured Output classes that inherit from `StructuredContent`
This document outlines our test-driven development (TDD) process and the tools available for testing.
9
+
10
+
## TDD Cycle
11
+
12
+
1. **Write a Test First**
13
+
[pytest.mdc](mdc:.cursor/rules/pytest.mdc)
14
+
15
+
2. **Write the Code**
16
+
- Implement the minimum amount of code needed to pass the test
17
+
- Follow the project's coding standards
18
+
- Keep it simple - don't write more than needed
19
+
20
+
3. **Run Linting and Type Checking**
21
+
[standards.mdc](mdc:.cursor/rules/standards.mdc)
22
+
23
+
4. **Refactor if needed**
24
+
If the code needs refactoring, with the best practices [best_practices.mdc](mdc:.cursor/rules/best_practices.mdc)
25
+
26
+
5. **Validate tests**
27
+
28
+
Remember: The key to TDD is writing the test first and letting it drive your implementation. Always run the full test suite and quality checks before considering a feature complete.
Copy file name to clipboardExpand all lines: docs/pages/build-reliable-ai-workflows-with-pipelex/pipe-operators/PipeLLM.md
+95-5Lines changed: 95 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,96 @@ For structured data output, `PipeLLM` employs two main strategies:
13
13
a. First, the LLM generates a free-form text based on the initial prompt.
14
14
b. Second, another LLM call is made with a specific prompt designed to extract and structure the information from the generated text into the target Pydantic model.
15
15
16
+
## Working with Images (Vision Language Models)
17
+
18
+
`PipeLLM` supports Vision Language Models (VLMs) that can process both text and images. To use images in your prompts:
19
+
20
+
### Basic Image Input
21
+
22
+
Images must be declared in the `inputs` section of your pipe definition. The image will be automatically passed to the VLM along with your text prompt.
23
+
24
+
```toml
25
+
[pipe.describe_image]
26
+
PipeLLM = "Describe an image"
27
+
inputs = { image = "Image" }
28
+
output = "VisualDescription"
29
+
prompt_template = """
30
+
Describe the provided image in great detail.
31
+
"""
32
+
```
33
+
34
+
**Important**: Do NOT reference image variables in your prompt template using `@image` or `$image`. Images are automatically passed to vision-enabled LLMs and should not be treated as text variables.
35
+
36
+
**Flexible Image Inputs**
37
+
38
+
You can use any concept that refines `Image` as an input, and choose descriptive variable names that fit your use case:
39
+
40
+
```toml
41
+
[pipe.analyze_wedding]
42
+
PipeLLM = "Analyze wedding photo"
43
+
inputs = { wedding_photo = "images.Photo" }
44
+
output = "PhotoAnalysis"
45
+
prompt_template = """
46
+
Analyze this wedding photo and describe the key moments captured.
47
+
"""
48
+
```
49
+
50
+
### Images as Sub-attributes of Structured Content
51
+
52
+
When working with structured content that contains image fields (like `PageContent` which has a `page_view` field), you need to specify the full path to the image attribute in the `inputs` section:
53
+
54
+
```toml
55
+
[pipe.analyze_page_view]
56
+
PipeLLM = "Analyze the visual layout of a page"
57
+
inputs = { "page_content.page_view" = "Image" }
58
+
output = "LayoutAnalysis"
59
+
prompt_template = """
60
+
Analyze the visual layout and design elements of this page.
61
+
Focus on typography, spacing, and overall composition.
62
+
"""
63
+
```
64
+
65
+
In this example:
66
+
-`page_content` is the input variable containing a `PageContent` object
67
+
-`page_view` is the `ImageContent` field within the `PageContent` structure
68
+
- The dot notation `page_content.page_view` tells Pipelex to extract the image from that specific field
69
+
70
+
### Multiple Images
71
+
72
+
You can include multiple images in a single prompt by listing them in the inputs:
73
+
74
+
```toml
75
+
[pipe.compare_images]
76
+
PipeLLM = "Compare two images"
77
+
inputs = {
78
+
first_image = "Image",
79
+
second_image = "Image"
80
+
}
81
+
output = "ImageComparison"
82
+
prompt_template = """
83
+
Compare these two images and describe their similarities and differences.
84
+
"""
85
+
```
86
+
87
+
### Combining Text and Image Inputs
88
+
89
+
You can mix any stuff and image inputs in the same pipe:
90
+
91
+
```toml
92
+
[pipe.analyze_document_with_context]
93
+
PipeLLM = "Analyze a document page with additional context"
94
+
inputs = {
95
+
context = "Text",
96
+
document.page_view = "Image"
97
+
}
98
+
output = "DocumentAnalysis"
99
+
prompt_template = """
100
+
Given this context: $context
101
+
102
+
Analyze the document page shown in the image and explain how it relates to the provided context.
103
+
"""
104
+
```
105
+
16
106
## Configuration
17
107
18
108
`PipeLLM` is configured in your pipeline's `.toml` file.
@@ -22,17 +112,18 @@ For structured data output, `PipeLLM` employs two main strategies:
|`PipeLLM`| string | A descriptive name for the LLM operation. | Yes |
25
-
|`inputs`| dictionary | The input concept(s) for the LLM operation, as a dictionary mapping input names to concept codes. | Yes |
115
+
|`inputs`| dictionary | The input concept(s) for the LLM operation, as a dictionary mapping input names to concept codes. For images within structured content, use dot notation (e.g., `"page.image"`). | Yes |
26
116
|`output`| string | The output concept produced by the LLM operation. | Yes |
27
117
|`llm`| string or table | Specifies the LLM preset(s) to use. Can be a single preset or a table mapping different presets for different generation modes (e.g., `main`, `object_direct`). | No |
28
118
|`system_prompt`| string | A system-level prompt to guide the LLM's behavior (e.g., "You are a helpful assistant"). Can be inline text or a reference to a template file (`"file:path/to/prompt.md"`). | No |
29
119
|`prompt`| string | A simple, static user prompt. Use this when you don't need to inject any variables. | No |
30
-
|`prompt_template`| string | A template for the user prompt. Use `$` for inline variables (e.g., `$topic`) and `@` to insert the content of an entire input (e.g., `@text_to_summarize`). | No |
31
-
|`images`| list of strings |For Vision Language Models (VLMs), specifies which input variables are images. | No |
120
+
|`prompt_template`| string | A template for the user prompt. Use `$` for inline variables (e.g., `$topic`) and `@` to insert the content of an entire input (e.g., `@text_to_summarize`). **Note**: Do not use `@` or `$` for image variables. | No |
121
+
|`images`| list of strings |**Deprecated**: Use the `inputs` section to declare image inputs instead. | No |
32
122
|`structuring_method`| string | The method for generating structured output. Can be `direct` or `preliminary_text`. Defaults to the global configuration. | No |
33
123
|`prompt_template_to_structure`| string | The prompt template for the second step in `preliminary_text` mode. | No |
34
124
|`output_multiplicity`| string or integer | Defines the number of outputs. Use `"list"` for a variable-length list, or an integer (e.g., `3`) for a fixed-size list. | No |
35
125
126
+
## Examples
36
127
37
128
### Simple Text Generation Example
38
129
@@ -75,7 +166,6 @@ This pipe takes an image of a table and uses a VLM to extract the content as an
75
166
PipeLLM = "Extract table data from an image"
76
167
inputs = { image = "TableScreenshot" }
77
168
output = "TableData"
78
-
images = ["image"]
79
169
prompt_template = """
80
170
Extract the table data from this image and format it as a structured table.
81
171
"""
@@ -105,4 +195,4 @@ Analyze this expense report and extract the following information:
105
195
"""
106
196
```
107
197
108
-
In this example, `Pipelex` will instruct the LLM to return a list of objects that conform to the `Expense` structure.
198
+
In this example, `Pipelex` will instruct the LLM to return a list of objects that conform to the `Expense` structure.
0 commit comments