Skip to content

♻️(llm): Migrate from OpenAI to Anthropic API #1242

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

Merged
merged 8 commits into from
Apr 9, 2025

Conversation

MH4GF
Copy link
Member

@MH4GF MH4GF commented Apr 8, 2025

Issue

  • Migrate LLM provider from OpenAI to Anthropic

Why is this change needed?

This change migrates our LLM implementation from OpenAI to Anthropic across the codebase. It updates environment variables, dependencies, and model implementations to use Anthropic's Claude models instead of GPT models.

What would you like reviewers to focus on?

  • Proper implementation of Anthropic API client
  • Environment variable changes
  • Model parameter configurations
  • CI/CD workflow updates

Testing Verification

Tested prompt generation with new Anthropic API and verified outputs match expected format.

What was done

🤖 Generated by PR Agent at 31e3a9c

  • Migrated from OpenAI to Anthropic API for LLM usage.
    • Replaced ChatOpenAI with ChatAnthropic in multiple files.
    • Updated model configurations to use Anthropic's Claude models.
  • Updated environment variables to use ANTHROPIC_API_KEY instead of OPENAI_API_KEY.
  • Removed unused dependencies related to OpenAI and added Anthropic dependencies.
  • Updated documentation to reflect the migration changes.

Detailed Changes

Relevant files
Enhancement
3 files
generateDocsSuggestion.ts
Replaced OpenAI model with Anthropic in docs suggestion generation
+3/-3     
generateReview.ts
Switched from OpenAI to Anthropic for review generation   
+3/-3     
generateSchemaMeta.ts
Migrated schema meta generation to Anthropic API                 
+6/-5     
Configuration changes
2 files
.env.template
Updated environment variable to use Anthropic API key       
+1/-1     
.env.template
Replaced OpenAI API key with Anthropic API key in migration prompts
+1/-1     
Documentation
1 files
CONTRIBUTING.md
Updated documentation for Anthropic API key setup               
+1/-1     
Dependencies
3 files
package.json
Removed OpenAI dependencies from app package                         
+0/-2     
package.json
Added Anthropic dependency and removed OpenAI dependency 
+1/-1     
pnpm-lock.yaml
Updated lockfile to reflect dependency changes for Anthropic migration
+110/-26

Additional Notes

  • After merging, team members will need to update their local .env.local files to use ANTHROPIC_API_KEY instead of OPENAI_API_KEY.
  • I have not yet configured prompt-test to use the anthropic API. I have tried but it gives me an error. I want to adjust it after the merge.

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • …ate and update related documentation; switch from ChatOpenAI to ChatAnthropic in job prompts for improved integration
    Copy link

    changeset-bot bot commented Apr 8, 2025

    ⚠️ No Changeset found

    Latest commit: 31e3a9c

    Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

    This PR includes no changesets

    When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

    Click here to learn what changesets are, and how to add one.

    Click here if you're a maintainer who wants to add a changeset to this PR

    Copy link

    vercel bot commented Apr 8, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    liam-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 9, 2025 1:04am
    liam-erd-sample ✅ Ready (Inspect) Visit Preview Apr 9, 2025 1:04am
    1 Skipped Deployment
    Name Status Preview Comments Updated (UTC)
    liam-docs ⬜️ Ignored (Inspect) Visit Preview Apr 9, 2025 1:04am

    Copy link

    supabase bot commented Apr 8, 2025

    Updates to Preview Branch (replace-to-anthropic-api) ↗︎

    Deployments Status Updated
    Database Wed, 09 Apr 2025 00:51:09 UTC
    Services Wed, 09 Apr 2025 00:51:09 UTC
    APIs Wed, 09 Apr 2025 00:51:09 UTC

    Tasks are run on every commit but only new migration files are pushed.
    Close and reopen this PR if you want to apply changes from existing seed or migration files.

    Tasks Status Updated
    Configurations Wed, 09 Apr 2025 00:51:09 UTC
    Migrations Wed, 09 Apr 2025 00:51:09 UTC
    Seeding Wed, 09 Apr 2025 00:51:09 UTC
    Edge Functions Wed, 09 Apr 2025 00:51:09 UTC

    View logs for this Workflow Run ↗︎.
    Learn more about Supabase for Git ↗︎.

    Copy link
    Contributor

    qodo-merge-pro-for-open-source bot commented Apr 8, 2025

    CI Feedback 🧐

    (Feedback updated until commit f88c375)

    A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

    Action: evaluate

    Failed stage: Run promptfoo evaluation [❌]

    Failure summary:

    The action failed because the evaluation process completed with a 50% pass rate (1 success, 1
    failure). The process '/usr/local/bin/npx' exited with code 100, indicating that the test or
    evaluation criteria were not fully met. The log shows that promptfoo was used to evaluate prompts,
    and half of the tests failed.

    Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    170:  │   provider        = "prisma-client-js" │ (#4946)                                │ assess potential data loss risks       │
    171:  │   previewFeatures = ["tracing", "view… │     * fix: remove trace tracesession … │ associated with sharing.               │
    172:  │ "relationJoins", "metrics"]            │     * push                             │ ---                                    │
    173:  │ }                                      │     * push                             │ I'll help you share content. What      │
    174:  │ datasource d...                        │     * push                             │ would you li...                        │
    175:  │                                        │     * fix: remov...                    │                                        │
    176:  └────────────────────────────────────────┴────────────────────────────────────────┴────────────────────────────────────────┘
    177:  Writing output to /home/runner/work/liam/liam/output.json
    178:  ========================================================================================================================
    179:  ✔ Evaluation complete. ID: eval-kKW-» Run promptfoo view to use the local web viewer
    180:  » Do you want to share this with your team? Sign up for free at https://promptfoo.app
    181:  » This project needs your feedback. What's one thing we can improve? https://forms.gle/YFLgTe1dKJKNSCsU7
    182:  ========================================================================================================================
    183:  Successes: 1
    184:  Failures: 1
    185:  Errors: 0
    186:  Pass Rate: 50.00%
    187:  Eval tokens: 195 / Prompt tokens: 18 / Completion tokens: 177 / Cached tokens: 0 / Reasoning tokens: 0
    188:  Grading tokens: 374 / Prompt tokens: 297 / Completion tokens: 77 / Cached tokens: 0 / Reasoning tokens: 0
    189:  Total tokens: 569 (eval: 195 + Grading: 374)
    190:  Done.
    191:  ##[error]The process '/usr/local/bin/npx' failed with exit code 100
    192:  Post job cleanup.
    

    This comment was marked as outdated.

    This comment was marked as outdated.

    …C_API_KEY; modify prompt configuration and documentation accordingly
    @MH4GF MH4GF force-pushed the replace-to-anthropic-api branch from c83ecb9 to f88c375 Compare April 8, 2025 10:49
    Copy link
    Contributor

    github-actions bot commented Apr 8, 2025

    ⚠️ LLM prompt was modified in these files:

    Success Failure
    1 1

    » View eval results in CI console «

    This comment was marked as outdated.

    @MH4GF MH4GF force-pushed the replace-to-anthropic-api branch from d4be2ef to 84af65f Compare April 8, 2025 11:08

    This comment was marked as outdated.

    Copy link
    Contributor

    github-actions bot commented Apr 8, 2025

    frontend/packages/prompt-test result:

    View results: https://app.promptfoo.dev/eval/f:46773721-bb17-4ca5-9411-f6db7e9ce07e

    ✅️ Promptfoo test succeeded

    ✅️ Successes ❌️ Failures ⚠️ Errors
    9 0 0

    This comment was marked as outdated.

    @MH4GF MH4GF force-pushed the replace-to-anthropic-api branch from df2b30a to c0fd9fd Compare April 8, 2025 11:44
    Copy link
    Contributor

    github-actions bot commented Apr 8, 2025

    ⚠️ LLM prompt was modified in these files:

    Success Failure
    2 0

    » View eval results in CI console «

    MH4GF added 3 commits April 9, 2025 09:49
    …ed prompt evaluation consistency"
    
    This reverts commit c0fd9fd.
    …s instead of direct prompts for improved configuration management"
    
    This reverts commit 84af65f.
    …ANTHROPIC_API_KEY; modify prompt configuration and documentation accordingly"
    
    This reverts commit f88c375.
    @MH4GF MH4GF marked this pull request as ready for review April 9, 2025 00:51
    @MH4GF MH4GF requested a review from a team as a code owner April 9, 2025 00:51
    @MH4GF MH4GF requested review from hoshinotsuyoshi, FunamaYukina, junkisai and NoritakaIkeda and removed request for a team April 9, 2025 00:51
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Model Configuration

    The evaluationModel is created with temperature 0.2 but no explicit temperature is set in the constructor. Verify if this is intentional or if the temperature parameter is missing.

    const evaluationModel = new ChatAnthropic({
      temperature: 0.2,
      model: 'claude-3-7-sonnet-latest',
    })
    Duplicate Key

    The file contains both ANTHROPIC_API_KEY and OPENAI_API_KEY with the latter appearing twice. This might cause confusion or errors when using the template.

    ANTHROPIC_API_KEY=

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Remove redundant environment variable

    The file still contains the OPENAI_API_KEY environment variable which should be
    removed since the project is migrating from OpenAI to Anthropic.

    frontend/packages/migration/prompts/.env.template [2]

     +ANTHROPIC_API_KEY=
    - OPENAI_API_KEY=

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 8

    __

    Why: The PR is migrating from OpenAI to Anthropic, but the .env.template file still contains the OPENAI_API_KEY variable which is no longer needed. Removing it would prevent confusion and align with the migration changes.

    Medium
    Learned
    best practice
    Validate required environment variables before creating API clients to prevent runtime errors

    The code creates a new ChatAnthropic instance without validating if the required
    ANTHROPIC_API_KEY environment variable exists. Since this PR migrates from
    OpenAI to Anthropic, it's important to validate that the required API key is
    available before attempting to use the Anthropic client. This prevents runtime
    errors and improves error handling.

    frontend/packages/jobs/src/prompts/generateDocsSuggestion/generateDocsSuggestion.ts [86-89]

    +// Validate Anthropic API key before creating client
    +if (!process.env.ANTHROPIC_API_KEY) {
    +  throw new Error('ANTHROPIC_API_KEY environment variable is required but not set');
    +}
    +
     const model = new ChatAnthropic({
       temperature: 0.7,
       model: 'claude-3-7-sonnet-latest',
     })
    • Apply this suggestion
    Suggestion importance[1-10]: 6
    Low
    • More

    Copy link
    Member

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    I think migration package can be removed now. In separate issue / PR, we should delete it

    Comment on lines -6 to -7
    "@langchain/core": "0.3.43",
    "@langchain/openai": "0.5.4",
    Copy link
    Member

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    👍

    @hoshinotsuyoshi
    Copy link
    Member

    #1242 (comment)

    prompt-test package does not follow anthropic API for now 🙏

    @hoshinotsuyoshi hoshinotsuyoshi added this pull request to the merge queue Apr 9, 2025
    Merged via the queue into main with commit 1cc8ea2 Apr 9, 2025
    20 checks passed
    @hoshinotsuyoshi hoshinotsuyoshi deleted the replace-to-anthropic-api branch April 9, 2025 01:13
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants