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

Add AI Model Fallback Mechanism for Improved Reliability #901

Open
jelveh opened this issue Nov 22, 2024 · 0 comments
Open

Add AI Model Fallback Mechanism for Improved Reliability #901

jelveh opened this issue Nov 22, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@jelveh
Copy link
Contributor

jelveh commented Nov 22, 2024

Well, we just got banned by Anthropic without any warning, which highlights the importance of being resilient when it comes to using 3rd party services.

Currently, when an AI model request fails (e.g., due to provider errors), the entire request fails. We should implement an automatic fallback mechanism to improve reliability and ensure requests succeed whenever possible.

Current Behavior

  • When a model provider (e.g., OpenAI) returns an error, the request fails completely
  • No automatic fallback to alternative models
  • Users experience complete failure rather than degraded service

Proposed Solution
Implement an automatic fallback chain for AI model requests:

  1. Try requested model first (e.g., claude-3-5-sonnet)
  2. If that fails, fall back to gpt-4o mini
  3. If gpt-4o mini fails, fall back to llama
  4. Only fail completely if all fallback options are exhausted

Implementation Details

  1. Response Enhancement:

    • Add a new response attribute (e.g., usedModel) indicating which model actually handled the request
    • This allows clients to know if a fallback was used
  2. Configuration Option:

    • Add a new option to disable fallback behavior: disableFallback (default: false)
    • Example usage:
    puter.ai.chat("Hello!", {
      model: "claude-3-5-sonnet",
      disableFallback: true  // Disable automatic fallback
    })
  3. Fallback Chain:

    • Define clear fallback hierarchy
    • Consider timeout/retry logic before moving to next fallback

Expected Behavior

// Example 1: With fallback enabled (default)
const response = await puter.ai.chat("Hello!", { model: "claude-3-5-sonnet" });
console.log(response.text);         // The response text
console.log(response.usedModel);    // e.g., "gpt-4o-mini" if Claude failed

// Example 2: With fallback disabled
try {
  const response = await puter.ai.chat("Hello!", {
    model: "claude-3-5-sonnet",
    disableFallback: true
  });
} catch (error) {
  // Original error from Claude is thrown
}
@jelveh jelveh added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Nov 22, 2024
@jelveh jelveh removed good first issue Good for newcomers help wanted Extra attention is needed labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants