-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Open
Labels
Description
Summary
litellm/files/main.py has significant code duplication. Each function (create_file, file_retrieve, file_delete, file_list, file_content) repeats nearly identical credential/configuration logic for each provider.
| Provider | create_file | file_retrieve | file_delete | file_list | file_content |
|---|---|---|---|---|---|
| OpenAI | ~20 lines | ~20 lines | ~20 lines | ~20 lines | ~20 lines |
| Azure | ~20 lines | ~20 lines | ~20 lines | ~20 lines | ~20 lines |
| Vertex | ~15 lines | - | - | - | ~15 lines |
| Anthropic | ~5 lines ✓ | ~5 lines ✓ | ~5 lines ✓ | ~5 lines ✓ | ~5 lines ✓ |
Estimated ~400+ lines of repeated code that could be reduced significantly with helpers.
Proposed Solution
Create get_api_credentials() helpers in each provider's common_utils.py, similar to what was done for Anthropic in PR #16594:
# Example: litellm/llms/openai/common_utils.py
class OpenAIModelInfo:
@staticmethod
def get_api_credentials(api_base=None, api_key=None, organization=None):
# centralized logic here
return api_base, api_key, organizationIn PR #16594, Anthropic's file operations were refactored:
- Before: ~60 lines of repeated credential logic
- After: ~20 lines using
AnthropicModelInfo.get_api_credentials()
The same approach could reduce OpenAI and Azure code by similar amounts.
Files
litellm/files/main.pylitellm/llms/openai/common_utils.pylitellm/llms/azure/common_utils.py