Skip to content

Commit 20e1524

Browse files
committed
✨ add inference options
1 parent 13834be commit 20e1524

File tree

7 files changed

+58
-12
lines changed

7 files changed

+58
-12
lines changed

mindee/input/inference_parameters.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ class InferenceParameters:
1111
model_id: str
1212
"""ID of the model, required."""
1313
rag: bool = False
14-
"""If set to `True`, will enable Retrieval-Augmented Generation."""
14+
"""Use Retrieval-Augmented Generation during inference."""
15+
raw_text: bool = False
16+
"""Extract the entire text from the document as strings, and fill the ``raw_text`` attribute."""
17+
polygon: bool = False
18+
"""Calculate bounding box polygons for values, and fill the ``locations`` attribute of fields"""
19+
confidence: bool = False
20+
"""
21+
Calculate confidence scores for values, and fill the ``confidence`` attribute of fields.
22+
Useful for automation.
23+
"""
1524
alias: Optional[str] = None
1625
"""Use an alias to link the file to your own DB. If empty, no alias will be used."""
1726
webhook_ids: Optional[List[str]] = None

mindee/mindee_http/mindee_api_v2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def req_post_inference_enqueue(
8484

8585
if params.rag:
8686
data["rag"] = "true"
87+
if params.raw_text:
88+
data["raw_text"] = "true"
89+
if params.confidence:
90+
data["confidence"] = "true"
91+
if params.polygon:
92+
data["polygon"] = "true"
8793
if params.webhook_ids and len(params.webhook_ids) > 0:
8894
data["webhook_ids"] = ",".join(params.webhook_ids)
8995
if params.alias and len(params.alias):

mindee/parsing/v2/inference.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from typing import Optional
2-
31
from mindee.parsing.common.string_dict import StringDict
2+
from mindee.parsing.v2.inference_active_options import ActiveOptions
43
from mindee.parsing.v2.inference_file import InferenceFile
54
from mindee.parsing.v2.inference_model import InferenceModel
65
from mindee.parsing.v2.inference_result import InferenceResult
@@ -9,25 +8,29 @@
98
class Inference:
109
"""Inference object for a V2 API return."""
1110

11+
id: str
12+
"""ID of the inference."""
1213
model: InferenceModel
1314
"""Model info for the inference."""
1415
file: InferenceFile
1516
"""File info for the inference."""
1617
result: InferenceResult
1718
"""Result of the inference."""
18-
id: Optional[str]
19-
"""ID of the inference."""
19+
active_options: ActiveOptions
20+
"""Active options for the inference."""
2021

2122
def __init__(self, raw_response: StringDict):
23+
self.id = raw_response["id"]
2224
self.model = InferenceModel(raw_response["model"])
2325
self.file = InferenceFile(raw_response["file"])
2426
self.result = InferenceResult(raw_response["result"])
25-
self.id = raw_response["id"] if "id" in raw_response else None
27+
self.active_options = ActiveOptions(raw_response["active_options"])
2628

2729
def __str__(self) -> str:
2830
return (
29-
f"Inference\n#########\n"
30-
f"{self.model}\n\n"
31-
f"{self.file}"
32-
f"{self.result}\n"
31+
f"Inference\n#########"
32+
f"\n{self.model}"
33+
f"\n\n{self.file}"
34+
f"\n\n{self.active_options}"
35+
f"\n\n{self.result}\n"
3336
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from mindee.parsing.common.string_dict import StringDict
2+
3+
4+
class ActiveOptions:
5+
"""Active options for the inference."""
6+
7+
raw_text: bool
8+
polygon: bool
9+
confidence: bool
10+
rag: bool
11+
12+
def __init__(self, raw_response: StringDict):
13+
self.raw_text = raw_response["raw_text"]
14+
self.polygon = raw_response["polygon"]
15+
self.confidence = raw_response["confidence"]
16+
self.rag = raw_response["rag"]
17+
18+
def __str__(self) -> str:
19+
return (
20+
f"Active Options\n=============="
21+
f"\n:Raw Text: {self.raw_text}"
22+
f"\n:Polygon: {self.polygon}"
23+
f"\n:Confidence: {self.confidence}"
24+
f"\n:RAG: {self.rag}"
25+
)

mindee/parsing/v2/inference_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ def __init__(self, raw_response: StringDict) -> None:
1919
self.raw_text = RawText(raw_response["raw_text"])
2020

2121
def __str__(self) -> str:
22-
out_str = f"\n\nFields\n======{self.fields}"
22+
out_str = f"Fields\n======{self.fields}"
2323
return out_str

mindee/parsing/v2/raw_text.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ class RawText:
1212

1313
def __init__(self, raw_response: StringDict):
1414
self.pages = [RawTextPage(page) for page in raw_response.get("pages", [])]
15+
16+
def __str__(self) -> str:
17+
return "\n\n".join([page.content for page in self.pages])

0 commit comments

Comments
 (0)