refactor: provider HTTP dedup + fix context length false-positive#23
Conversation
…se-positive - Extract duplicated HTTP request/response logic from openai.rs and custom.rs into a shared http_base.rs HttpProvider. Both providers are now thin constructor wrappers (~500 lines removed). - Remove overly broad "max_tokens" pattern from is_context_length_error() that was misclassifying parameter validation errors as context length errors, triggering unnecessary fallbacks. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR delivers two targeted improvements: it extracts shared HTTP logic from Key changes:
Confidence Score: 4/5
Important Files Changed
Class Diagram%%{init: {'theme': 'neutral'}}%%
classDiagram
class LlmProvider {
<<trait>>
+chat_completion(messages, tools) Future~ChatMessage~
}
class HttpProvider {
-http: reqwest::Client
-api_key: String
-model: String
-base_url: String
-label: String
+new(api_key, model, base_url, label) HttpProvider
+with_base_url(url) HttpProvider
+completions_url() String
+chat_completion(messages, tools) Future~ChatMessage~
}
class OpenAiProvider {
<<factory>>
+new(api_key, model) HttpProvider
}
class CustomProvider {
<<factory>>
+new(api_key, model, base_url) HttpProvider
}
class AnthropicProvider {
-http: reqwest::Client
-api_key: String
-model: String
-base_url: String
+new(api_key, model) AnthropicProvider
+with_base_url(url) AnthropicProvider
+chat_completion(messages, tools) Future~ChatMessage~
}
LlmProvider <|.. HttpProvider : implements
LlmProvider <|.. AnthropicProvider : implements
OpenAiProvider ..> HttpProvider : creates
CustomProvider ..> HttpProvider : creates
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Point to crate::provider::http_base instead of the now-empty crate::provider::openai. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
openai.rsandcustom.rsinto a sharedhttp_base.rsHttpProvider. Both providers are now thin constructor wrappers (~500 lines removed, net -125 lines)."max_tokens"pattern fromis_context_length_error()that was misclassifying parameter validation errors (e.g., "max_tokens must be less than X") as context length errors, triggering unnecessary trajectory-clearing fallbacks. Flagged by Sentry in PR refactor: split large modules into focused submodules #16.Test plan
cargo test)🤖 Generated with Claude Code