--- title: "VertexAICodeGenerator" id: vertexaicodegenerator slug: "/vertexaicodegenerator" description: "This component enables code generation using Google Vertex AI generative model." --- # VertexAICodeGenerator This component enables code generation using Google Vertex AI generative model. | | | | --- | --- | | **Mandatory run variables** | “prefix”: A string of code before the current point

”suffix”: An optional string of code after the current point | | **Output variables** | “replies”: Code generated by the model | | **API reference** | [Google Vertex](/reference/integrations-google-vertex) | | **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex | `VertexAICodeGenerator` supports `code-bison`, `code-bison-32k`, and `code-gecko`. ### Parameters Overview `VertexAICodeGenerator` uses Google Cloud Application Default Credentials (ADCs) for authentication. For more information on how to set up ADCs, see the [official documentation](https://cloud.google.com/docs/authentication/provide-credentials-adc). Keep in mind that it’s essential to use an account that has access to a project authorized to use Google Vertex AI endpoints. You can find your project ID in the [GCP resource manager](https://console.cloud.google.com/cloud-resource-manager) or locally by running `gcloud projects list` in your terminal. For more info on the gcloud CLI, see its [official documentation](https://cloud.google.com/cli). ## Usage You need to install `google-vertex-haystack` package first to use the `VertexAIImageCaptioner`: ```shell pip install google-vertex-haystack ``` Basic usage: ````python from haystack_integrations.components.generators.google_vertex import VertexAICodeGenerator generator = VertexAICodeGenerator() result = generator.run(prefix="def to_json(data):") for answer in result["replies"]: print(answer) ```` You can also set other parameters like the number of output tokens, temperature, stop sequences, and the number of candidates. Let’s try a different model: ```python from haystack_integrations.components.generators.google_vertex import ( VertexAICodeGenerator, ) generator = VertexAICodeGenerator( model="code-gecko", temperature=0.8, candidate_count=3, ) result = generator.run(prefix="def convert_temperature(degrees):") for answer in result["replies"]: print(answer) ```