Class CodeGenerationModel (1.27.1)

CodeGenerationModel(model_id: str, endpoint_name: typing.Optional[str] = None)

A language model that generates code.

.. rubric:: Examples

Getting answers:

generation_model = CodeGenerationModel.from_pretrained("code-bison@001") print(generation_model.predict( prefix="Write a function that checks if a year is a leap year.", ))

completion_model = CodeGenerationModel.from_pretrained("code-gecko@001") print(completion_model.predict( prefix="def reverse_string(s):", ))

Methods

CodeGenerationModel

CodeGenerationModel(model_id: str, endpoint_name: typing.Optional[str] = None)

Creates a LanguageModel.

This constructor should not be called directly. Use LanguageModel.from_pretrained(model_name=...) instead.

from_pretrained

from_pretrained(model_name: str) -> vertexai._model_garden._model_garden_models.T

Loads a _ModelGardenModel.

Exceptions
Type Description
ValueError If model_name is unknown.
ValueError If model does not support this class.

predict

predict(
    prefix: str,
    suffix: typing.Optional[str] = "",
    *,
    max_output_tokens: int = 128,
    temperature: float = 0.0
) -> vertexai.language_models._language_models.TextGenerationResponse

Gets model response for a single prompt.