Add Google AI Studio /v1/files upload API support (#9645)

* test: fix import for test

* fix: fix bad error string

* docs: cleanup files docs

* fix(files/main.py): cleanup error string

* style: initial commit with a provider/config pattern for files api

google ai studio files api onboarding

* fix: test

* feat(gemini/files/transformation.py): support gemini files api response transformation

* fix(gemini/files/transformation.py): return file id as gemini uri

allows id to be passed in to chat completion request, just like openai

* feat(llm_http_handler.py): support async route for files api on llm_http_handler

* fix: fix linting errors

* fix: fix model info check

* fix: fix ruff errors

* fix: fix linting errors

* Revert "fix: fix linting errors"

This reverts commit 926a5a527f.

* fix: fix linting errors

* test: fix test

* test: fix tests
This commit is contained in:
Krish Dholakia 2025-04-02 08:56:58 -07:00 committed by GitHub
parent d1abb9b68b
commit 0519c0c507
40 changed files with 1006 additions and 245 deletions

View file

@ -1481,9 +1481,9 @@ class OpenAIFilesAPI(BaseLLM):
self,
create_file_data: CreateFileRequest,
openai_client: AsyncOpenAI,
) -> FileObject:
) -> OpenAIFileObject:
response = await openai_client.files.create(**create_file_data)
return response
return OpenAIFileObject(**response.model_dump())
def create_file(
self,
@ -1495,7 +1495,7 @@ class OpenAIFilesAPI(BaseLLM):
max_retries: Optional[int],
organization: Optional[str],
client: Optional[Union[OpenAI, AsyncOpenAI]] = None,
) -> Union[FileObject, Coroutine[Any, Any, FileObject]]:
) -> Union[OpenAIFileObject, Coroutine[Any, Any, OpenAIFileObject]]:
openai_client: Optional[Union[OpenAI, AsyncOpenAI]] = self.get_openai_client(
api_key=api_key,
api_base=api_base,
@ -1518,8 +1518,8 @@ class OpenAIFilesAPI(BaseLLM):
return self.acreate_file( # type: ignore
create_file_data=create_file_data, openai_client=openai_client
)
response = openai_client.files.create(**create_file_data)
return response
response = cast(OpenAI, openai_client).files.create(**create_file_data)
return OpenAIFileObject(**response.model_dump())
async def afile_content(
self,