問題
在學習spring-ai-alibaba時,發現1.0.0.2版本在自動裝配DashScopeCloudStore時,會報如下錯誤:
Field dashScopeCloudStore in com.example.spring_ai_alibaba_examples.examples.SpringAiAlibabaExample01 required a bean of type 'com.alibaba.cloud.ai.dashscope.rag.DashScopeCloudStore' that could not be found.
意思是沒有找到DashScopeCloudStore
原因分析
查看了一下spring-ai-alibaba-autoconfigure-dashscope包里確實沒有提供對應的Bean,也就是說該類沒有自動裝配
上網搜了一下,發現1.0.0-M6.1版本已經有人提出過這個問題了(DashScopeCloudStore Auto-configuration 注入問題 · Issue #84 · springaialibaba/spring-ai-alibaba-website),仍然是open狀態,尚未解決
問題解決
那就只能自己創建一個了
this.dashScopeCloudStore = new DashScopeCloudStore(DashScopeApi.builder().apiKey("your api key").build(), new DashScopeStoreOptions("知識庫名稱"));
這只是一個最簡化樣例,在創建DashScopeApi和DashScopeStoreOptions的時候可以添加許多其他參數
優化建議
建議官方提供一個自動裝配的DashScopeApi
然后就可以通過以下方式使用DashScopeCloudStore
?
@Beanpublic DashScopeCloudStore dashScopeCloudStore(DashScopeApi dashScopeApi) {return new DashScopeCloudStore(dashScopeApi, new DashScopeStoreOptions("測試庫"));}