Files
markitect-main/markitect/llm/exceptions.py
tegwick fecc2fd4fa feat(llm): add LLM integration module with OpenRouter and Claude Code adapters
Implements markitect/llm/ package with concrete LLMAdapter implementations:
- OpenRouterAdapter: HTTP via urllib with retry/backoff on 429/5xx
- ClaudeCodeAdapter: subprocess-based Claude CLI with stdin piping
- Factory pattern: create_adapter("openrouter") or create_adapter("claude-code")
- API key resolution chain: constructor > env var > project-root key file
- 42 unit tests, 2 integration tests (gated on API key / CLI availability)

Also adds the infospace-with-history example with Wealth of Nations VSM
analysis pipeline, templates, schemas, source chapters, and processed
output for chapters 1-2. process_chapters.py now supports --provider
and --model flags for automatic LLM-driven processing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 01:17:58 +01:00

72 lines
1.8 KiB
Python

"""
LLM-specific exceptions.
Extends the MarkitectError hierarchy for LLM integration errors.
"""
from typing import Optional, Dict, Any
from markitect.exceptions import MarkitectError
class LLMError(MarkitectError):
"""Base exception for all LLM operations."""
pass
class LLMConfigurationError(LLMError):
"""Missing API key, invalid model name, or bad provider config."""
pass
class LLMAPIError(LLMError):
"""HTTP-level failure from an LLM provider API.
Attributes:
status_code: HTTP status code (e.g. 500, 502).
response_body: Raw response body text, if available.
"""
def __init__(
self,
message: str,
status_code: int = 0,
response_body: str = "",
cause: Optional[Exception] = None,
context: Optional[Dict[str, Any]] = None,
):
super().__init__(message, cause=cause, context=context)
self.status_code = status_code
self.response_body = response_body
class LLMRateLimitError(LLMAPIError):
"""429 Too Many Requests from the provider."""
pass
class LLMTimeoutError(LLMError):
"""Request or subprocess exceeded the configured timeout."""
pass
class LLMSubprocessError(LLMError):
"""Claude Code CLI subprocess failed.
Attributes:
return_code: Process exit code.
stderr: Captured stderr text.
"""
def __init__(
self,
message: str,
return_code: int = 1,
stderr: str = "",
cause: Optional[Exception] = None,
context: Optional[Dict[str, Any]] = None,
):
super().__init__(message, cause=cause, context=context)
self.return_code = return_code
self.stderr = stderr