先行一步
VMware 提供培訓和認證,助您快速進步。
瞭解更多我們很高興宣佈 Spring AI 的 1.0.0 M4 里程碑版本釋出。
此版本修復了大部分報告的錯誤,並在各個領域帶來了顯著增強。
Spring AI 現在支援 Amazon Bedrock Converse API,它為 Amazon 提供的 AI 對話模型提供了一個統一介面。與舊的 Bedrock Invoke API 不同,Converse 引入了令人興奮的新功能,例如 工具呼叫 (Tool Calling) 和 多模態/視覺能力 (Multimodality/Visual capabilities)(適用於支援這些功能的模型)。這使得它成為使用 Amazon 對話模型更強大和靈活的選擇。
在許多方面,Converse API 的作用類似於 Spring AI 本身,提供跨模型 API 的可移植性,但僅限於 Amazon 的對話模型。我們建議將對話模型遷移到 Converse 模組。請注意,嵌入模型不受影響。
有關此新功能的詳細資訊,請參閱 Spring AI Bedrock Converse 文件。您還可以關注 即將進行的改進 以獲取未來的增強功能。非常感謝 Max Jiang 啟動這項大型工作。
最近的改進透過 FunctionCallback
Builder 類擴充套件了對各種函式型別和方法的支援。這允許呼叫 java.util.Function
、Supplier
和 Consumer
介面。
FunctionCallback callback = FunctionCallback.builder()
.description("Process a new order")
.function("processOrder", (Order order) -> processOrderLogic(order))
.inputType(Order.class)
.build();
使用 BiFunction<I, ToolContext, O>
透過 ToolContext
訪問附加狀態或上下文
@Bean
@Description("Get the weather in location")
public BiFunction<WeatherService.Request, ToolContext, WeatherService.Response> weatherFunctionWithContext() {
return (request, context) -> new MockWeatherService().apply(request);
}
方法呼叫支援為 M5 中即將推出的 @ToolMapping
註解提供了基礎
public static class LightControl {
private static final Logger logger = LoggerFactory.getLogger(LightControl.class);
private final Map<String, Object> arguments = new HashMap<>();
public void controlLight(String roomName, boolean on) {
arguments.put("roomName", roomName);
arguments.put("on", on);
logger.info("Setting light in room '{}' to: {}", roomName, on ? "ON" : "OFF");
}
}
用法
LightControl lightControl = new LightControl();
String response = ChatClient.create(this.chatModel)
.prompt("Turn light on in the living room.")
.functions(
FunctionCallback.builder()
.description("Controls lights by room name, allowing them to be turned on or off.")
.method("controlLight", String.class, boolean.class)
.targetObject(lightControl)
.build()
)
.call()
.content();
有關附加功能,請查閱涵蓋以下內容的 FunctionCallback 文件
ParameterizedTypeReference
支援泛型輸入型別Spring AI 引入了對 Kotlin 的支援,使 Kotlin 開發人員能夠更輕鬆地將 AI 能力整合到他們的應用程式中。此版本引入了地道的 Kotlin 擴充套件和型別安全的 API。非常感謝 Sebastien Deleuze 承擔這項工作。
新的 Kotlin 擴充套件提供了更簡潔、型別安全的方式來處理 AI 響應。現在,您可以使用 Kotlin 的 reified 泛型,而不是 Java 風格的型別宣告
import org.springframework.ai.chat.client.entity
data class Joke(val setup: String, val punchline: String)
@SpringBootApplication
class KotlinHelloWorldApplication {
@Bean
fun jokeRunner(chatModel: ChatModel) = CommandLineRunner {
val response = ChatClient.create(chatModel).prompt().user("Tell me a joke").call().entity<Joke>()
println("\nJoke:")
println("Setup: ${response.setup}")
println("Punchline: ${response.punchline}")
}
}
fun main(args: Array<String>) {
runApplication<KotlinHelloWorldApplication>(*args)
}
Kotlin 函式現在可以直接註冊為 AI 工具。語法很簡單
@Configuration
class Config {
@Bean
fun weatherFunctionInfo(currentWeather: (WeatherRequest) -> WeatherResponse): FunctionCallback {
return FunctionCallback.builder()
.description(
"Find the weather conditions, forecasts, and temperatures for a location, like a city or state."
)
.function("WeatherInfo", currentWeather)
.inputType(WeatherRequest::class.java)
.build()
}
@Bean
@Description("Get current weather")
fun currentWeather(): (WeatherRequest) -> WeatherResponse = { request ->
MockKotlinWeatherService().invoke(request)
}
}
然後,可以按如下方式使用。
@Bean
open fun init(chatModel: ChatModel) = CommandLineRunner {
try {
val userMessage = UserMessage(
"What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations."
)
val response = chatModel.call(
Prompt(
listOf(userMessage),
OpenAiChatOptions.builder().withFunction("WeatherInfo").build()
)
)
println("Response: $response")
}
catch (e: Exception) {
println("Error during weather check: ${e.message}")
}
}
參考文件已更新,包含 Kotlin 示例,您可以在 spring-ai-examples 倉庫中找到其他示例。
倉庫 awesome-spring-ai 延續了其他“awseome”倉庫的主題,收集了與 Spring AI 相關的社群資源,如書籍、演示、示例程式碼等。如果您發現了任何有用的材料,請向該倉庫提交 PR。
倉庫 spring-ai-integration-tests 現已可用,並正在取得進展,每天兩次執行整個專案的整合測試。
倉庫 spring-ai-examples 現已可用於託管“官方”示例。檢視反射代理示例!
此外,作為對該專案的介紹,請檢視部落格文章 為何選擇 Spring AI
Spring AI 引入了對基於模組化 RAG 系統設計最新研究的先進檢索增強生成 (RAG) 的實驗性支援,特別是論文 Modular RAG: Transforming RAG Systems into LEGO-like Reconfigurable Frameworks 和 Retrieval-Augmented Generation for Large Language Models: A Survey。非常感謝 Thomas Vittale 領導這項工作。
以下是關鍵構建塊
預檢索元件
QueryTransformer
: 轉換查詢以提高檢索效率(例如,翻譯、重寫)QueryExpander
: 將單個查詢擴充套件為多個變體以捕獲更廣泛的上下文編排元件
QueryRouter
: 根據元資料或語義分析將查詢路由到適當的檢索器檢索元件
DocumentRetriever
: 用於檢索相關文件的核心介面DocumentJoiner
: 合併來自多個檢索器/查詢的結果後檢索元件
DocumentCompressor
: 在保留關鍵資訊的同時減少文件內容DocumentRanker
: 按相關性對文件重新排序DocumentSelector
: 根據條件過濾檢索到的文件增強元件
QueryAugmenter
: 使用檢索到的上下文增強查詢ContextualQueryAugmenter
: 專注於文件上下文整合的預設實現基於我們的模組化 RAG 元件,RetrievalAugmentationAdvisor
提供了一個實現,幫助您入門並提供線性的 RAG 流程
您可以在 bean 定義中將這些協作的構建塊元件組合在一起,例如
@Bean
public RetrievalAugmentationAdvisor customRagAdvisor(VectorStore vectorStore) {
return RetrievalAugmentationAdvisor.builder()
.queryTransformers(List.of(new TranslationQueryTransformer(...)))
.queryExpander(new MultiQueryExpander(...))
.queryRouter(
AllRetrieversQueryRouter.builder()
.documentRetrievers(new VectorStoreDocumentRetriever(...))
.build()
)
.documentJoiner(new ConcatenationDocumentJoiner())
.queryAugmenter(new ContextualQueryAugmenter(...))
.build();
}
雖然 RetrievalAugmentationAdvisor 實現了線性流程,但使用者可以實現自定義的 Advisor
來實現條件、分支、遞迴和自適應流程等高階模式。更多文件即將推出,我們鼓勵您在我們的 GitHub 問題跟蹤器上傳送反饋。
在模型模組中有幾個地方使用了 Spring Boot。現在不再是這種情況。對 Spring Boot 的唯一依賴僅限於 autoconfigure 模組。
Azure OpenAI SDK 已升級到 12 Beta 版本。
擴充套件了配置和設定文件,重點關注
透過眾多貢獻者的努力,在各個方面進行了其他重構、錯誤修復和文件增強。如果您的 PR 尚未被處理,我們會盡快處理,請耐心等待。感謝
我們計劃在 12 月下旬釋出最後一個里程碑版本 1.0.0 M5,重點關注設計問題,例如在 ChatResponse 中返回更多資訊,徹底改進 VectorStore API 以支援新增/刪除和不同的查詢型別,統一各種 Builder 的 API 風格等。然後我們將在 1 月釋出 1.0.0 RC1 版本,隨後很快釋出 1.0.0 GA 版本。