feat(devgen/providers): normalize token limit error handling
Add token limit error detection and formatting across all provider modules to surface clear diagnostics when context windows are exceeded, improving error messages and preventing silent failures. New Features - Introduce `is_token_limit_error` checks in Anthropic, Gemini, Hugging Face, Ollama, OpenAI, and OpenRouter providers. - Use `format_token_limit_error` to generate user‑friendly error messages for token limit overs. Enhancements - Centralize token limit error handling for consistent diagnostics across providers. - Explicitly re‑raise `RuntimeError` in Hugging Face to preserve original behavior. Bug Fixes - None
This commit is contained in:
6 files changed
+37
-1
No files matched your search
@@ -1,5 +1,7 @@
|
||||
from openai import OpenAI
|
||||
|
||||
from devgen.utils import format_token_limit_error, is_token_limit_error
|
||||
|
||||
|
||||
class OpenaiProvider:
|
||||
"""Generates a response string using the OpenAI ChatCompletion API based on the provided prompt and parameters. This method initializes an OpenAI client with the given API key, sends a chat completion request with specified model and additional parameters, and returns the content of the generated message.
|
||||
@@ -59,6 +61,8 @@ class OpenaiProvider:
|
||||
**kwargs,
|
||||
)
|
||||
except Exception as e:
|
||||
if is_token_limit_error(e):
|
||||
raise RuntimeError(format_token_limit_error("OpenAI", e)) from e
|
||||
raise RuntimeError(
|
||||
f"OpenAI request failed: {e}. "
|
||||
"Check the model name, API key permissions, and your account quota."
|
||||
|
||||
Reference in new issue
Block a user