Class CodeGenerationModel (1.26.1)

CodeGenerationModel(model_id: str, endpoint_name: 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):", ))

Inheritance

builtins.object > vertexai._model_garden._model_garden_models._ModelGardenModel > vertexai.language_models._language_models._LanguageModel > CodeGenerationModel

Methods

CodeGenerationModel

CodeGenerationModel(model_id: str, endpoint_name: 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)

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: Optional[str] = "",
    *,
    max_output_tokens: int = 128,
    temperature: float = 0.0
)

Gets model response for a single prompt.