unrealon 1.0.9__py3-none-any.whl → 1.1.1__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 +23 -21
- unrealon-1.1.1.dist-info/METADATA +722 -0
- unrealon-1.1.1.dist-info/RECORD +82 -0
- {unrealon-1.0.9.dist-info → unrealon-1.1.1.dist-info}/WHEEL +1 -1
- unrealon-1.1.1.dist-info/entry_points.txt +9 -0
- {unrealon-1.0.9.dist-info → unrealon-1.1.1.dist-info/licenses}/LICENSE +1 -1
- unrealon_bridge/__init__.py +114 -0
- unrealon_bridge/cli.py +316 -0
- unrealon_bridge/client/__init__.py +93 -0
- unrealon_bridge/client/base.py +78 -0
- unrealon_bridge/client/commands.py +89 -0
- unrealon_bridge/client/connection.py +90 -0
- unrealon_bridge/client/events.py +65 -0
- unrealon_bridge/client/health.py +38 -0
- unrealon_bridge/client/html_parser.py +146 -0
- unrealon_bridge/client/logging.py +139 -0
- unrealon_bridge/client/proxy.py +70 -0
- unrealon_bridge/client/scheduler.py +450 -0
- unrealon_bridge/client/session.py +70 -0
- unrealon_bridge/configs/__init__.py +14 -0
- unrealon_bridge/configs/bridge_config.py +212 -0
- unrealon_bridge/configs/bridge_config.yaml +39 -0
- unrealon_bridge/models/__init__.py +138 -0
- unrealon_bridge/models/base.py +28 -0
- unrealon_bridge/models/command.py +41 -0
- unrealon_bridge/models/events.py +40 -0
- unrealon_bridge/models/html_parser.py +79 -0
- unrealon_bridge/models/logging.py +55 -0
- unrealon_bridge/models/parser.py +63 -0
- unrealon_bridge/models/proxy.py +41 -0
- unrealon_bridge/models/requests.py +95 -0
- unrealon_bridge/models/responses.py +88 -0
- unrealon_bridge/models/scheduler.py +592 -0
- unrealon_bridge/models/session.py +28 -0
- unrealon_bridge/server/__init__.py +91 -0
- unrealon_bridge/server/base.py +171 -0
- unrealon_bridge/server/handlers/__init__.py +23 -0
- unrealon_bridge/server/handlers/command.py +110 -0
- unrealon_bridge/server/handlers/html_parser.py +139 -0
- unrealon_bridge/server/handlers/logging.py +95 -0
- unrealon_bridge/server/handlers/parser.py +95 -0
- unrealon_bridge/server/handlers/proxy.py +75 -0
- unrealon_bridge/server/handlers/scheduler.py +545 -0
- unrealon_bridge/server/handlers/session.py +66 -0
- unrealon_browser/__init__.py +61 -18
- unrealon_browser/{src/cli → cli}/browser_cli.py +6 -13
- unrealon_browser/{src/cli → cli}/cookies_cli.py +5 -1
- unrealon_browser/{src/core → core}/browser_manager.py +2 -2
- unrealon_browser/{src/managers → managers}/captcha.py +1 -1
- unrealon_browser/{src/managers → managers}/cookies.py +1 -1
- unrealon_browser/managers/logger_bridge.py +231 -0
- unrealon_browser/{src/managers → managers}/profile.py +1 -1
- unrealon_driver/__init__.py +73 -19
- unrealon_driver/browser/__init__.py +8 -0
- unrealon_driver/browser/config.py +74 -0
- unrealon_driver/browser/manager.py +416 -0
- unrealon_driver/exceptions.py +28 -0
- unrealon_driver/parser/__init__.py +55 -0
- unrealon_driver/parser/cli_manager.py +141 -0
- unrealon_driver/parser/daemon_manager.py +227 -0
- unrealon_driver/parser/managers/__init__.py +46 -0
- unrealon_driver/parser/managers/browser.py +51 -0
- unrealon_driver/parser/managers/config.py +281 -0
- unrealon_driver/parser/managers/error.py +412 -0
- unrealon_driver/parser/managers/html.py +732 -0
- unrealon_driver/parser/managers/logging.py +609 -0
- unrealon_driver/parser/managers/result.py +321 -0
- unrealon_driver/parser/parser_manager.py +628 -0
- unrealon/sdk_config.py +0 -88
- unrealon-1.0.9.dist-info/METADATA +0 -810
- unrealon-1.0.9.dist-info/RECORD +0 -246
- unrealon_browser/pyproject.toml +0 -182
- unrealon_browser/src/__init__.py +0 -62
- unrealon_browser/src/managers/logger_bridge.py +0 -395
- unrealon_driver/README.md +0 -204
- unrealon_driver/pyproject.toml +0 -187
- unrealon_driver/src/__init__.py +0 -90
- unrealon_driver/src/cli/__init__.py +0 -10
- unrealon_driver/src/cli/main.py +0 -66
- unrealon_driver/src/cli/simple.py +0 -510
- unrealon_driver/src/config/__init__.py +0 -11
- unrealon_driver/src/config/auto_config.py +0 -478
- unrealon_driver/src/core/__init__.py +0 -18
- unrealon_driver/src/core/exceptions.py +0 -289
- unrealon_driver/src/core/parser.py +0 -638
- unrealon_driver/src/dto/__init__.py +0 -66
- unrealon_driver/src/dto/cli.py +0 -119
- unrealon_driver/src/dto/config.py +0 -18
- unrealon_driver/src/dto/events.py +0 -237
- unrealon_driver/src/dto/execution.py +0 -313
- unrealon_driver/src/dto/services.py +0 -311
- unrealon_driver/src/execution/__init__.py +0 -23
- unrealon_driver/src/execution/daemon_mode.py +0 -317
- unrealon_driver/src/execution/interactive_mode.py +0 -88
- unrealon_driver/src/execution/modes.py +0 -45
- unrealon_driver/src/execution/scheduled_mode.py +0 -209
- unrealon_driver/src/execution/test_mode.py +0 -250
- unrealon_driver/src/logging/__init__.py +0 -24
- unrealon_driver/src/logging/driver_logger.py +0 -512
- unrealon_driver/src/services/__init__.py +0 -24
- unrealon_driver/src/services/browser_service.py +0 -726
- unrealon_driver/src/services/llm/__init__.py +0 -15
- unrealon_driver/src/services/llm/browser_llm_service.py +0 -363
- unrealon_driver/src/services/llm/llm.py +0 -195
- unrealon_driver/src/services/logger_service.py +0 -232
- unrealon_driver/src/services/metrics_service.py +0 -185
- unrealon_driver/src/services/scheduler_service.py +0 -489
- unrealon_driver/src/services/websocket_service.py +0 -362
- unrealon_driver/src/utils/__init__.py +0 -16
- unrealon_driver/src/utils/service_factory.py +0 -317
- unrealon_driver/src/utils/time_formatter.py +0 -338
- unrealon_llm/README.md +0 -44
- unrealon_llm/__init__.py +0 -26
- unrealon_llm/pyproject.toml +0 -154
- unrealon_llm/src/__init__.py +0 -228
- unrealon_llm/src/cli/__init__.py +0 -0
- unrealon_llm/src/core/__init__.py +0 -11
- unrealon_llm/src/core/smart_client.py +0 -438
- unrealon_llm/src/dto/__init__.py +0 -155
- unrealon_llm/src/dto/models/__init__.py +0 -0
- unrealon_llm/src/dto/models/config.py +0 -343
- unrealon_llm/src/dto/models/core.py +0 -328
- unrealon_llm/src/dto/models/enums.py +0 -123
- unrealon_llm/src/dto/models/html_analysis.py +0 -345
- unrealon_llm/src/dto/models/statistics.py +0 -473
- unrealon_llm/src/dto/models/translation.py +0 -383
- unrealon_llm/src/dto/models/type_conversion.py +0 -462
- unrealon_llm/src/dto/schemas/__init__.py +0 -0
- unrealon_llm/src/exceptions.py +0 -392
- unrealon_llm/src/llm_config/__init__.py +0 -20
- unrealon_llm/src/llm_config/logging_config.py +0 -178
- unrealon_llm/src/llm_logging/__init__.py +0 -42
- unrealon_llm/src/llm_logging/llm_events.py +0 -107
- unrealon_llm/src/llm_logging/llm_logger.py +0 -466
- unrealon_llm/src/managers/__init__.py +0 -15
- unrealon_llm/src/managers/cache_manager.py +0 -67
- unrealon_llm/src/managers/cost_manager.py +0 -107
- unrealon_llm/src/managers/request_manager.py +0 -298
- unrealon_llm/src/modules/__init__.py +0 -0
- unrealon_llm/src/modules/html_processor/__init__.py +0 -25
- unrealon_llm/src/modules/html_processor/base_processor.py +0 -415
- unrealon_llm/src/modules/html_processor/details_processor.py +0 -85
- unrealon_llm/src/modules/html_processor/listing_processor.py +0 -91
- unrealon_llm/src/modules/html_processor/models/__init__.py +0 -20
- unrealon_llm/src/modules/html_processor/models/processing_models.py +0 -40
- unrealon_llm/src/modules/html_processor/models/universal_model.py +0 -56
- unrealon_llm/src/modules/html_processor/processor.py +0 -102
- unrealon_llm/src/modules/llm/__init__.py +0 -0
- unrealon_llm/src/modules/translator/__init__.py +0 -0
- unrealon_llm/src/provider.py +0 -116
- unrealon_llm/src/utils/__init__.py +0 -95
- unrealon_llm/src/utils/common.py +0 -64
- unrealon_llm/src/utils/data_extractor.py +0 -188
- unrealon_llm/src/utils/html_cleaner.py +0 -767
- unrealon_llm/src/utils/language_detector.py +0 -308
- unrealon_llm/src/utils/models_cache.py +0 -592
- unrealon_llm/src/utils/smart_counter.py +0 -229
- unrealon_llm/src/utils/token_counter.py +0 -189
- unrealon_sdk/README.md +0 -25
- unrealon_sdk/__init__.py +0 -30
- unrealon_sdk/pyproject.toml +0 -231
- unrealon_sdk/src/__init__.py +0 -150
- unrealon_sdk/src/cli/__init__.py +0 -12
- unrealon_sdk/src/cli/commands/__init__.py +0 -22
- unrealon_sdk/src/cli/commands/benchmark.py +0 -42
- unrealon_sdk/src/cli/commands/diagnostics.py +0 -573
- unrealon_sdk/src/cli/commands/health.py +0 -46
- unrealon_sdk/src/cli/commands/integration.py +0 -498
- unrealon_sdk/src/cli/commands/reports.py +0 -43
- unrealon_sdk/src/cli/commands/security.py +0 -36
- unrealon_sdk/src/cli/commands/server.py +0 -483
- unrealon_sdk/src/cli/commands/servers.py +0 -56
- unrealon_sdk/src/cli/commands/tests.py +0 -55
- unrealon_sdk/src/cli/main.py +0 -126
- unrealon_sdk/src/cli/utils/reporter.py +0 -519
- unrealon_sdk/src/clients/openapi.yaml +0 -3347
- unrealon_sdk/src/clients/python_http/__init__.py +0 -3
- unrealon_sdk/src/clients/python_http/api_config.py +0 -228
- unrealon_sdk/src/clients/python_http/models/BaseModel.py +0 -12
- unrealon_sdk/src/clients/python_http/models/BroadcastDeliveryStats.py +0 -33
- unrealon_sdk/src/clients/python_http/models/BroadcastMessage.py +0 -17
- unrealon_sdk/src/clients/python_http/models/BroadcastMessageRequest.py +0 -35
- unrealon_sdk/src/clients/python_http/models/BroadcastPriority.py +0 -10
- unrealon_sdk/src/clients/python_http/models/BroadcastResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/BroadcastResultResponse.py +0 -33
- unrealon_sdk/src/clients/python_http/models/BroadcastTarget.py +0 -11
- unrealon_sdk/src/clients/python_http/models/ConnectionStats.py +0 -27
- unrealon_sdk/src/clients/python_http/models/ConnectionsResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/DeveloperMessageResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ErrorResponse.py +0 -25
- unrealon_sdk/src/clients/python_http/models/HTTPValidationError.py +0 -16
- unrealon_sdk/src/clients/python_http/models/HealthResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/HealthStatus.py +0 -33
- unrealon_sdk/src/clients/python_http/models/LogLevel.py +0 -10
- unrealon_sdk/src/clients/python_http/models/LoggingRequest.py +0 -27
- unrealon_sdk/src/clients/python_http/models/LoggingResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/MaintenanceMode.py +0 -9
- unrealon_sdk/src/clients/python_http/models/MaintenanceModeRequest.py +0 -33
- unrealon_sdk/src/clients/python_http/models/MaintenanceStatusResponse.py +0 -39
- unrealon_sdk/src/clients/python_http/models/ParserCommandRequest.py +0 -25
- unrealon_sdk/src/clients/python_http/models/ParserMessageResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/ParserRegistrationRequest.py +0 -28
- unrealon_sdk/src/clients/python_http/models/ParserRegistrationResponse.py +0 -25
- unrealon_sdk/src/clients/python_http/models/ParserType.py +0 -10
- unrealon_sdk/src/clients/python_http/models/ProxyBlockRequest.py +0 -19
- unrealon_sdk/src/clients/python_http/models/ProxyEndpointResponse.py +0 -20
- unrealon_sdk/src/clients/python_http/models/ProxyListResponse.py +0 -19
- unrealon_sdk/src/clients/python_http/models/ProxyProvider.py +0 -10
- unrealon_sdk/src/clients/python_http/models/ProxyPurchaseRequest.py +0 -25
- unrealon_sdk/src/clients/python_http/models/ProxyResponse.py +0 -47
- unrealon_sdk/src/clients/python_http/models/ProxyRotationRequest.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ProxyStatus.py +0 -10
- unrealon_sdk/src/clients/python_http/models/ProxyUsageRequest.py +0 -19
- unrealon_sdk/src/clients/python_http/models/ProxyUsageStatsResponse.py +0 -26
- unrealon_sdk/src/clients/python_http/models/ServiceRegistrationDto.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ServiceStatsResponse.py +0 -31
- unrealon_sdk/src/clients/python_http/models/SessionStartRequest.py +0 -23
- unrealon_sdk/src/clients/python_http/models/SuccessResponse.py +0 -25
- unrealon_sdk/src/clients/python_http/models/SystemNotificationResponse.py +0 -23
- unrealon_sdk/src/clients/python_http/models/ValidationError.py +0 -18
- unrealon_sdk/src/clients/python_http/models/ValidationErrorResponse.py +0 -21
- unrealon_sdk/src/clients/python_http/models/WebSocketMetrics.py +0 -21
- unrealon_sdk/src/clients/python_http/models/__init__.py +0 -44
- unrealon_sdk/src/clients/python_http/services/None_service.py +0 -35
- unrealon_sdk/src/clients/python_http/services/ParserManagement_service.py +0 -190
- unrealon_sdk/src/clients/python_http/services/ProxyManagement_service.py +0 -289
- unrealon_sdk/src/clients/python_http/services/SocketLogging_service.py +0 -187
- unrealon_sdk/src/clients/python_http/services/SystemHealth_service.py +0 -119
- unrealon_sdk/src/clients/python_http/services/WebSocketAPI_service.py +0 -198
- unrealon_sdk/src/clients/python_http/services/__init__.py +0 -0
- unrealon_sdk/src/clients/python_http/services/admin_service.py +0 -125
- unrealon_sdk/src/clients/python_http/services/async_None_service.py +0 -35
- unrealon_sdk/src/clients/python_http/services/async_ParserManagement_service.py +0 -190
- unrealon_sdk/src/clients/python_http/services/async_ProxyManagement_service.py +0 -289
- unrealon_sdk/src/clients/python_http/services/async_SocketLogging_service.py +0 -189
- unrealon_sdk/src/clients/python_http/services/async_SystemHealth_service.py +0 -123
- unrealon_sdk/src/clients/python_http/services/async_WebSocketAPI_service.py +0 -200
- unrealon_sdk/src/clients/python_http/services/async_admin_service.py +0 -125
- unrealon_sdk/src/clients/python_websocket/__init__.py +0 -28
- unrealon_sdk/src/clients/python_websocket/client.py +0 -490
- unrealon_sdk/src/clients/python_websocket/events.py +0 -732
- unrealon_sdk/src/clients/python_websocket/example.py +0 -136
- unrealon_sdk/src/clients/python_websocket/types.py +0 -871
- unrealon_sdk/src/core/__init__.py +0 -64
- unrealon_sdk/src/core/client.py +0 -556
- unrealon_sdk/src/core/config.py +0 -465
- unrealon_sdk/src/core/exceptions.py +0 -239
- unrealon_sdk/src/core/metadata.py +0 -191
- unrealon_sdk/src/core/models.py +0 -142
- unrealon_sdk/src/core/types.py +0 -68
- unrealon_sdk/src/dto/__init__.py +0 -268
- unrealon_sdk/src/dto/authentication.py +0 -108
- unrealon_sdk/src/dto/cache.py +0 -208
- unrealon_sdk/src/dto/common.py +0 -19
- unrealon_sdk/src/dto/concurrency.py +0 -393
- unrealon_sdk/src/dto/events.py +0 -108
- unrealon_sdk/src/dto/health.py +0 -339
- unrealon_sdk/src/dto/load_balancing.py +0 -336
- unrealon_sdk/src/dto/logging.py +0 -230
- unrealon_sdk/src/dto/performance.py +0 -165
- unrealon_sdk/src/dto/rate_limiting.py +0 -295
- unrealon_sdk/src/dto/resource_pooling.py +0 -128
- unrealon_sdk/src/dto/structured_logging.py +0 -112
- unrealon_sdk/src/dto/task_scheduling.py +0 -121
- unrealon_sdk/src/dto/websocket.py +0 -55
- unrealon_sdk/src/enterprise/__init__.py +0 -59
- unrealon_sdk/src/enterprise/authentication.py +0 -401
- unrealon_sdk/src/enterprise/cache_manager.py +0 -578
- unrealon_sdk/src/enterprise/error_recovery.py +0 -494
- unrealon_sdk/src/enterprise/event_system.py +0 -549
- unrealon_sdk/src/enterprise/health_monitor.py +0 -747
- unrealon_sdk/src/enterprise/load_balancer.py +0 -964
- unrealon_sdk/src/enterprise/logging/__init__.py +0 -68
- unrealon_sdk/src/enterprise/logging/cleanup.py +0 -156
- unrealon_sdk/src/enterprise/logging/development.py +0 -744
- unrealon_sdk/src/enterprise/logging/service.py +0 -410
- unrealon_sdk/src/enterprise/multithreading_manager.py +0 -853
- unrealon_sdk/src/enterprise/performance_monitor.py +0 -539
- unrealon_sdk/src/enterprise/proxy_manager.py +0 -696
- unrealon_sdk/src/enterprise/rate_limiter.py +0 -652
- unrealon_sdk/src/enterprise/resource_pool.py +0 -763
- unrealon_sdk/src/enterprise/task_scheduler.py +0 -709
- unrealon_sdk/src/internal/__init__.py +0 -10
- unrealon_sdk/src/internal/command_router.py +0 -497
- unrealon_sdk/src/internal/connection_manager.py +0 -397
- unrealon_sdk/src/internal/http_client.py +0 -446
- unrealon_sdk/src/internal/websocket_client.py +0 -420
- unrealon_sdk/src/provider.py +0 -471
- unrealon_sdk/src/utils.py +0 -234
- /unrealon_browser/{src/cli → cli}/__init__.py +0 -0
- /unrealon_browser/{src/cli → cli}/interactive_mode.py +0 -0
- /unrealon_browser/{src/cli → cli}/main.py +0 -0
- /unrealon_browser/{src/core → core}/__init__.py +0 -0
- /unrealon_browser/{src/dto → dto}/__init__.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/config.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/core.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/dataclasses.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/detection.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/enums.py +0 -0
- /unrealon_browser/{src/dto → dto}/models/statistics.py +0 -0
- /unrealon_browser/{src/managers → managers}/__init__.py +0 -0
- /unrealon_browser/{src/managers → managers}/stealth.py +0 -0
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
LLM-specific Event Types and Context
|
|
3
|
-
|
|
4
|
-
Extends the SDK logging system with AI/LLM specific event types and context models.
|
|
5
|
-
Focused on tracking LLM operations, costs, performance, and analysis results.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from enum import Enum
|
|
9
|
-
from typing import Optional, Dict, Any, List
|
|
10
|
-
from pydantic import BaseModel, Field, ConfigDict
|
|
11
|
-
from unrealon_sdk.src.dto.logging import SDKContext, SDKEventType
|
|
12
|
-
|
|
13
|
-
# Use SDK event types directly instead of creating new ones
|
|
14
|
-
class LLMEventType(str, Enum):
|
|
15
|
-
"""LLM-specific event types mapped to SDK event types for compatibility."""
|
|
16
|
-
|
|
17
|
-
# LLM Client Events (mapped to SDK events)
|
|
18
|
-
LLM_CLIENT_INITIALIZED = SDKEventType.COMPONENT_CREATED.value
|
|
19
|
-
LLM_REQUEST_STARTED = SDKEventType.API_CALL_STARTED.value
|
|
20
|
-
LLM_REQUEST_COMPLETED = SDKEventType.API_CALL_COMPLETED.value
|
|
21
|
-
LLM_REQUEST_FAILED = SDKEventType.API_CALL_FAILED.value
|
|
22
|
-
LLM_REQUEST_RETRIED = SDKEventType.CONNECTION_RETRY.value
|
|
23
|
-
LLM_REQUEST_CACHED = SDKEventType.PERFORMANCE_OPTIMIZATION_APPLIED.value
|
|
24
|
-
|
|
25
|
-
# Cost Tracking Events (mapped to SDK events)
|
|
26
|
-
COST_CALCULATED = SDKEventType.PERFORMANCE_METRIC_COLLECTED.value
|
|
27
|
-
COST_LIMIT_WARNING = SDKEventType.PERFORMANCE_THRESHOLD_EXCEEDED.value
|
|
28
|
-
COST_LIMIT_EXCEEDED = SDKEventType.ERROR_DETECTED.value
|
|
29
|
-
DAILY_BUDGET_RESET = SDKEventType.DEBUG_CHECKPOINT.value
|
|
30
|
-
|
|
31
|
-
# Token Management Events (mapped to SDK events)
|
|
32
|
-
TOKENS_COUNTED = SDKEventType.PERFORMANCE_METRIC_COLLECTED.value
|
|
33
|
-
TOKEN_OPTIMIZATION_APPLIED = SDKEventType.PERFORMANCE_OPTIMIZATION_APPLIED.value
|
|
34
|
-
TOKEN_LIMIT_EXCEEDED = SDKEventType.ERROR_DETECTED.value
|
|
35
|
-
|
|
36
|
-
# HTML Analysis Events (mapped to SDK events)
|
|
37
|
-
HTML_ANALYSIS_STARTED = SDKEventType.COMMAND_RECEIVED.value
|
|
38
|
-
HTML_ANALYSIS_COMPLETED = SDKEventType.COMMAND_COMPLETED.value
|
|
39
|
-
HTML_CLEANING_APPLIED = SDKEventType.PERFORMANCE_OPTIMIZATION_APPLIED.value
|
|
40
|
-
SELECTOR_GENERATED = SDKEventType.COMMAND_COMPLETED.value
|
|
41
|
-
SELECTOR_VALIDATED = SDKEventType.PYDANTIC_MODEL_VALIDATION.value
|
|
42
|
-
PATTERN_EXTRACTED = SDKEventType.COMMAND_COMPLETED.value
|
|
43
|
-
|
|
44
|
-
# Translation Events (mapped to SDK events)
|
|
45
|
-
TRANSLATION_STARTED = SDKEventType.COMMAND_RECEIVED.value
|
|
46
|
-
TRANSLATION_COMPLETED = SDKEventType.COMMAND_COMPLETED.value
|
|
47
|
-
LANGUAGE_DETECTED = SDKEventType.DEBUG_CHECKPOINT.value
|
|
48
|
-
|
|
49
|
-
# Schema Generation Events (mapped to SDK events)
|
|
50
|
-
SCHEMA_GENERATION_STARTED = SDKEventType.COMMAND_RECEIVED.value
|
|
51
|
-
SCHEMA_GENERATION_COMPLETED = SDKEventType.COMMAND_COMPLETED.value
|
|
52
|
-
TYPE_CONVERSION_APPLIED = SDKEventType.PERFORMANCE_OPTIMIZATION_APPLIED.value
|
|
53
|
-
|
|
54
|
-
# Cache Events (mapped to SDK events)
|
|
55
|
-
CACHE_HIT = SDKEventType.PERFORMANCE_OPTIMIZATION_APPLIED.value
|
|
56
|
-
CACHE_MISS = SDKEventType.DEBUG_CHECKPOINT.value
|
|
57
|
-
RESPONSE_CACHED = SDKEventType.PERFORMANCE_OPTIMIZATION_APPLIED.value
|
|
58
|
-
|
|
59
|
-
# Models Cache Events (mapped to SDK events)
|
|
60
|
-
MODELS_CACHE_UPDATED = SDKEventType.PERFORMANCE_OPTIMIZATION_APPLIED.value
|
|
61
|
-
|
|
62
|
-
# Performance Events (mapped to SDK events)
|
|
63
|
-
HTML_SIZE_OPTIMIZED = SDKEventType.PERFORMANCE_OPTIMIZATION_APPLIED.value
|
|
64
|
-
BATCH_PROCESSING_STARTED = SDKEventType.COMMAND_RECEIVED.value
|
|
65
|
-
BATCH_PROCESSING_COMPLETED = SDKEventType.COMMAND_COMPLETED.value
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
class LLMContext(SDKContext):
|
|
69
|
-
"""Extended context for LLM operations."""
|
|
70
|
-
|
|
71
|
-
# LLM Provider Information
|
|
72
|
-
provider: Optional[str] = Field(None, description="LLM provider (openrouter, openai, etc.)")
|
|
73
|
-
model: Optional[str] = Field(None, description="Model used for request")
|
|
74
|
-
|
|
75
|
-
# Request Details
|
|
76
|
-
request_id: Optional[str] = Field(None, description="Unique request identifier")
|
|
77
|
-
prompt_tokens: Optional[int] = Field(None, description="Number of input tokens")
|
|
78
|
-
completion_tokens: Optional[int] = Field(None, description="Number of output tokens")
|
|
79
|
-
total_tokens: Optional[int] = Field(None, description="Total tokens used")
|
|
80
|
-
|
|
81
|
-
# Cost Information
|
|
82
|
-
cost_usd: Optional[float] = Field(None, description="Request cost in USD")
|
|
83
|
-
daily_cost_usd: Optional[float] = Field(None, description="Total daily cost in USD")
|
|
84
|
-
|
|
85
|
-
# HTML Analysis Context
|
|
86
|
-
html_size_bytes: Optional[int] = Field(None, description="Original HTML size in bytes")
|
|
87
|
-
cleaned_html_size_bytes: Optional[int] = Field(None, description="Cleaned HTML size in bytes")
|
|
88
|
-
target_elements: Optional[List[str]] = Field(None, description="Target elements for extraction")
|
|
89
|
-
selectors_generated: Optional[int] = Field(None, description="Number of selectors generated")
|
|
90
|
-
confidence_score: Optional[float] = Field(None, description="Analysis confidence score")
|
|
91
|
-
|
|
92
|
-
# Translation Context
|
|
93
|
-
source_language: Optional[str] = Field(None, description="Source language detected")
|
|
94
|
-
target_language: Optional[str] = Field(None, description="Target language for translation")
|
|
95
|
-
text_length: Optional[int] = Field(None, description="Length of text to translate")
|
|
96
|
-
|
|
97
|
-
# Schema Context
|
|
98
|
-
schema_type: Optional[str] = Field(None, description="Type of schema generated (pydantic, typescript, etc.)")
|
|
99
|
-
fields_count: Optional[int] = Field(None, description="Number of fields in schema")
|
|
100
|
-
|
|
101
|
-
# Performance Metrics
|
|
102
|
-
cache_hit_rate: Optional[float] = Field(None, description="Cache hit rate percentage")
|
|
103
|
-
optimization_applied: Optional[str] = Field(None, description="Type of optimization applied")
|
|
104
|
-
|
|
105
|
-
model_config = ConfigDict(
|
|
106
|
-
extra="allow" # Allow additional fields for flexibility
|
|
107
|
-
)
|
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
LLM Logger - Specialized logging for AI operations
|
|
3
|
-
|
|
4
|
-
Wraps the SDK DevelopmentLogger with LLM-specific convenience methods.
|
|
5
|
-
Provides structured logging for AI operations, cost tracking, and performance monitoring.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import asyncio
|
|
9
|
-
from typing import Optional, Dict, Any, List
|
|
10
|
-
from datetime import datetime, timezone
|
|
11
|
-
|
|
12
|
-
from unrealon_sdk.src.enterprise.logging.development import (
|
|
13
|
-
DevelopmentLogger,
|
|
14
|
-
initialize_development_logger,
|
|
15
|
-
get_development_logger
|
|
16
|
-
)
|
|
17
|
-
from unrealon_sdk.src.dto.logging import SDKEventType, SDKSeverity, SDKContext
|
|
18
|
-
|
|
19
|
-
from .llm_events import LLMEventType, LLMContext
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class LLMLogger:
|
|
23
|
-
"""
|
|
24
|
-
Specialized logger for LLM operations.
|
|
25
|
-
|
|
26
|
-
Wraps the SDK DevelopmentLogger with convenience methods for:
|
|
27
|
-
- LLM request/response logging
|
|
28
|
-
- Cost tracking and budget monitoring
|
|
29
|
-
- HTML analysis operations
|
|
30
|
-
- Token counting and optimization
|
|
31
|
-
- Performance metrics
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
def __init__(self, dev_logger: Optional[DevelopmentLogger] = None):
|
|
35
|
-
"""Initialize LLM logger with optional development logger."""
|
|
36
|
-
self._dev_logger = dev_logger or get_development_logger()
|
|
37
|
-
if not self._dev_logger:
|
|
38
|
-
raise RuntimeError(
|
|
39
|
-
"No development logger available. Call initialize_llm_logger() first."
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
# LLM Request Logging
|
|
43
|
-
def log_llm_request_start(
|
|
44
|
-
self,
|
|
45
|
-
provider: str,
|
|
46
|
-
model: str,
|
|
47
|
-
prompt_tokens: int,
|
|
48
|
-
request_id: Optional[str] = None,
|
|
49
|
-
details: Optional[Dict[str, Any]] = None,
|
|
50
|
-
) -> None:
|
|
51
|
-
"""Log start of LLM request."""
|
|
52
|
-
context = SDKContext(
|
|
53
|
-
component_name="LLMClient",
|
|
54
|
-
layer_name="UnrealOn_LLM",
|
|
55
|
-
correlation_id=request_id,
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
# Add LLM-specific details
|
|
59
|
-
llm_details = details or {}
|
|
60
|
-
llm_details.update({
|
|
61
|
-
"provider": provider,
|
|
62
|
-
"model": model,
|
|
63
|
-
"prompt_tokens": prompt_tokens,
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
self._dev_logger.log_info(
|
|
67
|
-
LLMEventType.LLM_REQUEST_STARTED,
|
|
68
|
-
f"Starting LLM request to {provider}/{model} ({prompt_tokens} tokens)",
|
|
69
|
-
context=context,
|
|
70
|
-
details=details,
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
def log_llm_request_completed(
|
|
74
|
-
self,
|
|
75
|
-
provider: str,
|
|
76
|
-
model: str,
|
|
77
|
-
prompt_tokens: int,
|
|
78
|
-
completion_tokens: int,
|
|
79
|
-
cost_usd: float,
|
|
80
|
-
duration_ms: float,
|
|
81
|
-
request_id: Optional[str] = None,
|
|
82
|
-
cached: bool = False,
|
|
83
|
-
details: Optional[Dict[str, Any]] = None,
|
|
84
|
-
) -> None:
|
|
85
|
-
"""Log successful LLM request completion."""
|
|
86
|
-
context = LLMContext()
|
|
87
|
-
|
|
88
|
-
message = f"LLM request completed: {provider}/{model}"
|
|
89
|
-
if cached:
|
|
90
|
-
message += " (cached)"
|
|
91
|
-
message += f" - {prompt_tokens + completion_tokens} tokens, ${cost_usd:.4f}"
|
|
92
|
-
|
|
93
|
-
event_type = LLMEventType.LLM_REQUEST_CACHED if cached else LLMEventType.LLM_REQUEST_COMPLETED
|
|
94
|
-
|
|
95
|
-
self._dev_logger.log_info(
|
|
96
|
-
event_type,
|
|
97
|
-
message,
|
|
98
|
-
context=context,
|
|
99
|
-
details=details,
|
|
100
|
-
duration_ms=duration_ms,
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
def log_llm_response_received(
|
|
104
|
-
self,
|
|
105
|
-
provider: str,
|
|
106
|
-
model: str,
|
|
107
|
-
completion_tokens: int,
|
|
108
|
-
total_tokens: int,
|
|
109
|
-
cost_usd: float,
|
|
110
|
-
request_id: Optional[str] = None,
|
|
111
|
-
details: Optional[Dict[str, Any]] = None,
|
|
112
|
-
) -> None:
|
|
113
|
-
"""Log LLM response received."""
|
|
114
|
-
context = LLMContext()
|
|
115
|
-
|
|
116
|
-
# Add response details
|
|
117
|
-
llm_details = details or {}
|
|
118
|
-
llm_details.update({
|
|
119
|
-
"provider": provider,
|
|
120
|
-
"model": model,
|
|
121
|
-
"completion_tokens": completion_tokens,
|
|
122
|
-
"total_tokens": total_tokens,
|
|
123
|
-
"cost_usd": cost_usd,
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
self._dev_logger.log_info(
|
|
127
|
-
LLMEventType.LLM_REQUEST_COMPLETED,
|
|
128
|
-
f"LLM response received: {provider}/{model} - {total_tokens} tokens, ${cost_usd:.4f}",
|
|
129
|
-
context=context,
|
|
130
|
-
details=llm_details,
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
def log_llm_request_failed(
|
|
134
|
-
self,
|
|
135
|
-
provider: str,
|
|
136
|
-
model: str,
|
|
137
|
-
error_message: str,
|
|
138
|
-
request_id: Optional[str] = None,
|
|
139
|
-
retry_count: Optional[int] = None,
|
|
140
|
-
exception: Optional[Exception] = None,
|
|
141
|
-
details: Optional[Dict[str, Any]] = None,
|
|
142
|
-
) -> None:
|
|
143
|
-
"""Log failed LLM request."""
|
|
144
|
-
context = LLMContext()
|
|
145
|
-
|
|
146
|
-
message = f"LLM request failed: {provider}/{model}"
|
|
147
|
-
if retry_count is not None:
|
|
148
|
-
message += f" (retry {retry_count})"
|
|
149
|
-
|
|
150
|
-
self._dev_logger.log_error(
|
|
151
|
-
LLMEventType.LLM_REQUEST_FAILED,
|
|
152
|
-
message,
|
|
153
|
-
context=context,
|
|
154
|
-
details=details,
|
|
155
|
-
error_message=error_message,
|
|
156
|
-
exception=exception,
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
# Cost Tracking
|
|
160
|
-
def log_cost_tracking(
|
|
161
|
-
self,
|
|
162
|
-
operation_cost_usd: float,
|
|
163
|
-
daily_total_usd: float,
|
|
164
|
-
daily_limit_usd: float,
|
|
165
|
-
model: Optional[str] = None,
|
|
166
|
-
details: Optional[Dict[str, Any]] = None,
|
|
167
|
-
) -> None:
|
|
168
|
-
"""Log cost tracking information."""
|
|
169
|
-
context = LLMContext()
|
|
170
|
-
|
|
171
|
-
utilization = (daily_total_usd / daily_limit_usd) * 100
|
|
172
|
-
|
|
173
|
-
if utilization >= 90:
|
|
174
|
-
severity = SDKSeverity.WARNING
|
|
175
|
-
event_type = LLMEventType.COST_LIMIT_WARNING
|
|
176
|
-
message = f"Cost limit warning: ${daily_total_usd:.4f}/${daily_limit_usd:.2f} ({utilization:.1f}%)"
|
|
177
|
-
elif utilization >= 100:
|
|
178
|
-
severity = SDKSeverity.ERROR
|
|
179
|
-
event_type = LLMEventType.COST_LIMIT_EXCEEDED
|
|
180
|
-
message = f"Cost limit exceeded: ${daily_total_usd:.4f}/${daily_limit_usd:.2f}"
|
|
181
|
-
else:
|
|
182
|
-
severity = SDKSeverity.DEBUG
|
|
183
|
-
event_type = LLMEventType.COST_CALCULATED
|
|
184
|
-
message = f"Cost tracked: +${operation_cost_usd:.4f} (daily: ${daily_total_usd:.4f}/${daily_limit_usd:.2f})"
|
|
185
|
-
|
|
186
|
-
self._dev_logger._log_event(
|
|
187
|
-
event_type=event_type,
|
|
188
|
-
message=message,
|
|
189
|
-
severity=severity,
|
|
190
|
-
context=context,
|
|
191
|
-
details=details,
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
# HTML Analysis Logging
|
|
195
|
-
def log_html_analysis_start(
|
|
196
|
-
self,
|
|
197
|
-
html_size_bytes: int,
|
|
198
|
-
target_elements: List[str],
|
|
199
|
-
analysis_id: Optional[str] = None,
|
|
200
|
-
details: Optional[Dict[str, Any]] = None,
|
|
201
|
-
) -> None:
|
|
202
|
-
"""Log start of HTML analysis."""
|
|
203
|
-
context = SDKContext(
|
|
204
|
-
correlation_id=analysis_id,
|
|
205
|
-
component_name="HTMLAnalyzer",
|
|
206
|
-
layer_name="UnrealOn_LLM"
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
# Add LLM-specific details to the details dict
|
|
210
|
-
llm_details = details or {}
|
|
211
|
-
llm_details.update({
|
|
212
|
-
"html_size_bytes": html_size_bytes,
|
|
213
|
-
"target_elements": target_elements,
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
self._dev_logger.log_info(
|
|
217
|
-
LLMEventType.HTML_ANALYSIS_STARTED,
|
|
218
|
-
f"Starting HTML analysis: {html_size_bytes:,} bytes, targeting {len(target_elements)} elements",
|
|
219
|
-
context=context,
|
|
220
|
-
details=llm_details,
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
def log_html_analysis_completed(
|
|
224
|
-
self,
|
|
225
|
-
selectors_generated: int,
|
|
226
|
-
confidence_score: float,
|
|
227
|
-
analysis_id: Optional[str] = None,
|
|
228
|
-
duration_ms: Optional[float] = None,
|
|
229
|
-
details: Optional[Dict[str, Any]] = None,
|
|
230
|
-
) -> None:
|
|
231
|
-
"""Log successful HTML analysis completion."""
|
|
232
|
-
context = LLMContext()
|
|
233
|
-
|
|
234
|
-
self._dev_logger.log_info(
|
|
235
|
-
LLMEventType.HTML_ANALYSIS_COMPLETED,
|
|
236
|
-
f"HTML analysis completed: {selectors_generated} selectors, {confidence_score:.2f} confidence",
|
|
237
|
-
context=context,
|
|
238
|
-
details=details,
|
|
239
|
-
duration_ms=duration_ms,
|
|
240
|
-
)
|
|
241
|
-
|
|
242
|
-
def log_html_cleaning(
|
|
243
|
-
self,
|
|
244
|
-
original_size_bytes: int,
|
|
245
|
-
cleaned_size_bytes: int,
|
|
246
|
-
optimization_type: str,
|
|
247
|
-
details: Optional[Dict[str, Any]] = None,
|
|
248
|
-
) -> None:
|
|
249
|
-
"""Log HTML cleaning and optimization."""
|
|
250
|
-
reduction_pct = ((original_size_bytes - cleaned_size_bytes) / original_size_bytes) * 100
|
|
251
|
-
|
|
252
|
-
context = LLMContext()
|
|
253
|
-
|
|
254
|
-
self._dev_logger.log_debug(
|
|
255
|
-
LLMEventType.HTML_CLEANING_APPLIED,
|
|
256
|
-
f"HTML cleaned: {original_size_bytes:,} → {cleaned_size_bytes:,} bytes ({reduction_pct:.1f}% reduction)",
|
|
257
|
-
context=context,
|
|
258
|
-
details={
|
|
259
|
-
"html_size_bytes": original_size_bytes,
|
|
260
|
-
"cleaned_html_size_bytes": cleaned_size_bytes,
|
|
261
|
-
"original_size_bytes": original_size_bytes,
|
|
262
|
-
"cleaned_size_bytes": cleaned_size_bytes,
|
|
263
|
-
"reduction_percentage": reduction_pct,
|
|
264
|
-
"optimization_type": optimization_type,
|
|
265
|
-
"optimization_applied": optimization_type,
|
|
266
|
-
**(details or {})
|
|
267
|
-
}
|
|
268
|
-
)
|
|
269
|
-
|
|
270
|
-
def log_html_analysis_failed(
|
|
271
|
-
self,
|
|
272
|
-
error_message: str,
|
|
273
|
-
analysis_id: Optional[str] = None,
|
|
274
|
-
details: Optional[Dict[str, Any]] = None,
|
|
275
|
-
) -> None:
|
|
276
|
-
"""Log failed HTML analysis."""
|
|
277
|
-
context = SDKContext(
|
|
278
|
-
correlation_id=analysis_id,
|
|
279
|
-
component_name="HTMLAnalyzer",
|
|
280
|
-
layer_name="UnrealOn_LLM"
|
|
281
|
-
)
|
|
282
|
-
|
|
283
|
-
self._dev_logger.log_error(
|
|
284
|
-
LLMEventType.LLM_REQUEST_FAILED,
|
|
285
|
-
f"HTML analysis failed: {error_message}",
|
|
286
|
-
context=context,
|
|
287
|
-
details=details,
|
|
288
|
-
error_message=error_message,
|
|
289
|
-
)
|
|
290
|
-
|
|
291
|
-
# Token Management
|
|
292
|
-
def log_token_counting(
|
|
293
|
-
self,
|
|
294
|
-
text_length: int,
|
|
295
|
-
token_count: int,
|
|
296
|
-
model: str,
|
|
297
|
-
optimization_applied: bool = False,
|
|
298
|
-
details: Optional[Dict[str, Any]] = None,
|
|
299
|
-
) -> None:
|
|
300
|
-
"""Log token counting operations."""
|
|
301
|
-
context = LLMContext()
|
|
302
|
-
|
|
303
|
-
event_type = LLMEventType.TOKEN_OPTIMIZATION_APPLIED if optimization_applied else LLMEventType.TOKENS_COUNTED
|
|
304
|
-
message = f"Tokens counted: {text_length:,} chars → {token_count:,} tokens ({model})"
|
|
305
|
-
if optimization_applied:
|
|
306
|
-
message += " [optimized]"
|
|
307
|
-
|
|
308
|
-
self._dev_logger.log_debug(
|
|
309
|
-
event_type,
|
|
310
|
-
message,
|
|
311
|
-
context=context,
|
|
312
|
-
details=details,
|
|
313
|
-
)
|
|
314
|
-
|
|
315
|
-
# Translation Logging
|
|
316
|
-
def log_translation(
|
|
317
|
-
self,
|
|
318
|
-
source_lang: str,
|
|
319
|
-
target_lang: str,
|
|
320
|
-
text_length: int,
|
|
321
|
-
success: bool = True,
|
|
322
|
-
duration_ms: Optional[float] = None,
|
|
323
|
-
error_message: Optional[str] = None,
|
|
324
|
-
details: Optional[Dict[str, Any]] = None,
|
|
325
|
-
) -> None:
|
|
326
|
-
"""Log translation operations."""
|
|
327
|
-
context = LLMContext()
|
|
328
|
-
|
|
329
|
-
if success:
|
|
330
|
-
self._dev_logger.log_info(
|
|
331
|
-
LLMEventType.TRANSLATION_COMPLETED,
|
|
332
|
-
f"Translation completed: {source_lang} → {target_lang} ({text_length:,} chars)",
|
|
333
|
-
context=context,
|
|
334
|
-
details=details,
|
|
335
|
-
duration_ms=duration_ms,
|
|
336
|
-
)
|
|
337
|
-
else:
|
|
338
|
-
self._dev_logger.log_error(
|
|
339
|
-
LLMEventType.TRANSLATION_COMPLETED,
|
|
340
|
-
f"Translation failed: {source_lang} → {target_lang}",
|
|
341
|
-
context=context,
|
|
342
|
-
details=details,
|
|
343
|
-
error_message=error_message,
|
|
344
|
-
)
|
|
345
|
-
|
|
346
|
-
# Performance Metrics
|
|
347
|
-
def log_performance_metric(
|
|
348
|
-
self,
|
|
349
|
-
metric_name: str,
|
|
350
|
-
value: float,
|
|
351
|
-
unit: str,
|
|
352
|
-
threshold: Optional[float] = None,
|
|
353
|
-
context: Optional[LLMContext] = None,
|
|
354
|
-
details: Optional[Dict[str, Any]] = None,
|
|
355
|
-
) -> None:
|
|
356
|
-
"""Log performance metrics with LLM context."""
|
|
357
|
-
# Use the underlying dev logger's performance metric method
|
|
358
|
-
self._dev_logger.log_performance_metric(
|
|
359
|
-
metric_name=metric_name,
|
|
360
|
-
value=value,
|
|
361
|
-
unit=unit,
|
|
362
|
-
threshold=threshold,
|
|
363
|
-
context=context,
|
|
364
|
-
)
|
|
365
|
-
|
|
366
|
-
# Cache Operations
|
|
367
|
-
def log_cache_operation(
|
|
368
|
-
self,
|
|
369
|
-
operation: str, # hit, miss, store
|
|
370
|
-
cache_key: str,
|
|
371
|
-
hit_rate: Optional[float] = None,
|
|
372
|
-
details: Optional[Dict[str, Any]] = None,
|
|
373
|
-
) -> None:
|
|
374
|
-
"""Log cache operations."""
|
|
375
|
-
context = LLMContext()
|
|
376
|
-
|
|
377
|
-
event_type_map = {
|
|
378
|
-
"hit": LLMEventType.CACHE_HIT,
|
|
379
|
-
"miss": LLMEventType.CACHE_MISS,
|
|
380
|
-
"store": LLMEventType.RESPONSE_CACHED,
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
event_type = event_type_map.get(operation, LLMEventType.CACHE_HIT)
|
|
384
|
-
|
|
385
|
-
self._dev_logger.log_debug(
|
|
386
|
-
event_type,
|
|
387
|
-
f"Cache {operation}: {cache_key[:50]}{'...' if len(cache_key) > 50 else ''}",
|
|
388
|
-
context=context,
|
|
389
|
-
details=details,
|
|
390
|
-
)
|
|
391
|
-
|
|
392
|
-
# Layer and Component Context (delegated to dev logger)
|
|
393
|
-
def set_layer_context(self, layer_name: str) -> None:
|
|
394
|
-
"""Set current layer context."""
|
|
395
|
-
self._dev_logger.set_layer_context(layer_name)
|
|
396
|
-
|
|
397
|
-
def set_component_context(self, component_name: str) -> None:
|
|
398
|
-
"""Set current component context."""
|
|
399
|
-
self._dev_logger.set_component_context(component_name)
|
|
400
|
-
|
|
401
|
-
def start_operation(self, operation_id: str, description: str) -> None:
|
|
402
|
-
"""Start tracking a long-running operation."""
|
|
403
|
-
self._dev_logger.start_operation(operation_id, description)
|
|
404
|
-
|
|
405
|
-
def complete_operation(self, operation_id: str, description: str, success: bool = True) -> None:
|
|
406
|
-
"""Complete a tracked operation."""
|
|
407
|
-
self._dev_logger.complete_operation(operation_id, description, success)
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
# Global LLM logger instance
|
|
411
|
-
_llm_logger: Optional[LLMLogger] = None
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
def initialize_llm_logger(
|
|
415
|
-
session_id: Optional[str] = None,
|
|
416
|
-
log_level: str = "INFO",
|
|
417
|
-
enable_console: bool = True,
|
|
418
|
-
enable_websocket: bool = True,
|
|
419
|
-
) -> LLMLogger:
|
|
420
|
-
"""
|
|
421
|
-
Initialize global LLM logger.
|
|
422
|
-
|
|
423
|
-
Creates a development logger and wraps it with LLM-specific functionality.
|
|
424
|
-
"""
|
|
425
|
-
global _llm_logger
|
|
426
|
-
|
|
427
|
-
# Map string log levels to SDK severity
|
|
428
|
-
level_map = {
|
|
429
|
-
"TRACE": SDKSeverity.TRACE,
|
|
430
|
-
"DEBUG": SDKSeverity.DEBUG,
|
|
431
|
-
"INFO": SDKSeverity.INFO,
|
|
432
|
-
"WARNING": SDKSeverity.WARNING,
|
|
433
|
-
"ERROR": SDKSeverity.ERROR,
|
|
434
|
-
"CRITICAL": SDKSeverity.CRITICAL,
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
sdk_level = level_map.get(log_level.upper(), SDKSeverity.INFO)
|
|
438
|
-
|
|
439
|
-
# Initialize or get existing dev logger
|
|
440
|
-
dev_logger = get_development_logger()
|
|
441
|
-
if not dev_logger:
|
|
442
|
-
dev_logger = initialize_development_logger(
|
|
443
|
-
session_id=session_id,
|
|
444
|
-
log_level=sdk_level,
|
|
445
|
-
enable_console=enable_console,
|
|
446
|
-
enable_websocket=enable_websocket,
|
|
447
|
-
)
|
|
448
|
-
|
|
449
|
-
# Set LLM layer context
|
|
450
|
-
dev_logger.set_layer_context("UnrealOn_LLM")
|
|
451
|
-
|
|
452
|
-
_llm_logger = LLMLogger(dev_logger)
|
|
453
|
-
|
|
454
|
-
# Log initialization
|
|
455
|
-
_llm_logger._dev_logger.log_info(
|
|
456
|
-
LLMEventType.LLM_CLIENT_INITIALIZED,
|
|
457
|
-
"LLM Logger initialized with SDK integration",
|
|
458
|
-
context=LLMContext(),
|
|
459
|
-
)
|
|
460
|
-
|
|
461
|
-
return _llm_logger
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
def get_llm_logger() -> Optional[LLMLogger]:
|
|
465
|
-
"""Get global LLM logger instance."""
|
|
466
|
-
return _llm_logger
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
LLM Managers
|
|
3
|
-
|
|
4
|
-
Modular components for LLM client functionality.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from .cache_manager import CacheManager
|
|
8
|
-
from .cost_manager import CostManager
|
|
9
|
-
from .request_manager import RequestManager
|
|
10
|
-
|
|
11
|
-
__all__ = [
|
|
12
|
-
"CacheManager",
|
|
13
|
-
"CostManager",
|
|
14
|
-
"RequestManager",
|
|
15
|
-
]
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Cache Manager
|
|
3
|
-
|
|
4
|
-
Manages LLM response caching with TTL and size limits.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import logging
|
|
8
|
-
from typing import Any, Dict, List, Optional
|
|
9
|
-
|
|
10
|
-
from cachetools import TTLCache
|
|
11
|
-
|
|
12
|
-
from unrealon_llm.src.dto import ChatMessage, LLMResponse
|
|
13
|
-
|
|
14
|
-
logger = logging.getLogger(__name__)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class CacheManager:
|
|
18
|
-
"""LLM response cache manager"""
|
|
19
|
-
|
|
20
|
-
def __init__(self, max_size: int = 100, ttl_seconds: int = 3600):
|
|
21
|
-
self.cache = TTLCache(maxsize=max_size, ttl=ttl_seconds)
|
|
22
|
-
self.enabled = True
|
|
23
|
-
|
|
24
|
-
def set_enabled(self, enabled: bool):
|
|
25
|
-
"""Enable or disable caching"""
|
|
26
|
-
self.enabled = enabled
|
|
27
|
-
if not enabled:
|
|
28
|
-
self.cache.clear()
|
|
29
|
-
|
|
30
|
-
def generate_cache_key(
|
|
31
|
-
self,
|
|
32
|
-
messages: List[ChatMessage],
|
|
33
|
-
model: str,
|
|
34
|
-
temperature: float,
|
|
35
|
-
response_format: Optional[str]
|
|
36
|
-
) -> str:
|
|
37
|
-
"""Generate cache key for request"""
|
|
38
|
-
messages_hash = hash(tuple((msg.role.value, msg.content) for msg in messages))
|
|
39
|
-
return f"{model}_{messages_hash}_{temperature}_{response_format}"
|
|
40
|
-
|
|
41
|
-
def get(self, cache_key: str) -> Optional[LLMResponse]:
|
|
42
|
-
"""Get cached response"""
|
|
43
|
-
if not self.enabled:
|
|
44
|
-
return None
|
|
45
|
-
|
|
46
|
-
return self.cache.get(cache_key)
|
|
47
|
-
|
|
48
|
-
def store(self, cache_key: str, response: LLMResponse):
|
|
49
|
-
"""Store response in cache"""
|
|
50
|
-
if not self.enabled:
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
self.cache[cache_key] = response
|
|
54
|
-
|
|
55
|
-
def clear(self):
|
|
56
|
-
"""Clear all cached responses"""
|
|
57
|
-
self.cache.clear()
|
|
58
|
-
|
|
59
|
-
def get_stats(self) -> Dict[str, Any]:
|
|
60
|
-
"""Get cache statistics"""
|
|
61
|
-
return {
|
|
62
|
-
"enabled": self.enabled,
|
|
63
|
-
"cache_size": len(self.cache),
|
|
64
|
-
"max_size": self.cache.maxsize,
|
|
65
|
-
"ttl_seconds": self.cache.ttl if hasattr(self.cache, 'ttl') else 0,
|
|
66
|
-
"cache_info": self.cache.currsize if hasattr(self.cache, 'currsize') else len(self.cache)
|
|
67
|
-
}
|