Skip to content

Commit f97397f

Browse files
committed
modify accomplishment measure
1 parent a742478 commit f97397f

File tree

3 files changed

+229
-0
lines changed

3 files changed

+229
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
Error handling result structures for embedding model engine matching.
3+
4+
This module provides structured error handling for engine matching operations,
5+
allowing engines to provide detailed failure reasons and suggestions.
6+
"""
7+
8+
from dataclasses import dataclass
9+
from typing import Any, Dict, Optional
10+
11+
12+
@dataclass
13+
class MatchResult:
14+
"""
15+
Result of engine matching operation with detailed error information.
16+
17+
This class provides structured information about whether an engine can handle
18+
a specific model configuration, and if not, why and what alternatives exist.
19+
"""
20+
21+
is_match: bool
22+
reason: Optional[str] = None
23+
error_type: Optional[str] = None
24+
technical_details: Optional[str] = None
25+
26+
@classmethod
27+
def success(cls) -> "MatchResult":
28+
"""Create a successful match result."""
29+
return cls(is_match=True)
30+
31+
@classmethod
32+
def failure(
33+
cls,
34+
reason: str,
35+
error_type: Optional[str] = None,
36+
technical_details: Optional[str] = None,
37+
) -> "MatchResult":
38+
"""Create a failed match result with optional details."""
39+
return cls(
40+
is_match=False,
41+
reason=reason,
42+
error_type=error_type,
43+
technical_details=technical_details,
44+
)
45+
46+
def to_dict(self) -> Dict[str, Any]:
47+
"""Convert to dictionary for API responses."""
48+
result = {"is_match": self.is_match}
49+
if not self.is_match:
50+
if self.reason:
51+
result["reason"] = self.reason
52+
if self.error_type:
53+
result["error_type"] = self.error_type
54+
if self.technical_details:
55+
result["technical_details"] = self.technical_details
56+
return result
57+
58+
def to_error_string(self) -> str:
59+
"""Convert to error string for backward compatibility."""
60+
if self.is_match:
61+
return "Available"
62+
error_msg = self.reason or "Unknown error"
63+
return error_msg
64+
65+
66+
# Error type constants for better categorization
67+
class ErrorType:
68+
HARDWARE_REQUIREMENT = "hardware_requirement"
69+
OS_REQUIREMENT = "os_requirement"
70+
MODEL_FORMAT = "model_format"
71+
DEPENDENCY_MISSING = "dependency_missing"
72+
MODEL_COMPATIBILITY = "model_compatibility"
73+
DIMENSION_MISMATCH = "dimension_mismatch"
74+
VERSION_REQUIREMENT = "version_requirement"
75+
CONFIGURATION_ERROR = "configuration_error"
76+
ENGINE_UNAVAILABLE = "engine_unavailable"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
Error handling result structures for engine matching.
3+
4+
This module provides structured error handling for engine matching operations,
5+
allowing engines to provide detailed failure reasons and suggestions.
6+
"""
7+
8+
from dataclasses import dataclass
9+
from typing import Any, Dict, Optional
10+
11+
12+
@dataclass
13+
class MatchResult:
14+
"""
15+
Result of engine matching operation with detailed error information.
16+
17+
This class provides structured information about whether an engine can handle
18+
a specific model configuration, and if not, why and what alternatives exist.
19+
"""
20+
21+
is_match: bool
22+
reason: Optional[str] = None
23+
error_type: Optional[str] = None
24+
technical_details: Optional[str] = None
25+
26+
@classmethod
27+
def success(cls) -> "MatchResult":
28+
"""Create a successful match result."""
29+
return cls(is_match=True)
30+
31+
@classmethod
32+
def failure(
33+
cls,
34+
reason: str,
35+
error_type: Optional[str] = None,
36+
technical_details: Optional[str] = None,
37+
) -> "MatchResult":
38+
"""Create a failed match result with optional details."""
39+
return cls(
40+
is_match=False,
41+
reason=reason,
42+
error_type=error_type,
43+
technical_details=technical_details,
44+
)
45+
46+
def to_dict(self) -> Dict[str, Any]:
47+
"""Convert to dictionary for API responses."""
48+
result = {"is_match": self.is_match}
49+
if not self.is_match:
50+
if self.reason:
51+
result["reason"] = self.reason
52+
if self.error_type:
53+
result["error_type"] = self.error_type
54+
if self.technical_details:
55+
result["technical_details"] = self.technical_details
56+
return result
57+
58+
def to_error_string(self) -> str:
59+
"""Convert to error string for backward compatibility."""
60+
if self.is_match:
61+
return "Available"
62+
error_msg = self.reason or "Unknown error"
63+
return error_msg
64+
65+
66+
# Error type constants for better categorization
67+
class ErrorType:
68+
HARDWARE_REQUIREMENT = "hardware_requirement"
69+
OS_REQUIREMENT = "os_requirement"
70+
MODEL_FORMAT = "model_format"
71+
QUANTIZATION = "quantization"
72+
DEPENDENCY_MISSING = "dependency_missing"
73+
MODEL_COMPATIBILITY = "model_compatibility"
74+
ABILITY_MISMATCH = "ability_mismatch"
75+
VERSION_REQUIREMENT = "version_requirement"
76+
CONFIGURATION_ERROR = "configuration_error"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
Error handling result structures for rerank model engine matching.
3+
4+
This module provides structured error handling for engine matching operations,
5+
allowing engines to provide detailed failure reasons and suggestions.
6+
"""
7+
8+
from dataclasses import dataclass
9+
from typing import Any, Dict, Optional
10+
11+
12+
@dataclass
13+
class MatchResult:
14+
"""
15+
Result of engine matching operation with detailed error information.
16+
17+
This class provides structured information about whether an engine can handle
18+
a specific model configuration, and if not, why and what alternatives exist.
19+
"""
20+
21+
is_match: bool
22+
reason: Optional[str] = None
23+
error_type: Optional[str] = None
24+
technical_details: Optional[str] = None
25+
26+
@classmethod
27+
def success(cls) -> "MatchResult":
28+
"""Create a successful match result."""
29+
return cls(is_match=True)
30+
31+
@classmethod
32+
def failure(
33+
cls,
34+
reason: str,
35+
error_type: Optional[str] = None,
36+
technical_details: Optional[str] = None,
37+
) -> "MatchResult":
38+
"""Create a failed match result with optional details."""
39+
return cls(
40+
is_match=False,
41+
reason=reason,
42+
error_type=error_type,
43+
technical_details=technical_details,
44+
)
45+
46+
def to_dict(self) -> Dict[str, Any]:
47+
"""Convert to dictionary for API responses."""
48+
result = {"is_match": self.is_match}
49+
if not self.is_match:
50+
if self.reason:
51+
result["reason"] = self.reason
52+
if self.error_type:
53+
result["error_type"] = self.error_type
54+
if self.technical_details:
55+
result["technical_details"] = self.technical_details
56+
return result
57+
58+
def to_error_string(self) -> str:
59+
"""Convert to error string for backward compatibility."""
60+
if self.is_match:
61+
return "Available"
62+
error_msg = self.reason or "Unknown error"
63+
return error_msg
64+
65+
66+
# Error type constants for better categorization
67+
class ErrorType:
68+
HARDWARE_REQUIREMENT = "hardware_requirement"
69+
OS_REQUIREMENT = "os_requirement"
70+
MODEL_FORMAT = "model_format"
71+
DEPENDENCY_MISSING = "dependency_missing"
72+
MODEL_COMPATIBILITY = "model_compatibility"
73+
DIMENSION_MISMATCH = "dimension_mismatch"
74+
VERSION_REQUIREMENT = "version_requirement"
75+
CONFIGURATION_ERROR = "configuration_error"
76+
ENGINE_UNAVAILABLE = "engine_unavailable"
77+
RERANK_SPECIFIC = "rerank_specific"

0 commit comments

Comments
 (0)