Skip to content

fix(openai): map the file citations of the code interpreter - #1060

Open
skybleak333 wants to merge 1 commit into
prism-php:mainfrom
skybleak333:fix/openai-container-file-citation
Open

skybleak333 wants to merge 1 commit into
prism-php:mainfrom
skybleak333:fix/openai-container-file-citation

Conversation

@skybleak333

Copy link
Copy Markdown

Description

When the code interpreter writes a file (a chart, a CSV), OpenAI annotates the text that mentions it with a container_file_citation, or a file_path on older models. CitationsMapper only knew file_citation and url_citation and threw for anything else, so asText() and asStructured() failed with InvalidArgumentException: Unknown citation source type: container_file_citation, after OpenAI had already run and billed the request.

Both types are now mapped to a Document citation, with the file name (or the file id for file_path) as the source and the ids in additionalContent (containerId, fileId), which is what the containers and files APIs need to download the file. When the message goes back in a later request, they're sent as the type they came in as, not as a url_citation. An annotation type the mapper doesn't know is skipped, so a new one won't fail a response that was already produced.

The four annotation types are the ones in the official SDK (openai-python, types/responses/response_output_text.py).

New tests: the mapper round trip for both types, an unknown type being skipped, and a code interpreter response with a container_file_citation through asText(). All four fail without the change. The full suite, PHPStan, Pint and Rector pass.

This branch has not been deployed

No deployments
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.

1 participant