最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring ai - No converter for org.springframework.ai.openai.api.ResponseFormat - Stack Overflow

programmeradmin7浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论