Implement core infrastructure: - BaseClientMixin with retry logic and validation - FastGPTClient base class with httpx - ChatClient with 11 chat operation methods - AppClient for analytics and logs - Custom exceptions (APIError, AuthenticationError, etc.) - Package configuration (pyproject.toml, setup.py) - Documentation (README.md, CLAUDE.md) - Basic usage examples 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
"""FastGPT Client Exceptions."""
|
|
|
|
|
|
class FastGPTError(Exception):
|
|
"""Base exception for all FastGPT errors."""
|
|
|
|
def __init__(self, message: str, status_code: int = None, response_data: dict = None):
|
|
self.message = message
|
|
self.status_code = status_code
|
|
self.response_data = response_data or {}
|
|
super().__init__(self.message)
|
|
|
|
|
|
class APIError(FastGPTError):
|
|
"""General API error (4xx, 5xx responses)."""
|
|
|
|
pass
|
|
|
|
|
|
class AuthenticationError(FastGPTError):
|
|
"""Authentication failed (401)."""
|
|
|
|
pass
|
|
|
|
|
|
class RateLimitError(FastGPTError):
|
|
"""Rate limit exceeded (429)."""
|
|
|
|
def __init__(self, message: str, retry_after: str = None, status_code: int = None, response_data: dict = None):
|
|
super().__init__(message, status_code, response_data)
|
|
self.retry_after = retry_after
|
|
|
|
|
|
class ValidationError(FastGPTError):
|
|
"""Invalid request parameters (422)."""
|
|
|
|
pass
|
|
|
|
|
|
class StreamParseError(FastGPTError):
|
|
"""Error parsing streaming response."""
|
|
|
|
pass
|