googleapis / googleapis/python-genai
Safety Settings Configuration in Batch mode with jsonl file
- Dominant language
- Python
- Stars
- 4k
- Forks
- 1k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 40
Description
hello,
how can I set the safety_settings while in batch mode and upload .jsonl file to create batch job using python api?
below is the template of each line of my upload .jsonl file
how can I modify below to make it work with the `safety_settings` setting?
```python
template = {
"key": f"low_{LANGUAGE_LIST[l]}_{i}",
"request": {
"contents": [
{"role": "model", "parts": [{"text": "test"}]},
{
"role": "user",
"parts": [{"text": "test"}],
},
],
"generation_config": {
"temperature": 0,
"thinkingConfig": {"includeThoughts": False, "thinkingBudget": 0},
"safety_settings": [
{
"category": "HARM_CATEGORY_UNSPECIFIED ",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_NONE",
},
],
},
},
}
```
below is the error I got, which is similar to #1271
```python
103 status_code = response.status_code
104 if 400 <= status_code < 500:
--> [105](file:///C:/Users/Ydam/anaconda3/envs/dev/lib/site-packages/google/genai/errors.py:105) raise ClientError(status_code, response_json, response)
106 elif 500 <= status_code < 600:
107 raise ServerError(status_code, response_json, response)
ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': "Error on line 1: invalid JSON, near column 103: no such field: 'safety_settings'\nError on line 2: invalid JSON, near column 103: no such field: 'safety_settings'\nError on line 3: invalid JSON, near column 555: no such field: 'safety_settings'\nError on line 4: invalid JSON, near column 119: no such field: 'safety_settings'\nError on line 5: invalid JSON, near column 519: no such field: 'safety_settings'\nError on line 6: invalid JSON, near column 41: no such field: 'safety_settings'\nError on line 7: invalid JSON, near column 41: no such field: 'safety_settings'\nError on line 8: invalid JSON, near column 103: no such field: 'safety_settings'\nError on line 9: invalid JSON, near column 531: no such field: 'safety_settings'\nError on line 10: invalid JSON, near column 41: no such field: 'safety_settings'", 'status': 'INVALID_ARGUMENT'}}
```
Contributor guide
Assessment
This issue has not been assessed yet.