Bridge
A Bridge acts as an intermediary between a Task and a ModelWrapper. It is responsible for translating task-specific requirements (like prompts and schemas) into a format the model wrapper understands, and conversely, integrating model outputs back into the document's results.
Bases: ABC
Bridge base class.
Source code in sieves/tasks/predictive/bridges.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
inference_mode
abstractmethod
property
Return inference mode.
Returns:
| Type | Description |
|---|---|
ModelWrapperInferenceMode
|
Inference mode. |
prompt_signature
abstractmethod
property
Create output signature.
E.g.: Signature in DSPy, Pydantic objects in outlines, JSON schema in jsonformers.
This is model type-specific.
Returns:
| Type | Description |
|---|---|
type[TaskPromptSignature] | TaskPromptSignature
|
Output signature object. This can be an instance (e.g. a regex string) or a class (e.g. a Pydantic class). |
prompt_template
property
Return prompt template.
Chains _prompt_instructions, _prompt_example_template and _prompt_conclusion.
Note: different model have different expectations as to how a prompt should look like. E.g. outlines supports the Jinja 2 templating format for insertion of values and few-shot examples, whereas DSPy integrates these things in a different value in the workflow and hence expects the prompt not to include these things. Mind model-specific expectations when creating a prompt template.
Returns:
| Type | Description |
|---|---|
str
|
Prompt template as string. None if not used by model wrapper. |
__init__(task_id, prompt_instructions, overwrite, model_settings)
Initialize new bridge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task ID. |
required |
prompt_instructions
|
str | None
|
Custom prompt instructions. If None, default instructions are used. |
required |
overwrite
|
bool
|
Whether to overwrite text with produced text. Considered only by bridges for tasks producing fluent text - like translation, summarization, PII masking, etc. |
required |
model_settings
|
ModelSettings
|
Model settings including inference_mode. |
required |
Source code in sieves/tasks/predictive/bridges.py
16 17 18 19 20 21 22 23 24 25 26 27 28 | |
consolidate(results, docs_offsets)
abstractmethod
Consolidate results for document chunks into document results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Sequence[TaskResult]
|
Results per document chunk. |
required |
docs_offsets
|
list[tuple[int, int]]
|
Chunk offsets per document. Chunks per document can be obtained with |
required |
Returns:
| Type | Description |
|---|---|
Sequence[TaskResult]
|
Results per document as a sequence. |
Source code in sieves/tasks/predictive/bridges.py
124 125 126 127 128 129 130 131 132 | |
extract(docs)
Extract all values from doc instances that are to be injected into the prompts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docs
|
Sequence[Doc]
|
Docs to extract values from. |
required |
Returns:
| Type | Description |
|---|---|
Sequence[dict[str, Any]]
|
All values from doc instances that are to be injected into the prompts as a sequence. |
Source code in sieves/tasks/predictive/bridges.py
107 108 109 110 111 112 113 | |
integrate(results, docs)
abstractmethod
Integrate results into Doc instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Sequence[TaskResult]
|
Results from prompt executable. |
required |
docs
|
list[Doc]
|
Doc instances to update. |
required |
Returns:
| Type | Description |
|---|---|
list[Doc]
|
Updated doc instances as a list. |
Source code in sieves/tasks/predictive/bridges.py
115 116 117 118 119 120 121 122 | |