Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use LiteLLM in place of ChatOpenAI #84

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Conversation

morganmcg1
Copy link
Member

@morganmcg1 morganmcg1 commented Dec 26, 2024

This PR adds a model-agnostic fallback system that allows using any model as a fallback for another model, with comprehensive error handling and testing.

Changes

  • Add model-agnostic fallback system in base ChatModel
  • Implement error handling with retryable errors
  • Add model tracking in responses
  • Add comprehensive test suite for fallback behavior
  • Update Gemini model to use new error handling system

Features

  • Support for cross-model fallbacks (e.g., Gemini -> OpenAI)
  • Retryable vs non-retryable error handling
  • Model tracking in responses
  • Fallback chains (multiple fallbacks)
  • Comprehensive test coverage

Example Usage

# Create models with fallback chain
final_fallback = OpenAIChatModel("gpt-3.5-turbo")
middle_fallback = GeminiChatModel("gemini-1.0-pro", fallback_model=final_fallback)
primary_model = GeminiChatModel("gemini-pro", fallback_model=middle_fallback)

# Response includes which model was used
response = primary_model.generate_response(messages)
print(f"Response from {response["model_used"]}: {response["content"]}")

- Add model-agnostic fallback system in base ChatModel
- Implement error handling with retryable errors
- Add model tracking in responses
- Add comprehensive test suite for fallback behavior
- Update Gemini model to use new error handling system
Copy link

socket-security bot commented Dec 26, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
pypi/[email protected] Transitive: environment, eval, filesystem, network, shell, unsafe +438 3.58 GB

View full report↗︎

- Remove temp files
- Update OpenAI model to use 'developer' role
- Keep existing prompt logic
- Use LiteLLM for provider-agnostic interface
- Handle OpenAI 'developer' role conversion
- Simple error handling with retryable errors
- Add comprehensive tests
- Use LiteLLM for provider-agnostic interface
- Support latest models:
  * OpenAI GPT-4 Turbo Mini (128K)
  * Gemini 2.0 Flash (1M)
  * Claude 3 Haiku (200K)
- Add comprehensive tests for:
  * Context window limits
  * Message format validation
  * Temperature validation
  * Error handling
  * Provider-specific message formats
- Remove custom fallback/retry logic
- Use litellm.completion fallbacks parameter
- Configure fallbacks in constructor
- Update tests to match LiteLLM behavior
- Remove custom message format handling (LiteLLM handles it)
- Remove custom retry/fallback logic (use LiteLLM's fallbacks param)
- Update tests to match LiteLLM behavior
- Remove custom error type handling
- Remove retryable flag (LiteLLM handles retries)
- Update tests to match simpler error handling
- Remove provider-specific model files (LiteLLM handles it)
- Remove token count tracking (not needed)
- Update tests to match simpler response format
- Match original ChatModel descriptor pattern
- Keep LiteLLM's provider-agnostic features
- Update tests to match descriptor pattern
- Keep RESPONSE_SYNTHESIS_SYSTEM_PROMPT and RESPONSE_SYNTHESIS_PROMPT_MESSAGES
- Update imports to use BaseChatModel
- Keep LangChain interface compatibility
- Remove BaseChatModel import (not needed)
- Update _load_chain to use ChatModel type hint
- Remove protobuf warning filters (not needed)
- Keep pytest import
- No longer needed since we're using MagicMock
- Provider-specific models have been removed
- Mock functionality handled in test files
- No longer needed after removing warning filters
- Only contained import pytest
- No fixtures or test configuration needed
- Replace OpenAI client with ChatModel
- Keep same model name (gpt-4o-2024-08-06)
- Keep same temperature (0)
- Add retries for reliability
- Move LiteLLM-based ChatModel to utils.py
- Remove old ChatOpenAI-based ChatModel
- Remove chat_model.py (no longer needed)
- Update imports to use ChatModel from utils.py
@morganmcg1 morganmcg1 changed the title Add cross-model fallback support and error handling Use LiteLLM in place of ChatOpenAI Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants