npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

anthropic-vertex

v1.0.3

Published

[copilot-is/anthropic-vertex](https://github.com/copilot-is/anthropic-vertex) is a community provider that uses Anthropic models through Vertex AI to provide language model support for the Vercel AI SDK.

Downloads

166

Readme

Vercel AI SDK - Anthropic Vertex Provider

copilot-is/anthropic-vertex is a community provider that uses Anthropic models through Vertex AI to provide language model support for the Vercel AI SDK.

This provider is a community-maintained module and is not officially supported by Vercel. It was forked from the Anthropic Vertex Provider pull request and updated.

Compatibility

The AnthropicVertex provider was tested with Vercel AI SDK version 3.1.0. To avoid TypeScript errors it is recommended to use version 3.3.0 or higher.

Example scripts

Example scripts how to use this provider can be found in the examples folder.

Setup

The AnthropicVertex provider is available in the anthropic-vertex module. You can install it with:

npm install anthropic-vertex
# or
pnpm add anthropic-vertex
# or
yarn add anthropic-vertex
# or
bun add anthropic-vertex

Provider Instance

You can import the default provider instance anthropicVertex from anthropic-vertex:

import { anthropicVertex } from 'anthropic-vertex';

If you need a customized setup, you can import createAnthropicVertex from anthropic-vertex and create a provider instance with your settings:

import { createAnthropicVertex } from 'anthropic-vertex';

const anthropicVertex = createAnthropicVertex({
  project: 'your-project-id',
  location: 'us-central1',
  // other options
});

You can use the following optional settings to customize the AnthropicVertex provider instance:

  • project string

    The Google Cloud project ID that you want to use for the API calls. It uses the GOOGLE_VERTEX_PROJECT environment variable by default.

  • location string

    The Google Cloud location that you want to use for the API calls, e.g. us-central1. It uses the GOOGLE_VERTEX_LOCATION environment variable by default.

  • googleAuthOptions object

    Optional. The Authentication options used by the Google Auth Library.

    • authClient object An AuthClient to use.

    • keyFilename string Path to a .json, .pem, or .p12 key file.

    • keyFile string Path to a .json, .pem, or .p12 key file.

    • credentials object Object containing client_email and private_key properties, or the external account client options.

    • clientOptions object Options object passed to the constructor of the client.

    • scopes string | string[] Required scopes for the desired API request.

    • projectId string Your project ID.

    • universeDomain string The default service domain for a given Cloud universe.

  • baseURL string

    Use a different URL prefix for API calls, e.g., to use proxy servers. The default prefix is https://{location}-aiplatform.googleapis.com/v1.

  • headers Record<string,string>

    Custom headers to include in the requests.

  • fetch (input: RequestInfo, init?: RequestInit) => Promise

    Custom fetch implementation. Defaults to the global fetch function. You can use it as a middleware to intercept requests, or to provide a custom fetch implementation for e.g. testing.

Language Models

You can create models that call the Anthropic API through Vertex AI using the provider instance. The first argument is the model ID, e.g., claude-3-sonnet@20240229:

const model = anthropicVertex('claude-3-sonnet@20240229');

Example: Generate Text

You can use AnthropicVertex language models to generate text with the generateText function:

import { anthropicVertex } from 'anthropic-vertex';
import { generateText } from 'ai';

const { text } = await generateText({
  model: anthropicVertex('claude-3-sonnet@20240229'),
  prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

AnthropicVertex language models can also be used in the streamText, generateObject, and streamObject functions (see AI SDK Core for more information).

Model Capabilities

| Model | Image Input | Object Generation | Tool Usage | Tool Streaming | | ------------------------------- | ------------------ | ------------------ | ------------------ | ------------------ | | claude-3-5-sonnet-v2@20241022 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | claude-3-5-sonnet@20240620 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | claude-3-opus@20240229 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | claude-3-sonnet@20240229 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | claude-3-haiku@20240307 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |

Environment Variables

To use the AnthropicVertex provider, you need to set up the following environment variables:

  • GOOGLE_VERTEX_LOCATION: Your Google Vertex region (e.g., 'us-central1')
  • GOOGLE_VERTEX_PROJECT: Your Google Cloud project ID

Make sure to set these variables in your environment or in a .env file in your project root.

Authentication

The AnthropicVertex provider uses Google Cloud authentication. Make sure you have set up your Google Cloud credentials properly. You can either use a service account key file or default application credentials.

For more information on setting up authentication, refer to the Google Cloud Authentication guide.

Tests

To run the tests, make sure you have installed the dependencies with:

pnpm install

Then, run the tests with:

pnpm test

All tests will get run automatically on every push to the repository to ensure regressions will get caught as early as possible.