Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: OpenAI Web Search Annotations #2460

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

apappascs
Copy link
Contributor

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 (with Annotation and UrlCitation records) to ChatCompletionMessage in OpenAiApi.java.
  • Updated OpenAiChatModel to populate the annotations field (via metadata) for both regular and streaming responses.
  • Added integration tests (webSearchAnnotationsTest, streamWebSearchAnnotationsTest) to OpenAiChatModelIT.java.
  • Added GPT_4_O_SEARCH_PREVIEW and GPT_4_O_MINI_SEARCH_PREVIEW to OpenAiApi.ChatModel.
  • Added WebSearchOptions and related records to OpenAiApi.
  • Minor updates to ChatCompletionRequest and its Builder.

Resolves #2449

This PR adds support for retrieving web search annotations from the OpenAI API, as described in their [web search documentation](https://platform.openai.com/docs/guides/web-search).  This allows us to access citation URLs and their context within generated responses when using models like `gpt-4o-search-preview`.

**Changes:**

*   Added `annotations` (with `Annotation` and `UrlCitation` records) to `ChatCompletionMessage` in `OpenAiApi.java`.
*   Updated `OpenAiChatModel` to populate the `annotations` field (via metadata) for both regular and streaming responses.
*   Added integration tests (`webSearchAnnotationsTest`, `streamWebSearchAnnotationsTest`) to `OpenAiChatModelIT.java`.
*   Added `GPT_4_O_SEARCH_PREVIEW` and `GPT_4_O_MINI_SEARCH_PREVIEW` to `OpenAiApi.ChatModel`.
*   Added `WebSearchOptions` and related records to `OpenAiApi`.
*   Minor updates to `ChatCompletionRequest` and its `Builder`.

Resolves spring-projects#2449

Signed-off-by: Alexandros Pappas <[email protected]>
@zainlateef
Copy link

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;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lacks support for annotations field in OpenAI's chat completion object
2 participants