javagoogle-cloud-platformgoogle-cloud-vertex-aivertex

VertexAI set GenerationConfig


I've changed the version of VertexAI

GenerateContentResponse response = null;
            GenerativeModel model = new GenerativeModel(MODEL_NAME, vertexAI);

but now I can't set model.setGenerationConfig(GenerationConfig.newBuilder().build());

Cannot resolve method 'setGenerationConfig' in 'GenerativeModel'

Solution

  • You can pass the GenerationConfig to the GenerativeModel constructor:

    GenerationConfig generationConfig =
                  GenerationConfig.newBuilder()
                      .setMaxOutputTokens(100)
                      .setTemperature(0.4F)
                      .setTopK(32)
                      .setTopP(1)
                      .build();
    
    GenerativeModel model = new GenerativeModel(MODEL_NAME, generationConfig, vertexAI);
    

    See this example here as well.