SpringAI-RC1正式發布:移除千帆大模型!
續 Spring AI M8 版本之后(5.1 發布),前幾日 Spring AI 悄悄的發布了最新版 Spring AI 1.0.0 RC1(5.13 發布),此版本也將是 GA(Generally Available,正式版)發布前的最后一個版本,正式版計劃在 5.20 日發布。
這個版本的改動相比于上一個版本 M8 來說,改動不算很大,但也有一些讓我們意想不到的版本更新,接下來一起來看。
移除千帆大模型 SDK
和國內開發者關系比較大的一個更新就是 Spring AI RC1 移除了百度的千帆大模型,給出的原因是中國境外無法訪問,所以被移除了,官方文檔中千帆的對接文檔也被刪除了,變成這個樣子了:
這樣一來,Spring AI 直接對接國內的大模型就剩下 DeepSeek 和智普 AI 這兩家公司了。
國內的阿里的百煉平臺也沒有直接提供 SDK 對接,算是比較遺憾的,因為國內使用通義大模型的公司是非常多的,并且百煉平臺內置了 200+ 家大模型,對接百煉相當于對接了 200+ 大模型。當然我們可以使用 OpenAI 協議接入它,但這就意味著,我們在這個項目中不能同時在接入 OpenAI 大模型了,希望后期官方能提供百煉平臺的 SDK 對接方式。
其他重要更新
- VectorStoreChatMemoryAdvisor 更新:
a.常量 CHAT_MEMORY_RETRIEVE_SIZE_KEY 被重命名為 TOP_K。
b.常量 DEFAULT_CHAT_MEMORY_RESPONSE_SIZE 被重命名為 DEFAULT_TOP_K,并且其默認值從 100 調成為 20。
- 常量 CHAT_MEMORY_CONVERSATION_ID_KEY 被重命名為 CONVERSATION_ID,并從 AbstractChatMemoryAdvisor 移動到 ChatMemory。請更新您的導入以使用 org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID。
- 問答中增加了自包含模版,例如:
- query 用于接收用戶問題的占位符。
- 用于接收檢索到的上下文的占位符 question_answer_context。
- 使用示例如下:
- QuestionAnswerAdvisor 具有以下占位符:
PromptTemplate customPromptTemplate = PromptTemplate.builder()
.renderer(StTemplateRenderer.builder().startDelimiterToken('<').endDelimiterToken('>').build())
.template("""
<query>
Context information is below.
---------------------
<question_answer_context>
---------------------
Given the context information and no prior knowledge, answer the query.
Follow these rules:
1. If the answer is not in the context, just say that you don't know.
2. Avoid statements like "Based on the context..." or "The provided information...".
""")
.build();
String question = "Where does the adventure of Anacletus and Birba take place?";
QuestionAnswerAdvisor qaAdvisor = QuestionAnswerAdvisor.builder(vectorStore)
.promptTemplate(customPromptTemplate)
.build();
String response = ChatClient.builder(chatModel).build()
.prompt(question)
.advisors(qaAdvisor)
.call()
.content();
- PromptChatMemoryAdvisor 具有以下占位符:
* instructions 接收原始系統消息的占位符。
* memory用于接收檢索到的對話記憶的占位符。
- VectorStoreChatMemoryAdvisor 具有以下占位符:
* instructions 接收原始系統消息的占位符。
* long_term_memory 用于接收檢索到的對話記憶的占位符。
組件重命名:
- spring-ai-model-chat-memory- → spring-ai-model-chat-memory-repository-
- spring-ai-autoconfigure-model-chat-memory- → spring-ai-autoconfigure-model-chat-memory-repository-
- spring-ai-starter-model-chat-memory- → spring-ai-starter-model-chat-memory-repository-
- org.springframework.ai.chat.memory.jdbc → org.springframework.ai.chat.memory.repository.jdbc
- JdbcChatMemoryAutoConfiguration → JdbcChatMemoryRepositoryAutoConfiguration
- spring.ai.chat.memory.… → spring.ai.chat.memory.repository.…
其他升級請查看官方更新日志:https://docs.spring.io/spring-ai/reference/upgrade-notes.html#upgrading-to-1-0-0-RC1
小結
AI 發展速度很快,對各行各業的影響也很大。充分了解和掌握 AI 知識,對日常工作提效或以后跳槽都有很大的幫助,讓我們一起行動起來,擁抱這場 AI 盛宴吧。