admin管理员组

文章数量:1402832

I have a Spring Boot (version 3.4.2) application with Spring AI and I want to get only JSON responses from OpenAI, so I configured it in my application.yml file, see Built-in JSON mode:

Some AI Models provide dedicated configuration options to generate structured (usually JSON) output.

  • OpenAI Structured Outputs can ensure your model generates responses conforming strictly to your provided JSON Schema. You can choose between the JSON_OBJECT that guarantees the message the model generates is valid JSON or JSON_SCHEMA with a supplied schema that guarantees the model will generate a response that matches your supplied schema (spring.ai.openai.chat.options.responseFormat option).

Unfortunately, it is not working.

Configuration

spring:
  ai:
    openai:
      chat:
        options:
          model: gpt-4o-mini
          temperature: 0.0
          responseFormat: JSON_SCHEMA

Logs

Failed to bind properties under 'spring.ai.openai.chat.options.response-format' to .springframework.ai.openai.api.ResponseFormat:

    Reason: .springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [@com.fasterxml.jackson.annotation.JsonProperty .springframework.ai.openai.api.ResponseFormat]

Research

  • I looked into ResponseFormat and ResponseFormat.Type and changed JSON_SCHEMA to json_schema but it didn't help.

  • I read Using the Chat Options Builder and tried to add the response format programmatically. But then I can no longer use BeanOutputConverter and have to write the JSON schema manually instead of getting it dynamically from the Java class.

Question

What did I wrong? How can I configure the response format in my application.yml?

本文标签: spring aiNo converter for orgspringframeworkaiopenaiapiResponseFormatStack Overflow