feat: use anthropic on vertex if configured
feat: use anthropic on vertex if configured
To do this, it moves the creation of a ChatModel into a the
llm_factory.
When we find the DUO_WORKFLOW__VERTEX_PROJECT_ID we'll try to
connect to Vertex-Anthropic. If it's not set, but ANTHROPIC_API_KEY
is set, we'll connect to regular-Anthropic. This means that we can
gradually transition to using Vertex-Anthropic in all environments.
When DUO_WORKFLOW__VERTEX_PROJECT_ID is set, we also require
DUO_WORKFLOW_SERVICE__VERTEX_LOCATION to be set. For now, this is
because we need to hardcode connecting to us-east5 for
Vertex-Anthropic, the models we need are not available in
us-east1. We'll need to change this behaviour based on
RUNWAY_REGION if we want to deploy this service in multiple regions.
During the initialization of the server, we also explicitly test if the model is accessible with the configured environment variables. This replaces the startup probe which normally executes a regular HTTP request, but is not available here yet. This ensures that we only put instances in rotation that have access to the configured model. As a result, a deploy with invalid environment will fill and leave the old instances in rotation.
To use this in development, you need to be signed in using gcloud to
an account that has access to Vertex. At GitLab we use the
ai-enablement-dev-69497ba7 GCP project for this.
For gitlab-org/gitlab#478883 (closed)
fix: patch ChatAnthropicVertex._format_output to include content
The original implementation for
ChatAnthropicVertex._format_output could return a message that
only has tool_calls populated but without content. This causes the
following error message when calling Anthropic:
Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages.16: `tool_result` block(s) provided when previous message does not contain any `tool_use` blocks'}}
To fix this, we've looked at the original implementation of
ChatAnthropic._format_output, and patched the implementation we
use here for switching to using Vertex.
We need to upstream a version of these change and upgrade our library. We'll do that in #96 (closed)