Normalize file api's to allow providers to use them
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3546954. -->
Reported by: [marcus_johansson](https://www.drupal.org/user/385947)
Related to !899
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>There are some providers that offers file api's that lets you upload files for reasons like:</p>
<ul>
<li>Use at inference</li>
<li>Use for finetuning</li>
<li>Use for vector searching.</li>
<li>Instructions for Batch API's</li>
<li>Use for evals</li>
<li>etc.</li>
</ul>
<p>Some examples of providers api documentation includes:</p>
<ul>
<li><a href="https://platform.openai.com/docs/api-reference/files/create">https://platform.openai.com/docs/api-reference/files/create</a></li>
<li><a href="https://docs.anthropic.com/en/docs/build-with-claude/files">https://docs.anthropic.com/en/docs/build-with-claude/files</a></li>
<li><a href="https://docs.fireworks.ai/api-reference/upload-dataset-files">https://docs.fireworks.ai/api-reference/upload-dataset-files</a></li>
<li><a href="https://docs.mistral.ai/api/#tag/files/operation/files_api_routes_upload_file">https://docs.mistral.ai/api/#tag/files/operation/files_api_routes_upload_file</a></li>
<li><a href="https://ai.google.dev/gemini-api/docs/files">https://ai.google.dev/gemini-api/docs/files</a></li>
<li>
</ul>
<p>Note that this is an incomplete list, and more providers will have them or will have them in the future.</p>
<p>We need some way of normalizing this, or come the conclussion that they differ so much, that we only decide to normalize a way of utilizing them in Chat or other requests.</p>
<p>What is important to take into consideration is that this is the first time in the AI module a request would become stateful. At the current time, you can for instance use an agent and have each loop run by a different provider, because all information required for the provider to do inference is provided in the request, including chat history, tool calling etc. </p>
<p>As soon as we add a provider specific id of a file, in a Chat request, that is not true anymore. So we have to think of ways to ease this into UI/UX for any third party provider that might want to integrate it.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<ul>
<li>Normalize common methods (upload, download, list, delete).</li>
<li>Track file existence, owner and provider for further use</li>
<li>Error gracefully when files don't exist/fail (retention in unknown and varies)</li>
<li>Generate issues for known providers to use this.</li>
</ul>
issue