spring-ai
spring-ai copied to clipboard
feat: OpenAI Web Search Annotations
This PR adds support for retrieving web search annotations from the OpenAI API, as described in their web search documentation. This allows us to access citation URLs and their context within generated responses when using models like gpt-4o-search-preview.
Changes:
- Added
annotations(withAnnotationandUrlCitationrecords) toChatCompletionMessageinOpenAiApi.java. - Updated
OpenAiChatModelto populate theannotationsfield (via metadata) for both regular and streaming responses. - Added integration tests (
webSearchAnnotationsTest,streamWebSearchAnnotationsTest) toOpenAiChatModelIT.java. - Added
GPT_4_O_SEARCH_PREVIEWandGPT_4_O_MINI_SEARCH_PREVIEWtoOpenAiApi.ChatModel. - Added
WebSearchOptionsand related records toOpenAiApi. - Minor updates to
ChatCompletionRequestand itsBuilder.
Resolves #2449
As a temporary workaround, add this objectMapper to your main class
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper;
}
}
@apappascs Thanks very much for the PR! Rebased and merged as 6c9b4d6cd