Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot disable OpenAiModerationModel when using OpenAiAutoConfiguration #2373

Open
gm2552 opened this issue Mar 3, 2025 · 0 comments
Open

Comments

@gm2552
Copy link

gm2552 commented Mar 3, 2025

Bug description
All of the Beans in the OpenAiAutoConfiguration class that require an API key have an option to disable the particular bean with the @ConditionalOnProperty with the exception of the OpenAiModerationModel. This has two potential issues:

  • Inconsistent AutoConfiguration pattern as all of the other Client or Model beans support an enabled property.
  • If I want to use constructs/classes in the OpenAI library but do not necessarily need a client connection (i.e. I don't need to set the apiKey), I cannot load my application without setting a bogus API key. The alternative is to disable AutoConfiguration for this class, but are scenarios where I still may want to auto configure a particular client.

Environment
Spring Boot 3.4.x and spring-ai M6.

Steps to reproduce
Set the enabled flag for all models and client to false and do not set an apiKey (do not disable auto configuration). The application will crash with the following error:

OpenAI API key must be set. Use the connection property: spring.ai.openai.api-key or spring.ai.openai.moderation.api-key property

Expected behavior
I would expect there to be a consistent pattern for disabling the moderation client. Something like:

spring:
  ai:
    openai:
      moderation:
        enabled: false

Minimal Complete Reproducible example
Please provide a failing test or a minimal complete verifiable example that reproduces the issue.
Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.

Just create a trivial SpringBootApplication with the OpenAI starter. Use the following application.yaml.

spring:
  ai:
    openai:
      chat:
        enabled: false 
      embedding:
        enabled: false
      image:
        enabled: false
      audio:
        transcription:
          enabled: false
        speech:
          enabled: false
gm2552 added a commit to gm2552/spring-ai that referenced this issue Mar 3, 2025
Added the ability to disable auto configuration of the
OpenAiModerationModel bean.  Addresses reported bug
[2373](spring-projects#2373)
gm2552 added a commit to gm2552/spring-ai that referenced this issue Mar 3, 2025
Added the ability to disable auto configuration of the
OpenAiModerationModel bean.  Addresses reported bug
[2373](spring-projects#2373)

Signed-off-by: Greg Meyer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant