vertex_ai 0.0.1 copy "vertex_ai: ^0.0.1" to clipboard
vertex_ai: ^0.0.1 copied to clipboard

Vertex AI API client.

Vertex AI API Client #

tests vertex_ai MIT

Dart client for the Vertex AI API.

Features #

Generative AI #

Generative AI support on Vertex AI (also known as genai) gives you access to Google's large generative AI models so you can use in your AI-powered applications.

Authentication #

The VertexAIGenAIClient delegates authentication to the googleapis_auth package.

To create an instance of VertexAIGenAIClient you need to provide an AuthClient instance.

There are several ways to obtain an AuthClient depending on your use case. Check out the googleapis_auth package documentation for more details.

Example using a service account JSON:

final serviceAccountCredentials = ServiceAccountCredentials.fromJson(
  json.decode(serviceAccountJson),
);
final authClient = await clientViaServiceAccount(
  serviceAccountCredentials,
  [VertexAIGenAIClient.cloudPlatformScope],
);
final vertexAi = VertexAIGenAIClient(
  authHttpClient: authClient,
  project: 'your-project-id',
);

The service account should have the following permission:

  • aiplatform.endpoints.predict

The requiredOAuth2 scope is:

  • https://www.googleapis.com/auth/cloud-platform (you can use the constant VertexAIGenAIClient.cloudPlatformScope)

Text models #

PaLM API for text is fine-tuned for language tasks such as classification, summarization, and entity extraction.

final res = await vertexAi.text.predict(
  prompt: 'What is the purpose of life?',
);

Chat models

PaLM API for chat is fine-tuned for multi-turn chat, where the model keeps track of previous messages in the chat and uses it as context for generating new responses.

final res = await vertexAi.chat.predict(
  context: 'I want you to act as a Socrat.',
  messages: const [
    VertexAIChatModelMessage(
      author: 'USER',
      content: 'Is justice neccessary in a society?',
    ),
  ],
);

Text embeddings

The Text Embedding API generates vector embeddings for input text. You can use embeddings for tasks like semantic search, recommendation, classification, and outlier detection.

final res = await vertexAi.textEmbeddings.predict(
  content: ['The only true wisdom is in knowing you know nothing.'],
);

License #

Vertex AI API Client is licensed under the MIT License.