private void addResponseFormat(InferenceParameters parameters, ChatCompletionCreateParams.Builder builder) {
        parameters.get(InferenceParameters.OPTION_JSON_SCHEMA).ifPresent(jsonSchemaStr -> {
            try {
                ObjectMapper mapper = new ObjectMapper();  
                // Parse the JSON string to a Map using readValue
                Map<String, Object> rawMap = mapper.readValue(
                    jsonSchemaStr.toString(), 
                    new TypeReference<Map<String, Object>>() {}
                );
                Map<String, JsonValue> additionalProps = new HashMap<>();
                
                // Convert each value to JsonValue
                rawMap.forEach((key, value) -> 
                    additionalProps.put(key, JsonValue.from(value)));
                
                ResponseFormatJsonSchema.JsonSchema.Schema schema = 
                    ResponseFormatJsonSchema.JsonSchema.Schema.builder()
                        .putAllAdditionalProperties(additionalProps)
                        .build();
                
                var jsonFormat = ResponseFormatJsonSchema.builder()
                    .jsonSchema(ResponseFormatJsonSchema.JsonSchema.builder()
                        .name("structured-output")
                        .schema(schema)
                        .build())
                    .build();
                
                builder.responseFormat(jsonFormat);
            } catch (Exception e) {
                throw new LanguageModelException(400, "Failed to parse JSON schema:\n" + jsonSchemaStr.toString() + "\n" + e.getMessage(), e);
            }
        });
    }
A configurable OpenAI client that extends the {@link ConfigurableLanguageModel} class.
Uses Official OpenAI java client (https://github.com/openai/openai-java)
Supports basic completion and structured JSON output. Extensible to support Embedding, Tool Calling and Moderations.
Will reuse clients for Completions using same endpoint and API key to reduce connection overhead for multiple requests to the same endpoint with the same API key.
@author lesters
@author glebashnik
@author thomasht86
model-integration/src/main/java/ai/vespa/llm/clients/OpenAI.java