[ML] Add AnthropicModelHandler for direct Claude inference#37956
[ML] Add AnthropicModelHandler for direct Claude inference#37956bvolpato wants to merge 1 commit intoapache:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
| } | ||
|
|
||
| // Anthropic RunInference IT tests | ||
| task anthropicInferenceTest { |
There was a problem hiding this comment.
Not too sure about this, I've based on the geminiInferenceTest, but is ANTHROPIC_API_KEY is not defined at runtime, it will be a noop.
There was a problem hiding this comment.
You should define the task but not add it to the inferencePostCommitIT task set yet since the repo doesn't have an anthropic API key secret. The OpenAI handler is in the same boat. At some point I need to see if Apache has resources around for these
5dc31d8 to
e1b72f9
Compare
|
Assigning reviewers: R: @jrmccluskey for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Adds a new RemoteModelHandler for Anthropic's Claude models via the Messages API. Features include: - AnthropicModelHandler with retry logic for 429/5xx errors - message_from_string and message_from_conversation request functions - System prompt support (constructor-level and per-request overrides) - Structured JSON output via output_config (GA API, requires anthropic>=0.86.0) - Comprehensive unit tests and integration tests (Fizz counting rule) - Integration tests gated behind ANTHROPIC_API_KEY env var
e9844cc to
412d534
Compare
Adds a
ModelHandlerfor Anthropic Claude models using the Messages API, enabling direct inference in Beam pipelines without requiring Vertex AI or GCP setup.This follows the same pattern as the existing
GeminiModelHandler, which provides direct Google AI Studio access alongside the Vertex AI-based handler. The motivation is the same: users should be able to use Claude models with just an API key, without needing GCP project setup, service accounts, or IAM configuration.Changes
anthropic_inference.py-AnthropicModelHandlerextendingRemoteModelHandler, withmessage_from_stringandmessage_from_conversationrequest functions, and retry logic for 429/5xx errorssystem=to configure the model persona or strict instruction sets.output_config=following Anthropic's GA JSON Schema format to force structured formatting out of Claude endpoints (enforcesanthropic>=0.86.0).anthropic_inference_test.py- Unit tests covering retry logic, request functions, model handler, output formatting logic, system prompts, and a full pipeline E2E test with picklable fakes.anthropic_inference_it_test.py- Integration tests for generating structured outputs (e.g. Fizz rules) and multi-turn conversations (requiresANTHROPIC_API_KEY).anthropic_tests_requirements.txt- Testing dependency declaration enforcinganthropic>=0.86.0.pytest.ini- Registration of theanthropic_postcommitmarker.CI note
The integration tests are not wired into
inferencePostCommitITor any Dataflow gradle task since the OSS project will not have Anthropic API keys configured. The IT tests exist for contributors to run locally:Unit tests (mock-based, no API key needed):
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.