unrealon 1.0.4__py3-none-any.whl → 1.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
unrealon/__init__.py ADDED
@@ -0,0 +1,28 @@
1
+ """
2
+ UnrealOn SDK - Main Package
3
+ """
4
+
5
+ # Import from centralized config
6
+ from .sdk_config import (
7
+ VERSION as __version__,
8
+ AUTHOR as __author__,
9
+ AUTHOR_EMAIL as __email__,
10
+ LICENSE as __license__,
11
+ PROJECT_URL as __url__,
12
+ VERSION_INFO,
13
+ PROJECT_INFO,
14
+ get_version,
15
+ is_debug_mode,
16
+ )
17
+
18
+ __all__ = [
19
+ "__version__",
20
+ "__author__",
21
+ "__email__",
22
+ "__license__",
23
+ "__url__",
24
+ "VERSION_INFO",
25
+ "PROJECT_INFO",
26
+ "get_version",
27
+ "is_debug_mode",
28
+ ]
unrealon/sdk_config.py ADDED
@@ -0,0 +1,88 @@
1
+ """
2
+ UnrealOn SDK Simple Config
3
+
4
+ Simple centralized configuration with Pydantic v2 models.
5
+ """
6
+
7
+ import os
8
+ from pydantic import BaseModel, Field, ConfigDict
9
+
10
+ # Simple version constants
11
+ VERSION = "1.0.6"
12
+
13
+ # Project info
14
+ AUTHOR = "UnrealOn Team"
15
+ AUTHOR_EMAIL = "dev@unrealon.com"
16
+ LICENSE = "MIT"
17
+ PROJECT_URL = "https://unrealon.com"
18
+
19
+
20
+ class VersionInfo(BaseModel):
21
+ """Version information model."""
22
+
23
+ model_config = ConfigDict(validate_assignment=True, extra="forbid")
24
+
25
+ version: str = Field(default=VERSION)
26
+
27
+
28
+
29
+ class ProjectInfo(BaseModel):
30
+ """Project information model."""
31
+
32
+ model_config = ConfigDict(validate_assignment=True, extra="forbid")
33
+
34
+ author: str = Field(default=AUTHOR)
35
+ email: str = Field(default=AUTHOR_EMAIL)
36
+ license: str = Field(default=LICENSE)
37
+ url: str = Field(default=PROJECT_URL)
38
+
39
+
40
+ # Global instances
41
+ VERSION_INFO = VersionInfo()
42
+ PROJECT_INFO = ProjectInfo()
43
+
44
+
45
+ def get_version() -> str:
46
+ """Get SDK version."""
47
+ return VERSION
48
+
49
+
50
+ def is_debug_mode() -> bool:
51
+ """Check if debug mode enabled."""
52
+ return os.getenv("UNREALON_DEBUG", "").lower() in ("1", "true", "debug")
53
+
54
+
55
+ # Compatibility check
56
+ def check_compatibility(required_version: str) -> bool:
57
+ """Check if SDK version is compatible with required version."""
58
+ try:
59
+ required = tuple(map(int, required_version.split(".")))
60
+ current = tuple(map(int, VERSION.split(".")))
61
+ return current >= required
62
+ except (ValueError, AttributeError):
63
+ return False
64
+
65
+
66
+ # Debug output
67
+ if os.getenv("UNREALON_DEBUG", "").lower() in ("1", "true", "debug"):
68
+ logger = logging.getLogger(__name__)
69
+ logger.info(f"🚀 UnrealOn SDK v{VERSION} loaded")
70
+ logger.info(f" 🎯 Service-based architecture")
71
+ logger.info(f" 📦 KISS principle - simple & reliable")
72
+ logger.info(f" 🔗 Available services: {', '.join(__all__)}")
73
+
74
+
75
+ __all__ = [
76
+ "VERSION",
77
+ "AUTHOR",
78
+ "AUTHOR_EMAIL",
79
+ "LICENSE",
80
+ "PROJECT_URL",
81
+ "VersionInfo",
82
+ "ProjectInfo",
83
+ "VERSION_INFO",
84
+ "PROJECT_INFO",
85
+ "get_version",
86
+ "is_debug_mode",
87
+ "check_compatibility",
88
+ ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: unrealon
3
- Version: 1.0.4
3
+ Version: 1.0.6
4
4
  Summary: AI-powered web scraping platform with real-time orchestration
5
5
  License: MIT
6
6
  Author: Unrealon Team
@@ -1,5 +1,7 @@
1
+ unrealon/__init__.py,sha256=IWhHl4jLgYR5HjEtHR1_-BF3tUkXJpP67IqqekdsVxk,494
2
+ unrealon/sdk_config.py,sha256=ak2gRMEo2I-YtiJplOhgNIdsQnnoZlKx6c87b8ws6EI,2118
1
3
  unrealon_browser/README.md,sha256=9pP6RrfMGHtdT5uDLFAUB1e4nNGzZudXViEo1940gKw,396
2
- unrealon_browser/__init__.py,sha256=ClwFNHvhcUJzqYdHuA7hODnBWKke8_CqvMXsPxLmEIg,622
4
+ unrealon_browser/__init__.py,sha256=pLHhYYhYJmzrED1Chi3uQAETVFxqQrikwEAwO2TTZ70,631
3
5
  unrealon_browser/pyproject.toml,sha256=_PTGU6Pwh7antWDqZeA6KU-Vx3Xw4jwTlU_Wgt6t0Cg,4945
4
6
  unrealon_browser/src/__init__.py,sha256=iw8FNzemhVx-AYGQVUthpW59IZy8FxCXpy0DvhRok4c,1339
5
7
  unrealon_browser/src/cli/__init__.py,sha256=b3r88oeCYsqZF8EU8EZXP9v54Q8cIimN7UmxJsXcB84,264
@@ -23,7 +25,7 @@ unrealon_browser/src/managers/logger_bridge.py,sha256=d4H67QcJOdupn_VpCNjZqsI5w3
23
25
  unrealon_browser/src/managers/profile.py,sha256=jrhjDgik697abHvioWub0smHb9YZWJy4opFPqdZli5A,18179
24
26
  unrealon_browser/src/managers/stealth.py,sha256=eSLAqpCHyyntUD1RzZC0jpNpYFuHpKl4J9WxmICx3Ww,13890
25
27
  unrealon_driver/README.md,sha256=KHcX4P_C58wh3PjpZS2sYf-GRUs3lsBcioi-1gbcHS8,5254
26
- unrealon_driver/__init__.py,sha256=Ze-6b2wdZY6mIJg97uPYdMt2ZkLJHj-gbNJPTZWJ5Xk,605
28
+ unrealon_driver/__init__.py,sha256=q1whUYDWp5ZLs01Y6YrMiuXmPuG_b3fRDfP_dKIoNI4,614
27
29
  unrealon_driver/pyproject.toml,sha256=_YeD0-KH1O5KrWNrPmK7mLDk_BkFhFrrOfNtIYbv-0M,4589
28
30
  unrealon_driver/src/__init__.py,sha256=0LA_rASCvvo42-7mlU2F1XFfEcrYIicCC4_E3nwj_wg,2450
29
31
  unrealon_driver/src/cli/__init__.py,sha256=6AE6FJoXxhr5bMGn9PVuavryEsvcjMiGFbQdn2c6L6o,260
@@ -61,7 +63,7 @@ unrealon_driver/src/utils/__init__.py,sha256=XIvXAbiMUNGXdTl5yxIfjYs8CdKTxBpI_ps
61
63
  unrealon_driver/src/utils/service_factory.py,sha256=D9aefhF4px2y7BB1JcFaRM3g7Izb_VIzrGuDznA3p9o,10941
62
64
  unrealon_driver/src/utils/time_formatter.py,sha256=5Vm0WTqc1X5rYBl8yA0_GFEunV5EgXXL_fra3YoEfHs,10105
63
65
  unrealon_llm/README.md,sha256=ln5eOG5igajQy7e0LEHxDSjGNL3yLtPBeNnj4YZ7Q2c,1102
64
- unrealon_llm/__init__.py,sha256=0NGg06sK5C-VS2KoBYDF2SnJgukNUkOiJw3Whf34_gQ,611
66
+ unrealon_llm/__init__.py,sha256=nN4_w3AIzMhMKkSwYppYLqvCzJ73jE302WRvhVqP80c,620
65
67
  unrealon_llm/pyproject.toml,sha256=to4asInBDsxznIp9KP1dZELcQLzikzd2AJe1AAp87r0,3755
66
68
  unrealon_llm/src/__init__.py,sha256=ga0mWhimHG6Xt-UJLKFb3IvpBawJtUWlSqkZLu8Q0Xg,5338
67
69
  unrealon_llm/src/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -89,9 +91,9 @@ unrealon_llm/src/managers/cost_manager.py,sha256=Bu4LUWcKB9JSwIz2m5FxAe5iEN3dVRX
89
91
  unrealon_llm/src/managers/request_manager.py,sha256=oMsn2x1P6AF_6C84kmJrl_SCTHpWzgBkR50M9-bIyd0,10702
90
92
  unrealon_llm/src/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
91
93
  unrealon_llm/src/modules/html_processor/__init__.py,sha256=-Z3ExABUbUn0l8GEZhbW3WYFJGv7uheGpftiyOji0yg,552
92
- unrealon_llm/src/modules/html_processor/base_processor.py,sha256=BUSK3wou_KWxxr9nFgFAK_HrZCbVjt44EwM6zGZLIP8,10930
93
- unrealon_llm/src/modules/html_processor/details_processor.py,sha256=XAQFlf0OvfcgjXDd7cAV_LUf07WrnS_3V2ia3zHPZTA,2033
94
- unrealon_llm/src/modules/html_processor/listing_processor.py,sha256=PSdFlSlZLZ_dIUS8d_umJKBepPDRyijEv9zruioX2r4,2271
94
+ unrealon_llm/src/modules/html_processor/base_processor.py,sha256=azggKCsE52cUnRAFi-7bak7LZPrYrrH5tJFWxI-HoBo,16423
95
+ unrealon_llm/src/modules/html_processor/details_processor.py,sha256=eiayCPIB9p4PSDtMUEgdPhtb8yu-LqN-WkFd86BuhE4,3479
96
+ unrealon_llm/src/modules/html_processor/listing_processor.py,sha256=h8D79XnVsWkEqcbDoVhcsbS1LYV2AngVo1ROy5oRD7o,3669
95
97
  unrealon_llm/src/modules/html_processor/models/__init__.py,sha256=Hn-ztJWI4SokVxhx-cakm5h_Xhjg0rn9_IXyToIjwRE,420
96
98
  unrealon_llm/src/modules/html_processor/models/processing_models.py,sha256=SoOE8KCwivU3FGLK3fxx0rKtKXyI-C7ibEHyWCApZAQ,1460
97
99
  unrealon_llm/src/modules/html_processor/models/universal_model.py,sha256=Zi3L_t4rcwHpbJKADWSdK7yBErVIGBf3ZRCsZxUsMDM,1738
@@ -108,7 +110,7 @@ unrealon_llm/src/utils/models_cache.py,sha256=IL1POtqFIybRyOakMEZnRLkqFx7FCfk1gV
108
110
  unrealon_llm/src/utils/smart_counter.py,sha256=F96Y_Yj-5uuio4hkgkuVjjAsRSgu0_LfQxFJKOu_cbA,8048
109
111
  unrealon_llm/src/utils/token_counter.py,sha256=TB0cNbjipiVkin_6yra4VjpbcUZqLEfVv8cgTPTcX9s,6209
110
112
  unrealon_sdk/README.md,sha256=_rRg7h9Fqsc-w_kkv8FM1wHF7dL6TH7-WRr79iJOM80,470
111
- unrealon_sdk/__init__.py,sha256=qjFvskNOMfE3UBGTC2todD7zmYgNJZlRtPo1JE8FYqw,755
113
+ unrealon_sdk/__init__.py,sha256=4XWzXb7QYSL1s9v7gVci6Ks3eqv5TAU19FgaVigWpRM,764
112
114
  unrealon_sdk/pyproject.toml,sha256=WsbZqROrphT3fXvOTF4200ZiVTMjJjnavRtoqipH1UQ,5799
113
115
  unrealon_sdk/src/__init__.py,sha256=skeneU3XDXF6_nsEKbBZ4Gq5uHXU0v1vArVOGJ6Asxo,3552
114
116
  unrealon_sdk/src/cli/__init__.py,sha256=0jzVnvi6pCOA8TxkyE9rDmJPvesYvXGKGWJiKDd0Kd8,180
@@ -238,7 +240,7 @@ unrealon_sdk/src/internal/http_client.py,sha256=uU3BdNYj4ZL16y0BpBxOtWLOo-pE-8LW
238
240
  unrealon_sdk/src/internal/websocket_client.py,sha256=1TteTv_6dUMXS5xTXwld6XB2Q0hcOsycLv9l_KEB8aA,15700
239
241
  unrealon_sdk/src/provider.py,sha256=kyKjUjuo6s8hcTld8gIc7aO4SM7ozhsUlIM0EXOyblw,14104
240
242
  unrealon_sdk/src/utils.py,sha256=nj8a83a7p_RXA985yRdHQxPr2S4rwKiwp1wD3qj7EEU,5440
241
- unrealon-1.0.4.dist-info/LICENSE,sha256=eEH8mWZW49YMpl4Sh5MtKqkZ8aVTzKQXiNPEnvL14ns,1070
242
- unrealon-1.0.4.dist-info/METADATA,sha256=y5iPh0hGKFGc87R9ydbNdtstgynXL8ACisIsjUrRAlc,29082
243
- unrealon-1.0.4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
244
- unrealon-1.0.4.dist-info/RECORD,,
243
+ unrealon-1.0.6.dist-info/LICENSE,sha256=eEH8mWZW49YMpl4Sh5MtKqkZ8aVTzKQXiNPEnvL14ns,1070
244
+ unrealon-1.0.6.dist-info/METADATA,sha256=_XESL3BDHrP03yZDXTZT7tfpI72rmOy8GpWmTlRzurg,29082
245
+ unrealon-1.0.6.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
246
+ unrealon-1.0.6.dist-info/RECORD,,
@@ -13,7 +13,7 @@ __description__ = "Enterprise browser automation with stealth capabilities"
13
13
 
14
14
 
15
15
  # Import from centralized config
16
- from sdk_config import (
16
+ from unrealon.sdk_config import (
17
17
  VERSION as __version__,
18
18
  AUTHOR as __author__,
19
19
  AUTHOR_EMAIL as __email__,
@@ -13,7 +13,7 @@ __description__ = "Simple, modular parser development tools for UnrealOn SDK"
13
13
 
14
14
 
15
15
  # Import from centralized config
16
- from sdk_config import (
16
+ from unrealon.sdk_config import (
17
17
  VERSION as __version__,
18
18
  AUTHOR as __author__,
19
19
  AUTHOR_EMAIL as __email__,
unrealon_llm/__init__.py CHANGED
@@ -13,7 +13,7 @@ __description__ = "Large Language Model integration tools for UnrealOn SDK"
13
13
 
14
14
 
15
15
  # Import from centralized config
16
- from sdk_config import (
16
+ from unrealon.sdk_config import (
17
17
  VERSION as __version__,
18
18
  AUTHOR as __author__,
19
19
  AUTHOR_EMAIL as __email__,
@@ -10,6 +10,7 @@ import json
10
10
  import random
11
11
  from typing import Type
12
12
  import traceback
13
+ import re
13
14
 
14
15
  from unrealon_llm.src.core import SmartLLMClient
15
16
  from unrealon_llm.src.dto import ChatMessage, MessageRole
@@ -77,6 +78,10 @@ class BaseHTMLProcessor(ABC):
77
78
  """Return extraction prompt template for this processor type"""
78
79
  pass
79
80
 
81
+ def _trim_system_prompt(self, system_prompt: str) -> str:
82
+ """Trim system prompt to remove empty lines"""
83
+ return "\n".join(system_prompt.split("\n")[1:])
84
+
80
85
  async def extract_patterns(self, html_content: str) -> ExtractionResult:
81
86
  """
82
87
  Extract patterns from HTML using LLM intelligence
@@ -116,15 +121,27 @@ class BaseHTMLProcessor(ABC):
116
121
  prompt_tokens=0,
117
122
  details={
118
123
  "full_prompt": prompt[:2000] + "..." if len(prompt) > 2000 else prompt,
119
- "schema_json": json.dumps(self.schema_class.model_json_schema(), indent=2)
120
- }
124
+ "schema_json": json.dumps(
125
+ self.schema_class.model_json_schema(), indent=2
126
+ ),
127
+ },
121
128
  )
122
129
 
130
+ # Add critical format requirements to the prompt
131
+ SYSTEM_PROMPT = f"""
132
+ You are an HTML-to-JSON expert at analyzing {self.processor_type} pages.
133
+ You MUST return JSON that EXACTLY matches the Pydantic schema provided.
134
+ RESPOND ONLY WITH VALID JSON.
135
+ NO EXPLANATIONS, NO TEXT, ONLY JSON!
136
+ Include ALL required fields from the schema!
137
+ CRITICAL: The 'selectors' field must be a DICTIONARY/OBJECT, not a list!
138
+ """
139
+
123
140
  # Prepare LLM messages
124
141
  messages = [
125
142
  ChatMessage(
126
143
  role=MessageRole.SYSTEM,
127
- content=f"You are an HTML-to-JSON expert at analyzing {self.processor_type} pages. You MUST return JSON that EXACTLY matches the Pydantic schema provided. RESPOND ONLY WITH VALID JSON. NO EXPLANATIONS, NO TEXT, ONLY JSON! Include ALL required fields from the schema!",
144
+ content=self._trim_system_prompt(SYSTEM_PROMPT),
128
145
  ),
129
146
  ChatMessage(
130
147
  role=MessageRole.USER,
@@ -144,8 +161,7 @@ class BaseHTMLProcessor(ABC):
144
161
  try:
145
162
  # Call LLM
146
163
  response = await self.llm_client.chat_completion(
147
- messages,
148
- response_model=self.schema_class
164
+ messages, response_model=self.schema_class
149
165
  )
150
166
 
151
167
  # Log full LLM response for debugging
@@ -167,7 +183,7 @@ class BaseHTMLProcessor(ABC):
167
183
  )
168
184
 
169
185
  # Use the validated model from LLM response
170
- if hasattr(response, 'extracted_model') and response.extracted_model:
186
+ if hasattr(response, "extracted_model") and response.extracted_model:
171
187
  validated_model = response.extracted_model
172
188
  validated_result = validated_model.model_dump()
173
189
  logger.log_html_analysis_completed(
@@ -203,8 +219,36 @@ class BaseHTMLProcessor(ABC):
203
219
  "raw_llm_response": result_data,
204
220
  },
205
221
  )
206
- # Fall back to raw data
207
- validated_result = result_data
222
+
223
+ # 🔥 SMART FALLBACK: Try to fix common LLM format issues
224
+ try:
225
+ fixed_data = self._fix_llm_response_format(result_data, str(e))
226
+ validated_model = self.schema_class(**fixed_data)
227
+ validated_result = validated_model.model_dump()
228
+ logger.log_html_analysis_completed(
229
+ selectors_generated=len(str(fixed_data)),
230
+ confidence_score=fixed_data.get("confidence", 0.0),
231
+ details={
232
+ "processor_type": self.processor_type,
233
+ "validation_success": True,
234
+ "schema_matched": True,
235
+ "format_fixed": True,
236
+ },
237
+ )
238
+ except Exception as fix_error:
239
+ logger.log_html_analysis_failed(
240
+ error_message=f"Format fixing also failed: {str(fix_error)}",
241
+ details={
242
+ "processor_type": self.processor_type,
243
+ "validation_error": str(e),
244
+ "fix_error": str(fix_error),
245
+ "raw_llm_response": result_data,
246
+ },
247
+ )
248
+ # Final fallback: create minimal valid structure
249
+ validated_result = self._create_fallback_result(
250
+ result_data, str(e)
251
+ )
208
252
 
209
253
  # Create Pydantic processing metadata
210
254
  processing_info = ProcessingInfo(
@@ -253,12 +297,20 @@ class BaseHTMLProcessor(ABC):
253
297
 
254
298
  # Add random number to bypass any caching
255
299
  cache_buster = random.randint(100000, 999999)
256
-
257
- schema_prompt = f"""PYDANTIC 2 SCHEMA (Request #{cache_buster}):
258
- {schema_json}
259
300
 
260
- CRITICAL: Return JSON that EXACTLY matches this schema structure!
261
- The response must include ALL required fields: detected_item_type, extraction_strategy, confidence, selectors, documentation."""
301
+ schema_prompt = f"""
302
+ PYDANTIC 2 SCHEMA (Request #{cache_buster}):
303
+ {schema_json}
304
+
305
+ 🚨 CRITICAL FORMAT REQUIREMENTS:
306
+ 1. Return JSON that EXACTLY matches this schema structure!
307
+ 2. The response must include ALL required fields: detected_item_type, extraction_strategy, confidence, selectors, documentation
308
+ 3. The "selectors" field MUST be a DICTIONARY/OBJECT with field names as keys and arrays of CSS selectors as values
309
+ 4. Example: "selectors": {{"title": ["h1.title", ".product-name"], "price": [".price", ".cost"]}}
310
+ 5. DO NOT return "selectors" as a list: ❌ ["h1.title", ".price"]
311
+ 6. DO return "selectors" as a dictionary: ✅ {{"title": ["h1.title"], "price": [".price"]}}
312
+ """
313
+ schema_prompt = self._trim_system_prompt(schema_prompt)
262
314
 
263
315
  return prompt_template.format(
264
316
  processor_type=self.processor_type,
@@ -292,3 +344,72 @@ The response must include ALL required fields: detected_item_type, extraction_st
292
344
  estimated_cost = (total_tokens / 1_000_000) * 0.25
293
345
 
294
346
  return estimated_cost
347
+
348
+ def _fix_llm_response_format(self, result_data: dict, error_message: str) -> dict:
349
+ """Fix common LLM response format issues."""
350
+ fixed_data = result_data.copy()
351
+
352
+ # Fix selectors if it's a list instead of dict
353
+ if "selectors" in fixed_data and isinstance(fixed_data["selectors"], list):
354
+ logger.log_html_analysis_failed(
355
+ error_message="Fixing selectors format: list -> dict",
356
+ details={
357
+ "processor_type": self.processor_type,
358
+ "original_selectors": fixed_data["selectors"],
359
+ },
360
+ )
361
+
362
+ # Convert list to dict with generic field names
363
+ selectors_list = fixed_data["selectors"]
364
+ fixed_data["selectors"] = {}
365
+
366
+ # Try to intelligently map list items to field names
367
+ field_names = ["item", "title", "price", "description", "image", "link"]
368
+ for i, selector in enumerate(selectors_list):
369
+ if i < len(field_names):
370
+ field_name = field_names[i]
371
+ else:
372
+ field_name = f"field_{i+1}"
373
+
374
+ # Convert single selector to list
375
+ if isinstance(selector, str):
376
+ fixed_data["selectors"][field_name] = [selector]
377
+ elif isinstance(selector, list):
378
+ fixed_data["selectors"][field_name] = selector
379
+ else:
380
+ fixed_data["selectors"][field_name] = [str(selector)]
381
+
382
+ # Ensure all required fields exist
383
+ required_fields = [
384
+ "detected_item_type",
385
+ "extraction_strategy",
386
+ "confidence",
387
+ "selectors",
388
+ "documentation",
389
+ ]
390
+ for field in required_fields:
391
+ if field not in fixed_data:
392
+ if field == "detected_item_type":
393
+ fixed_data[field] = "unknown"
394
+ elif field == "extraction_strategy":
395
+ fixed_data[field] = "fallback_strategy"
396
+ elif field == "confidence":
397
+ fixed_data[field] = 0.1
398
+ elif field == "selectors":
399
+ fixed_data[field] = {}
400
+ elif field == "documentation":
401
+ fixed_data[field] = (
402
+ "Extraction completed with fallback processing due to format issues."
403
+ )
404
+
405
+ return fixed_data
406
+
407
+ def _create_fallback_result(self, result_data: dict, error_message: str) -> dict:
408
+ """Create a minimal valid result when all else fails."""
409
+ return {
410
+ "detected_item_type": "unknown",
411
+ "extraction_strategy": "fallback_strategy",
412
+ "confidence": 0.1,
413
+ "selectors": {},
414
+ "documentation": f"Extraction failed due to validation error: {error_message}. Raw data: {str(result_data)[:500]}...",
415
+ }
@@ -25,37 +25,61 @@ class DetailsProcessor(BaseHTMLProcessor):
25
25
  def get_extraction_prompt_template(self) -> str:
26
26
  """Return details-specific extraction prompt template"""
27
27
 
28
- return """{schema}
29
-
30
- [__TASK_DESCRIPTION__]
31
- Analyze this DETAILS/PRODUCT/ITEM page and generate universal extraction patterns.
32
- PROCESSOR TYPE: {processor_type}
33
- THIS IS A DETAILS PAGE containing information about a single item/product/service/article.
34
- [/__TASK_DESCRIPTION__]
35
-
36
- [__INSTRUCTIONS__]
37
- YOUR TASK:
38
- Analyze this details page and generate extraction patterns for ANY type of item.
39
- This could be: product details, service info, article content, job description, real estate listing, person profile, etc.
40
-
41
- CRITICAL REQUIREMENTS:
42
- 1. Return simple CSS selectors in the "selectors" object
43
- 2. Include comprehensive markdown documentation
44
- 3. Provide real examples from the actual HTML
45
- 4. Explain the page structure and best extraction approach
46
- 5. Include confidence scores and fallback strategies
47
- 6. Document any special handling needed
48
-
49
- ANALYZE THE HTML AND DETERMINE:
50
- - What type of item this page describes
51
- - What information is available (specs, pricing, reviews, etc.)
52
- - How content is structured and organized
53
- - What actions are possible (buy, contact, etc.)
54
- - Best extraction strategy for this specific page
55
- [/__INSTRUCTIONS__]
56
-
57
- [__HTML_CONTENT__]
58
- HTML CONTENT (first 50KB):
59
- {html_content}
60
- [/__HTML_CONTENT__]
61
- """
28
+ prompt = """{schema}
29
+ [__TASK_DESCRIPTION__]
30
+ Analyze this DETAILS/PRODUCT/ITEM page and generate universal extraction patterns.
31
+ PROCESSOR TYPE: {processor_type}
32
+ THIS IS A DETAILS PAGE containing information about a single item/product/service/article.
33
+ [/__TASK_DESCRIPTION__]
34
+
35
+ [__CRITICAL_FORMAT_REQUIREMENTS__]
36
+ 🚨 SELECTORS FORMAT: The "selectors" field MUST be a DICTIONARY/OBJECT, NOT a list!
37
+ Example of CORRECT format:
38
+ "selectors": {{
39
+ "title": ["h1.product-title", "h1.page-title", ".item-name"],
40
+ "price": [".price", ".cost", "span[data-price]", ".product-price"],
41
+ "description": [".description", ".product-desc", ".item-details"],
42
+ "images": ["img.product-image", ".gallery img", "img[src*='product']"],
43
+ "specifications": [".specs", ".product-specs", ".item-specifications"],
44
+ "reviews": [".reviews", ".product-reviews", ".customer-reviews"]
45
+ }}
46
+
47
+ WRONG format (DO NOT USE):
48
+ "selectors": ["h1.title", ".price", ".description"]
49
+
50
+ CORRECT format (USE THIS):
51
+ "selectors": {{
52
+ "title": ["h1.title", ".product-name", "h1[itemprop='name']"],
53
+ "price": [".price", ".cost", "span[data-price]"],
54
+ "description": [".description", ".product-desc", ".item-details"]
55
+ }}
56
+ [/__CRITICAL_FORMAT_REQUIREMENTS__]
57
+
58
+ [__INSTRUCTIONS__]
59
+ YOUR TASK:
60
+ Analyze this details page and generate extraction patterns for ANY type of item.
61
+ This could be: product details, service info, article content, job description, real estate listing, person profile, etc.
62
+
63
+ CRITICAL REQUIREMENTS:
64
+ 1. The "selectors" field MUST be a DICTIONARY with field names as keys and arrays of CSS selectors as values
65
+ 2. Include comprehensive markdown documentation
66
+ 3. Provide real examples from the actual HTML
67
+ 4. Explain the page structure and best extraction approach
68
+ 5. Include confidence scores and fallback strategies
69
+ 6. Document any special handling needed
70
+
71
+ ANALYZE THE HTML AND DETERMINE:
72
+ - What type of item this page describes
73
+ - What information is available (specs, pricing, reviews, etc.)
74
+ - How content is structured and organized
75
+ - What actions are possible (buy, contact, etc.)
76
+ - Best extraction strategy for this specific page
77
+ [/__INSTRUCTIONS__]
78
+
79
+ [__HTML_CONTENT__]
80
+ HTML CONTENT (first 50KB):
81
+ {html_content}
82
+ [/__HTML_CONTENT__]
83
+ """
84
+
85
+ return self._trim_system_prompt(prompt)
@@ -25,43 +25,67 @@ class ListingProcessor(BaseHTMLProcessor):
25
25
  def get_extraction_prompt_template(self) -> str:
26
26
  """Return listing-specific extraction prompt template"""
27
27
 
28
- return """{schema}
29
-
30
- [__TASK_DESCRIPTION__]
31
- Analyze this LISTING/CATALOG page and generate universal extraction patterns.
32
- PROCESSOR TYPE: {processor_type}
33
- THIS IS A LISTING PAGE containing multiple items arranged in a list or grid.
34
- [/__TASK_DESCRIPTION__]
35
-
36
- [__INSTRUCTIONS__]
37
- YOUR TASK:
38
- Analyze this listing page and generate extraction patterns for ANY type of items.
39
- This could be: products, services, articles, jobs, real estate, people, cars, etc.
40
-
41
- CRITICAL REQUIREMENTS:
42
- 1. Return simple CSS selectors in the "selectors" object
43
- 2. This is a LISTING PAGE with multiple items
44
- 3. Focus on identifying item containers and individual item patterns
45
- 4. Detect ANY type of items - not just products!
46
- 5. Provide multiple fallback selectors for reliability
47
- 6. Include pagination and navigation patterns
48
- 7. Use realistic confidence scores (0.1-1.0)
49
- 8. Auto-detect what type of content this listing contains
50
- 9. Provide extraction strategy advice
51
- 10. Look for structured data (JSON-LD, microdata)
52
- 11. Generate patterns that work with BeautifulSoup4 .select() method
53
- 12. RETURN JSON that EXACTLY matches the Pydantic schema above!
54
-
55
- ANALYZE THE HTML AND DETERMINE:
56
- - What type of items are listed (products, services, articles, etc.)
57
- - How items are structured and contained
58
- - What navigation elements exist
59
- - What metadata is available
60
- - Best extraction strategy for this specific page
61
- [/__INSTRUCTIONS__]
62
-
63
- [__HTML_CONTENT__]
64
- HTML CONTENT (first 50KB):
65
- {html_content}
66
- [/__HTML_CONTENT__]
67
- """
28
+ prompt = """{schema}
29
+
30
+ [__TASK_DESCRIPTION__]
31
+ Analyze this LISTING/CATALOG page and generate universal extraction patterns.
32
+ PROCESSOR TYPE: {processor_type}
33
+ THIS IS A LISTING PAGE containing multiple items arranged in a list or grid.
34
+ [/__TASK_DESCRIPTION__]
35
+
36
+ [__CRITICAL_FORMAT_REQUIREMENTS__]
37
+ 🚨 SELECTORS FORMAT: The "selectors" field MUST be a DICTIONARY/OBJECT, NOT a list!
38
+ Example of CORRECT format:
39
+ "selectors": {{
40
+ "items_container": ["div.product-grid", "ul.product-list", "div.items"],
41
+ "item_title": ["h3.product-title", "a.product-link", ".item-name"],
42
+ "item_price": [".price", ".cost", "span[data-price]"],
43
+ "item_image": ["img.product-image", ".item-img", "img[src*='product']"],
44
+ "pagination": [".pagination", ".page-nav", "nav[aria-label='pagination']"]
45
+ }}
46
+
47
+ WRONG format (DO NOT USE):
48
+ "selectors": ["div.product", "h3.title", ".price"]
49
+
50
+ CORRECT format (USE THIS):
51
+ "selectors": {{
52
+ "items": ["div.product", "li.item", ".product-card"],
53
+ "titles": ["h3.title", ".product-name", "a[title]"],
54
+ "prices": [".price", ".cost", "span[data-price]"]
55
+ }}
56
+ [/__CRITICAL_FORMAT_REQUIREMENTS__]
57
+
58
+ [__INSTRUCTIONS__]
59
+ YOUR TASK:
60
+ Analyze this listing page and generate extraction patterns for ANY type of items.
61
+ This could be: products, services, articles, jobs, real estate, people, cars, etc.
62
+
63
+ CRITICAL REQUIREMENTS:
64
+ 1. The "selectors" field MUST be a DICTIONARY with field names as keys and arrays of CSS selectors as values
65
+ 2. This is a LISTING PAGE with multiple items
66
+ 3. Focus on identifying item containers and individual item patterns
67
+ 4. Detect ANY type of items - not just products!
68
+ 5. Provide multiple fallback selectors for reliability
69
+ 6. Include pagination and navigation patterns
70
+ 7. Use realistic confidence scores (0.1-1.0)
71
+ 8. Auto-detect what type of content this listing contains
72
+ 9. Provide extraction strategy advice
73
+ 10. Look for structured data (JSON-LD, microdata)
74
+ 11. Generate patterns that work with BeautifulSoup4 .select() method
75
+ 12. RETURN JSON that EXACTLY matches the Pydantic schema above!
76
+
77
+ ANALYZE THE HTML AND DETERMINE:
78
+ - What type of items are listed (products, services, articles, etc.)
79
+ - How items are structured and contained
80
+ - What navigation elements exist
81
+ - What metadata is available
82
+ - Best extraction strategy for this specific page
83
+ [/__INSTRUCTIONS__]
84
+
85
+ [__HTML_CONTENT__]
86
+ HTML CONTENT (first 50KB):
87
+ {html_content}
88
+ [/__HTML_CONTENT__]
89
+ """
90
+
91
+ return self._trim_system_prompt(prompt)
unrealon_sdk/__init__.py CHANGED
@@ -16,7 +16,7 @@ __description__ = "Enterprise Parsing Platform SDK for UnrealOn"
16
16
 
17
17
 
18
18
  # Import from centralized config
19
- from sdk_config import (
19
+ from unrealon.sdk_config import (
20
20
  VERSION as __version__,
21
21
  AUTHOR as __author__,
22
22
  AUTHOR_EMAIL as __email__,