springai还是有很多坑,我是多模态模型报错。
java.lang.NullPointerException: Cannot invoke "java.lang.Integer.longValue()" because the return value of "com.alibaba.cloud.ai.dashscope.api.DashScopeApi$TokenUsage.totalTokens()" is null
是这个打印日志引起的去掉就好了
advisorSpec.advisors(new SimpleLoggerAdvisor());
org.springframework.ai.retry.NonTransientAiException: 400 - {"code":"InvalidParameter","message":"url error, please check url!","request_id":"4bb03499-1f23-92c2-8792-812ae60d9c49"}
我的URL没有问题 用的是官方样例的URL
new Media(
MimeTypeUtils.IMAGE_PNG,
new URI("https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg").toURL()
)
实际的报错原因是:正确使用多模态模型:qwen-vl-max-latest。且开启multi-model: true。感觉配置有点多余。而且这报错和实际错误相差太远了
ai:
# 阿里灵积
dash-scope:
api-key: sk-a4a1d7c881e44c32a31b9c210deb0086
chat:
options:
model: qwen-vl-max-latest
multi-model: true
org.springframework.ai.retry.NonTransientAiException: 400 {"code":"InvalidParameter.DataInspection","message":"The media format is not supported or incorrect for the data inspection.","request_id":"bc43b28b-2a90-9456-8c3b-2f679ee330c6"}
试了一下官方提供的图片 URL可以解析成功
new Media( MimeTypeUtils.IMAGE_PNG, new URI("https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg").toURL() )
使用本地花生壳映射出去的地址失败
改成Resource的形式,就不报错了。也是替代方案吧
new Media(new MediaType(MimeTypeUtils.IMAGE_PNG)
, new InputStreamResource(new FileInputStream(localFile)));