googleapis / googleapis/python-genai
How can I pass custom filenames to Gemini API for CSV files? (display_name not supported)
- Dominant language
- Python
- Stars
- 4k
- Forks
- 1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 40
Description
Environment:
OS: Ubuntu 20.04.6 LTS
Lang: Python 3.12
python-genai ver: v1.19.0(latest)
Gemini Model: models/gemini-2.0-flash
I'm trying to use Gemini to compare data differences between two CSV files and generate charts, using the following code:
```python3
history = [{"role": "user", "text": question, "gname": ujson.dumps(["files/wox6h1vnz9as", "files/2clsiimgvdsf"])},]
history_contexts = await get_session_history(ai_client, history, localdb_content)
print("1==============", history_contexts)
# history_contexts: [
# UserContent(parts=[
# Part(video_metadata=None, thought=None, inline_data=None, file_data=None, thought_signature=None, code_execution_result=None, executable_code=None,
# function_call=None, function_response=None, text='Group and calculate the total quantity by different categories in two files, and compare the data changes between the two files'),
# Part(video_metadata=None, thought=None, inline_data=None,
# file_data=FileData(display_name='inventory-2025-04-08.csv',
# file_uri='https://generativelanguage.googleapis.com/v1beta/files/wox6h1vnz9as',
# mime_type='text/csv'),
# thought_signature=None, code_execution_result=None, executable_code=None, function_call=None, function_response=None, text=None),
# Part(video_metadata=None, thought=None, inline_data=None,
# file_data=FileData(display_name='inventory-2025-04-03.csv',
# file_uri='https://generativelanguage.googleapis.com/v1beta/files/2clsiimgvdsf',
# mime_type='text/csv'),
# thought_signature=None, code_execution_result=None, executable_code=None, function_call=None, function_response=None, text=None)], role='user'),
# ]
async for chunk in await ai_client.aio.models.generate_content_stream(
model=modelname,
contents=history_contexts,
config=genai.types.GenerateContentConfig(
systemInstruction=[
instructs['identify'],
# instructs['html_style'],
],
)
):
yield f"200: {chunk.text}"
```
Note that I passed `file_data` containing `display_name` information in the `contents` parameter of the `generate_content_stream` method. However, I encountered the error: "display_name parameter is not supported in Gemini API".
```
File "/opt/src/views/utils/genai_files.py", line 554, in test_geni_models
async for chunk in await ai_client.aio.models.generate_content_stream(
File "/root/.cache/pypoetry/virtualenvs/scm-robot-eP1Loqjb-py3.12/lib/python3.12/site-packages/google/genai/models.py", line 7614, in async_generator
response = await self._generate_content_stream(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/scm-robot-eP1Loqjb-py3.12/lib/python3.12/site-packages/google/genai/models.py", line 6513, in _generate_content_stream
request_dict = _GenerateContentParameters_to_mldev(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/scm-robot-eP1Loqjb-py3.12/lib/python3.12/site-packages/google/genai/models.py", line 929, in _GenerateContentParameters_to_mldev
_Content_to_mldev(api_client, item, to_object)
File "/root/.cache/pypoetry/virtualenvs/scm-robot-eP1Loqjb-py3.12/lib/python3.12/site-packages/google/genai/models.py", line 170, in _Content_to_mldev
_Part_to_mldev(api_client, item, to_object)
File "/root/.cache/pypoetry/virtualenvs/scm-robot-eP1Loqjb-py3.12/lib/python3.12/site-packages/google/genai/models.py", line 121, in _Part_to_mldev
_FileData_to_mldev(
File "/root/.cache/pypoetry/virtualenvs/scm-robot-eP1Loqjb-py3.12/lib/python3.12/site-packages/google/genai/models.py", line 79, in _FileData_to_mldev
raise ValueError('display_name parameter is not supported in Gemini API.')
```
After I removed the `display_name` parameter from the `file_data`, the charts generated successfully. However, the two files lost their original filenames in the charts and are displayed as "file1" and "file2".
I want to know how to explicitly pass the filenames into the Gemini API. I found the [relevant code](https://github.com/googleapis/python-genai/blob/2f448bc2b8d2b09b6abc0ddba829610c227cf979/google/genai/models.py#L79) and tried using parameters like "displayName", "filename", "fileName", and "file_name", but all attempts failed.
Is there a way to pass custom filenames to the Gemini API?
Contributor guide
Assessment
This issue has not been assessed yet.