Overview
VertexAIModel is a legacy, deprecated model wrapper in the phoenix-evals package that provides an interface for using Google VertexAI text generation and code generation models (e.g., text-bison, code-bison). It extends BaseModel and integrates with the VertexAI TextGenerationModel and CodeGenerationModel classes from the google-cloud-aiplatform package. This wrapper does not support async execution and does not include rate limiting. For Gemini models, use GeminiModel or GoogleGenAIModel instead.
LLM_Evaluation
Model_Integration
Description
The VertexAIModel class is implemented as a Python dataclass that extends the abstract BaseModel. Key characteristics include:
- Legacy/Deprecated status: This wrapper targets older VertexAI text and code generation models. For Gemini models, the GeminiModel or GoogleGenAIModel wrappers are recommended.
- Dual model support: Automatically selects between
TextGenerationModel and CodeGenerationModel based on whether "code" appears in the model name (via the is_codey_model property).
- Tuned model support: Can load tuned/fine-tuned models via the
tuned_model parameter, using get_tuned_model() instead of from_pretrained().
- No async support: The
_async_generate_with_extra() method simply delegates to the synchronous _generate_with_extra(), as the underlying SDK lacks async capabilities.
- No rate limiting: Uses the default
RateLimiter from the base class without configuring it with a specific error type.
- Codey-aware parameters: When using Codey (code generation) models,
top_k and top_p parameters are excluded from invocation parameters since they are not supported.
- VertexAI initialization: Calls
vertexai.init() with project, location, and credentials during setup.
- Deprecated field migration: Both
model_name and tuned_model_name fields are deprecated with automatic migration and deprecation warnings.
- No usage tracking: Returns an empty
ExtraInfo() since the legacy VertexAI predict() API does not provide token usage information.
Usage
# Set up your GCP environment
# https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal
from phoenix.evals.models import VertexAIModel
# Basic usage with defaults (text-bison)
model = VertexAIModel()
# Specify project and model
model = VertexAIModel(
model="text-bison",
project="my-gcp-project",
location="us-central1",
)
response = model("Write a Python function to sort a list.")
print(response)
Code Reference
Source Location
| Property |
Value
|
| Repository |
Arize-ai/phoenix
|
| File |
packages/phoenix-evals/src/phoenix/evals/legacy/models/vertexai.py
|
| Lines |
215
|
| Module |
phoenix.evals.legacy.models.vertexai
|
Class Signature
@dataclass
class VertexAIModel(BaseModel):
project: Optional[str] = None
location: Optional[str] = None
credentials: Optional["Credentials"] = None
model: str = "text-bison"
tuned_model: Optional[str] = None
temperature: float = 0.0
max_tokens: int = 1024
top_p: float = 0.95
top_k: int = 40
# Deprecated
model_name: Optional[str] = None
tuned_model_name: Optional[str] = None
Constructor Parameters
| Parameter |
Type |
Default |
Description
|
| project |
Optional[str] |
None |
GCP project ID.
|
| location |
Optional[str] |
None |
GCP location/region (defaults to us-central1).
|
| credentials |
Optional[Credentials] |
None |
Google auth credentials.
|
| model |
str |
"text-bison" |
The VertexAI model name to use.
|
| tuned_model |
Optional[str] |
None |
Tuned/fine-tuned model name; if set, overrides model.
|
| temperature |
float |
0.0 |
Sampling temperature.
|
| max_tokens |
int |
1024 |
Maximum output tokens.
|
| top_p |
float |
0.95 |
Nucleus sampling probability mass (ignored for Codey models).
|
| top_k |
int |
40 |
Top-K sampling cutoff (ignored for Codey models).
|
| model_name |
Optional[str] |
None |
Deprecated. Use model instead.
|
| tuned_model_name |
Optional[str] |
None |
Deprecated. Use tuned_model instead.
|
Key Methods
| Method |
Signature |
Description
|
| __post_init__ |
(self) -> None |
Migrates deprecated fields, initializes environment, VertexAI, and model.
|
| _migrate_model_name |
(self) -> None |
Handles migration of model_name and tuned_model_name with warnings.
|
| _init_environment |
(self) -> None |
Imports vertexai and google.api_core.exceptions.
|
| _init_vertex_ai |
(self) -> None |
Calls vertexai.init() with project, location, and credentials.
|
| _instantiate_model |
(self) -> None |
Creates TextGenerationModel or CodeGenerationModel and loads pretrained or tuned weights.
|
| _generate_with_extra |
(self, prompt, **kwargs) -> Tuple[str, ExtraInfo] |
Synchronous generation via model.predict(); returns empty ExtraInfo.
|
| _async_generate_with_extra |
async (self, prompt, **kwargs) -> Tuple[str, ExtraInfo] |
Delegates to synchronous generation (no native async).
|
| is_codey_model |
@property -> bool |
Returns True if model name contains "code".
|
| invocation_params |
@property -> Dict[str, Any] |
Returns invocation parameters, excluding top_k/top_p for Codey models.
|
| verbose_generation_info |
(self) -> str |
Returns formatted invocation parameters string.
|
Helper Function
| Function |
Signature |
Description
|
| is_codey_model |
(model_name: str) -> bool |
Returns True if "code" is in the model name string.
|
Import
from phoenix.evals.models import VertexAIModel
I/O Contract
| Direction |
Type |
Description
|
| Input |
Union[str, MultimodalPrompt] |
A text string or multimodal prompt (converted to text-only).
|
| Output |
str |
Generated text response.
|
| Output (with extra) |
Tuple[str, ExtraInfo] |
Generated text paired with empty ExtraInfo() (no usage data available).
|
| Error |
ImportError |
Raised if google-cloud-aiplatform package is not installed.
|
Usage Examples
Text Generation
from phoenix.evals.models import VertexAIModel
model = VertexAIModel(
model="text-bison",
project="my-project",
temperature=0.2,
max_tokens=512,
)
response = model("Explain the MapReduce programming model.")
print(response)
Code Generation
from phoenix.evals.models import VertexAIModel
model = VertexAIModel(
model="code-bison",
project="my-project",
temperature=0.0,
)
# top_k and top_p are automatically excluded for Codey models
response = model("Write a Python function to compute the Fibonacci sequence.")
print(response)
With Tuned Model
from phoenix.evals.models import VertexAIModel
model = VertexAIModel(
tuned_model="projects/my-project/locations/us-central1/models/my-tuned-model",
project="my-project",
)
response = model("Classify the following text: ...")
print(response)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.