private FieldValue computeGeneration(Prompt prompt, String destination, DataType targetType) {
        var options = new HashMap<String, String>();
        String jsonSchema = null;
        
        if (config.responseFormatType() == LanguageModelFieldGeneratorConfig.ResponseFormatType.JSON) {
            jsonSchema = FieldGeneratorUtils.generateJsonSchemaForField(destination, targetType);
            options.put(InferenceParameters.OPTION_JSON_SCHEMA, jsonSchema);
        }
        
        var expandedPrompt = LanguageModelUtils.expandPrompt(prompt.asString(), promptTemplate, jsonSchema);
        var completions = languageModel.complete(StringPrompt.from(expandedPrompt), new InferenceParameters(options::get));
        var firstCompletion = completions.get(0);
        var generatedText = firstCompletion.text();
        FieldValue generatedFieldValue; 
        
        if (config.responseFormatType() == LanguageModelFieldGeneratorConfig.ResponseFormatType.JSON) {
            try {
                generatedFieldValue = FieldGeneratorUtils.parseJsonFieldValue(generatedText, destination, targetType);
            } catch (IllegalArgumentException e) {
                generatedFieldValue = switch (config.invalidResponseFormatPolicy()) {
                    case DISCARD -> null;
                    case WARN -> {
                        logger.warning(e.getMessage());
                        yield null;
                    }
                    case FAIL -> throw e;
                };
            }
        } else {
            generatedFieldValue = new StringFieldValue(generatedText);
        }
        
        return generatedFieldValue;
    }
Component for generating field values with a language model.

@author glebashnik
model-integration/src/main/java/ai/vespa/llm/generation/LanguageModelFieldGenerator.java