e2b-dev / fragments

Open-source Next.js template for building apps that are fully generated by AI. By E2B.
https://fragments.e2b.dev
Apache License 2.0
2.42k stars 298 forks source link

Add OpenRouter support with Claude 3.5 Sonnet model #61

Open PierrunoYT opened 6 days ago

PierrunoYT commented 6 days ago

This pull request adds support for OpenRouter as a new AI provider, specifically integrating the Claude 3.5 Sonnet mod from Anthropic through OpenRouter's API.

Key changes:

  1. Updated lib/models.json:

    • Added a new entry for the Claude 3.5 Sonnet model via OpenRouter:
      {
      "id": "anthropic/claude-3.5-sonnet",
      "provider": "OpenRouter",
      "providerId": "openrouter",
      "name": "Claude 3.5 Sonnet",
      "multiModal": true
      }
  2. Modified lib/models.ts:

    • Added OpenRouter configuration in the getModelClient function:
      • Set up API key and base URL for OpenRouter
      • Included optional headers for OpenRouter's rankings (HTTP-Referer and X-Title)
  3. Updated environment variables:

    • Added OPENROUTER_API_KEY to the environment configuration
    • Included NEXT_PUBLIC_SITE_URL and NEXT_PUBLIC_SITE_NAME for OpenRouter's optional headers
  4. No changes were required in components/chat.tsx or app/api/chat/route.ts as they were already set up to handle different model providers.

    This integration allows users to leverage the Claude 3.5 Sonnet model through OpenRouter, expanding the AI capabilitie of our application. The changes maintain compatibility with existing providers while adding this new option.

    To use this new model, users will need to set up their OpenRouter API key in the environment variables.

    Testing:

    • Verified that the OpenRouter model appears in the model selection list
    • Tested API calls to ensure proper communication with OpenRouter
    • Checked that multi-modal capabilities work as expected with this model

    Next steps:

    • Consider adding more OpenRouter models in the future if needed
    • Monitor usage and performance of the Claude 3.5 Sonnet model through OpenRouter
vercel[bot] commented 6 days ago

Someone is attempting to deploy a commit to the E2B Team on Vercel.

A member of the Team first needs to authorize it.

PierrunoYT commented 3 days ago

@mishushakov