gemini_utils
convert_dict_to_input
Convert dictionary to an input that can be used by the Gemini API. The output is a dictionary with keys “role” and “parts”.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_dict
|
dict
|
Content dictionary with keys “role” and “parts” where the values are strings. |
required |
media_folder
|
str
|
Folder where media files are stored ({data_folder}/media). |
required |
Returns:
| Type | Description |
|---|---|
dict
|
dict with keys “role” and “parts” where the value of role is either “user” or “model” and the value of parts is a list of inputs to make up an input (which can include text or image/video inputs). |
Source code in src/prompto/apis/gemini/gemini_utils.py
parse_parts
Parse parts data and create a list of multimedia data objects. If parts is a single dictionary, a list with a single multimedia data object is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parts
|
list[dict | str] | dict | str
|
Parts data to parse and create Part object(s). Can be a list of dictionaries and strings, or a single dictionary or string. |
required |
media_folder
|
str
|
Folder where media files are stored ({data_folder}/media). |
required |
Returns:
| Type | Description |
|---|---|
list[any]
|
List of multimedia data object(s) created from the input multimedia data |
Source code in src/prompto/apis/gemini/gemini_utils.py
parse_parts_value
Parse part dictionary and create a dictionary input for Gemini API. If part is a string, a dictionary to represent a text object is returned. If part is a dictionary, expected keys are: - type: str, multimedia type, one of [“text”, “image”, “file”] - media: str, file location (if type is image or file), text (if type is text)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
part
|
dict | str
|
Either a dictionary or a string which defines a multimodal object. |
required |
media_folder
|
str
|
Folder where media files are stored ({data_folder}/media). |
required |
Returns:
| Type | Description |
|---|---|
any
|
Multimedia data object |
Source code in src/prompto/apis/gemini/gemini_utils.py
process_response
Helper function to process the response from Gemini API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
dict
|
The response from the Gemini API as a dictionary |
required |
Returns:
| Type | Description |
|---|---|
str
|
The processed response text as a string |
Source code in src/prompto/apis/gemini/gemini_utils.py
process_safety_attributes
Helper function to process the safety attributes from Gemini API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
dict
|
The response from the Gemini API as a dictionary |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The safety attributes as a dictionary with category names as keys and their respective probabilities as values. Additionally, the dictionary contains a key ‘blocked’ with a list of booleans indicating whether each category is blocked, and ‘finish_reason’ |