Skip to content

Commit df73510

Browse files
harini-venkataramangaya3-zipstackhari-kuriakosejaseemjaskp
authored
[FEAT] Adapter for LLMWhisperer v2 (#110)
* Exception handling for Prompt Service * LLM Whisperer adapter v2 * Support for LLMWHisperer v2 adapter * Marked v1 as deprecated * Marked v1 as deprecated * Update json_schema.json Signed-off-by: Jaseem Jas <[email protected]> * Minor code standization changes * Refactor exception handling * Adding dev comments --------- Signed-off-by: Jaseem Jas <[email protected]> Co-authored-by: Gayathri <[email protected]> Co-authored-by: Hari John Kuriakose <[email protected]> Co-authored-by: Jaseem Jas <[email protected]>
1 parent a2436cf commit df73510

File tree

9 files changed

+792
-1
lines changed

9 files changed

+792
-1
lines changed

src/unstract/sdk/adapters/x2text/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ class X2TextConstants:
55
ENABLE_HIGHLIGHT = "enable_highlight"
66
EXTRACTED_TEXT = "extracted_text"
77
WHISPER_HASH = "whisper-hash"
8+
WHISPER_HASH_V2 = "whisper_hash"

src/unstract/sdk/adapters/x2text/llm_whisperer/src/static/json_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"title": "URL",
1919
"format": "uri",
2020
"default": "https://llmwhisperer-api.unstract.com",
21-
"description": "Provide the URL of the LLM Whisperer service."
21+
"description": "Provide the URL of the LLM Whisperer service. Please note that this version of LLM Whisperer is deprecated."
2222
},
2323
"unstract_key": {
2424
"type": "string",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Unstract LLM Whisperer v2 X2Text Adapter
2+
3+
## Env variables
4+
5+
The below env variables are resolved by LLM Whisperer adapter
6+
7+
| Variable | Description |
8+
| ---------------------------- | -------------------------------------------------------------------------------------------- |
9+
| `ADAPTER_LLMW_POLL_INTERVAL` | Time in seconds to wait before polling LLMWhisperer's status API. Defaults to 30s |
10+
| `ADAPTER_LLMW_MAX_POLLS` | Total number of times to poll the status API. Defaults to 30 |
11+
12+
13+
---
14+
id: llm_whisperer_apis_changelog
15+
---
16+
17+
# Changelog
18+
19+
## Version 2.0.0
20+
21+
:::warning
22+
This version of the API is not backward compatible with the previous version.
23+
:::
24+
25+
### API endpoint
26+
27+
- The base URL for the **V2** APIs is `https://llmwhisperer-api.unstract.com/api/v2`
28+
29+
### Global change in parameter naming
30+
31+
- All use of `whisper-hash` as a parameter has been replaced with `whisper_hash` for consistency.
32+
33+
### Whisper parameters
34+
35+
#### Added
36+
- `mode` (str, optional): The processing mode.
37+
- `mark_vertical_lines` (bool, optional): Whether to reproduce vertical lines in the document.
38+
- `mark_horizontal_lines` (bool, optional): Whether to reproduce horizontal lines in the document.
39+
- `line_splitter_strategy` (str, optional): The line splitter strategy to use. An advanced option for customizing the line splitting process.
40+
- `lang` (str, optional): The language of the document.
41+
- `tag` (str, optional): A tag to associate with the document. Used for auditing and tracking purposes.
42+
- `file_name` (str, optional): The name of the file being processed. Used for auditing and tracking purposes.
43+
- `use_webhook` (str, optional): The name of the webhook to call after the document is processed.
44+
- `webhook_metadata` (str, optional): Metadata to send to the webhook after the document is processed.
45+
46+
#### Removed
47+
- `timeout` (int, optional): The timeout for API requests. *There is no sync mode now. All requests are async.*
48+
- `force_text_processing` (bool, optional): Whether to force text processing. *This is feature is removed*
49+
- `ocr_provider` (str, optional): The OCR provider to use. *This is superseded by `mode`*
50+
- `processing_mode` (str, optional): The processing mode. *This is superseded by `mode`*
51+
- `store_metadata_for_highlighting` (bool, optional): Whether to store metadata for highlighting. *Feature is removed. Data still available and set back when retrieve is called*
52+
53+
54+
### New features
55+
56+
#### Webhooks
57+
58+
- Added support for webhooks. You can now register a webhook and use it to receive the processed document.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[build-system]
2+
requires = ["pdm-backend"]
3+
build-backend = "pdm.backend"
4+
5+
6+
[project]
7+
name = "unstract-llm_whisperer-x2text-v2"
8+
version = "0.0.1"
9+
description = "V2 of LLMWhisperer X2Text Adapter"
10+
authors = [
11+
{name = "Zipstack Inc.", email = "[email protected]"},
12+
]
13+
dependencies = [
14+
]
15+
requires-python = ">=3.9"
16+
readme = "README.md"
17+
classifiers = [
18+
"Programming Language :: Python"
19+
]
20+
license = {text = "MIT"}
21+
22+
[tool.pdm.build]
23+
includes = ["src"]
24+
package-dir = "src"
25+
# source-includes = ["tests"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .llm_whisperer_v2 import LLMWhispererV2
2+
3+
metadata = {
4+
"name": LLMWhispererV2.__name__,
5+
"version": "1.0.0",
6+
"adapter": LLMWhispererV2,
7+
"description": "LLMWhispererV2 X2Text adapter",
8+
"is_active": True,
9+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import os
2+
from enum import Enum
3+
4+
5+
class Modes(Enum):
6+
NATIVE_TEXT = "native_text"
7+
LOW_COST = "low_cost"
8+
HIGH_QUALITY = "high_quality"
9+
FORM = "form"
10+
11+
12+
class OutputModes(Enum):
13+
LAYOUT_PRESERVING = "layout_preserving"
14+
TEXT = "text"
15+
16+
17+
class HTTPMethod(Enum):
18+
GET = "GET"
19+
POST = "POST"
20+
21+
22+
class WhispererHeader:
23+
UNSTRACT_KEY = "unstract-key"
24+
25+
26+
class WhispererEndpoint:
27+
"""Endpoints available at LLMWhisperer service."""
28+
29+
TEST_CONNECTION = "test-connection"
30+
WHISPER = "whisper"
31+
STATUS = "whisper-status"
32+
RETRIEVE = "whisper-retrieve"
33+
34+
35+
class WhispererEnv:
36+
"""Env variables for LLM whisperer.
37+
38+
Can be used to alter behaviour at runtime.
39+
40+
Attributes:
41+
POLL_INTERVAL: Time in seconds to wait before polling
42+
LLMWhisperer's status API. Defaults to 30s
43+
MAX_POLLS: Total number of times to poll the status API.
44+
Set to -1 to poll indefinitely. Defaults to -1
45+
"""
46+
47+
POLL_INTERVAL = "ADAPTER_LLMW_POLL_INTERVAL"
48+
MAX_POLLS = "ADAPTER_LLMW_MAX_POLLS"
49+
50+
51+
class WhispererConfig:
52+
"""Dictionary keys used to configure LLMWhisperer service."""
53+
54+
URL = "url"
55+
MODE = "mode"
56+
OUTPUT_MODE = "output_mode"
57+
UNSTRACT_KEY = "unstract_key"
58+
MEDIAN_FILTER_SIZE = "median_filter_size"
59+
GAUSSIAN_BLUR_RADIUS = "gaussian_blur_radius"
60+
LINE_SPLITTER_TOLERANCE = "line_splitter_tolerance"
61+
LINE_SPLITTER_STRATEGY = "line_splitter_strategy"
62+
HORIZONTAL_STRETCH_FACTOR = "horizontal_stretch_factor"
63+
PAGES_TO_EXTRACT = "pages_to_extract"
64+
MARK_VERTICAL_LINES = "mark_vertical_lines"
65+
MARK_HORIZONTAL_LINES = "mark_horizontal_lines"
66+
PAGE_SEPARATOR = "page_seperator"
67+
URL_IN_POST = "url_in_post"
68+
TAG = "tag"
69+
USE_WEBHOOK = "use_webhook"
70+
WEBHOOK_METADATA = "webhook_metadata"
71+
TEXT_ONLY = "text_only"
72+
73+
74+
class WhisperStatus:
75+
"""Values returned / used by /whisper-status endpoint."""
76+
77+
PROCESSING = "processing"
78+
PROCESSED = "processed"
79+
DELIVERED = "delivered"
80+
UNKNOWN = "unknown"
81+
# Used for async processing
82+
WHISPER_HASH = "whisper_hash"
83+
STATUS = "status"
84+
85+
86+
class WhispererDefaults:
87+
"""Defaults meant for LLM whisperer."""
88+
89+
MEDIAN_FILTER_SIZE = 0
90+
GAUSSIAN_BLUR_RADIUS = 0.0
91+
FORCE_TEXT_PROCESSING = False
92+
LINE_SPLITTER_TOLERANCE = 0.75
93+
LINE_SPLITTER_STRATEGY = "left-priority"
94+
HORIZONTAL_STRETCH_FACTOR = 1.0
95+
POLL_INTERVAL = int(os.getenv(WhispererEnv.POLL_INTERVAL, 30))
96+
MAX_POLLS = int(os.getenv(WhispererEnv.MAX_POLLS, 30))
97+
PAGES_TO_EXTRACT = ""
98+
PAGE_SEPARATOR = "<<<"
99+
MARK_VERTICAL_LINES = False
100+
MARK_HORIZONTAL_LINES = False
101+
URL_IN_POST = False
102+
TAG = "default"
103+
TEXT_ONLY = False

0 commit comments

Comments
 (0)