描述bug
当将 @Moderate
注解添加到 @AiService
's方法时,会抛出异常,提示即使在 application.yml 文件中设置了建议的 moderation model 属性,但 moderation model 尚未配置。
日志和堆栈跟踪
dev.langchain4j.exception.IllegalConfigurationException: The @Moderate annotation is present, but the moderationModel is not set up. Please ensure a valid moderationModel is configured before using the @Moderate annotation.
at dev.langchain4j.exception.IllegalConfigurationException.illegalConfiguration(IllegalConfigurationException.java:12)
at dev.langchain4j.service.DefaultAiServices.build(DefaultAiServices.java:67)
at dev.langchain4j.service.spring.AiServiceFactory.getObject(AiServiceFactory.java:90)
重现步骤
@AiService
public interface Assistant {
@SystemMessage("""
You are a polite assistant.
""")
@Moderate
String assist(@UserMessage String message);
}
带有属性:
...
langchain4j:
open-ai:
chat-model:
api-key: ${OPENAI_API_KEY}
model-name: gpt-3.5-turbo
temperature: 0.7
log-requests: true
log-responses: true
moderation-model:
api-key: ${OPENAI_API_KEY}
预期行为
moderation model 应自动配置,并且像聊天模型一样可以立即使用 moderation。
请填写以下信息:
- LangChain4j 版本:0.31.0
- 使用的 LLM(s):gpt-3.5-turbo
- Java 版本:17
- Spring Boot 版本(如适用):3.2.4
其他上下文
看起来 dev.langchain4j.service.spring.AiServicesAutoConfig
在 aiServicesRegisteringBeanFactoryPostProcessor()
中缺少对 moderation model bean 的注册调用:
AiService aiServiceAnnotation = (AiService)aiServiceClass.getAnnotation(AiService.class);
addBeanReference(ChatLanguageModel.class, ...);
addBeanReference(StreamingChatLanguageModel.class, ...);
addBeanReference(ChatMemory.class, ...);
addBeanReference(ChatMemoryProvider.class, ...);
addBeanReference(ContentRetriever.class, ...);
addBeanReference(RetrievalAugmentor.class, ...);
addBeanReference(ModerationModel.class, ...); // <- this is missing!!
1条答案
按热度按时间f4t66c6m1#
感谢benedictstrube的举报!