Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d9d6c65
WIP: update tests with new SDK
andrewphilipsmith Apr 23, 2025
5de42f7
More updates to tests with new SDK
andrewphilipsmith Apr 24, 2025
283a564
Update GeminiAPI class string & chat methods with new SDK
andrewphilipsmith Apr 24, 2025
ef96645
Update GeminiAPI class string & chat methods with new SDK
andrewphilipsmith Apr 24, 2025
c39ea9b
Merge branch 'update-gemini-sdk' of github.com:alan-turing-institute/…
andrewphilipsmith Apr 25, 2025
32cf50d
Update gemini_media.py
andrewphilipsmith Apr 28, 2025
c80273f
fix bug in '_get_client' method
andrewphilipsmith Apr 29, 2025
60ec15b
fix bug in '_get_client' method
andrewphilipsmith Apr 29, 2025
d561e07
linting and copilot review changes
andrewphilipsmith Apr 30, 2025
7a2af56
WIP: migrate gemini media functions
andrewphilipsmith May 1, 2025
6e66327
tweak dependency versions
andrewphilipsmith May 6, 2025
487716d
Update pyproject.toml
andrewphilipsmith May 6, 2025
9fa2ad1
WIP: attempt tighter deps version restrictions
andrewphilipsmith May 6, 2025
68b5de1
Sorted dependencies in pyproject.toml
andrewphilipsmith May 6, 2025
0ef2373
WIP: tidy up and linting
andrewphilipsmith May 6, 2025
6c975bc
Tweak to comment
andrewphilipsmith May 7, 2025
5c5f4c4
failing test to demonstrate the thinking params
andrewphilipsmith May 15, 2025
2e001df
read thinking params from general params dict
andrewphilipsmith May 15, 2025
cac04f4
Adds failing test case
andrewphilipsmith May 16, 2025
1c87646
adds parsing function
andrewphilipsmith May 16, 2025
fd23441
Add "thinking_text" key to output
andrewphilipsmith May 16, 2025
4511cf0
Minor tweaks from copilot code review
andrewphilipsmith May 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/prompto/apis/gemini/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
HarmBlockThreshold,
HarmCategory,
SafetySetting,
ThinkingConfig,
)

from prompto.apis.base import AsyncAPI
Expand Down Expand Up @@ -338,10 +339,26 @@ async def _obtain_model_inputs(
f"parameters must be a dictionary, not {type(generation_config_params)}"
)

# Derive the required ThinkingConfig from the parameters
# TBC - how do we get these values from the prompt_dict?

# Placeholder values for now
include_thoughts = False
thinking_budget = 9999

if include_thoughts is None and thinking_budget is None:
thinking_config = None
else:
thinking_config = ThinkingConfig(
include_thoughts=include_thoughts,
thinking_budget=thinking_budget,
)

gen_content_config = GenerateContentConfig(
**generation_config_params,
safety_settings=safety_settings,
system_instruction=system_instruction,
thinking_config=thinking_config,
)

return prompt, model_name, client, gen_content_config, None
Expand Down
69 changes: 69 additions & 0 deletions tests/apis/gemini/test_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
HarmBlockThreshold,
HarmCategory,
SafetySetting,
ThinkingConfig,
)

from prompto.apis.gemini import GeminiAPI
Expand Down Expand Up @@ -475,6 +476,74 @@ async def test_gemini_obtain_model_inputs(temporary_data_folders, monkeypatch):
)


@pytest.mark.xfail(
reason="This cannot work until we agree on the schema for the thinking config parameters"
)
@pytest.mark.asyncio
async def test_gemini_obtain_model_inputs_thinking_config(
temporary_data_folders, monkeypatch
):
settings = Settings(data_folder="data")
log_file = "log.txt"
monkeypatch.setenv("GEMINI_API_KEY", "DUMMY")
gemini_api = GeminiAPI(settings=settings, log_file=log_file)

# These test cases are very similar to the test above, so we will not repeat assertions for all
# attributes - only those that are relevant to the thinking config

# Case 1: test with *NO* thinking config parameters provided
test_case = await gemini_api._obtain_model_inputs(
{
"id": "gemini_id",
"api": "gemini",
"model_name": "gemini_model_name",
"prompt": "test prompt",
"parameters": {"temperature": 1, "max_output_tokens": 100},
}
)
assert isinstance(test_case, tuple)
assert isinstance(test_case[3], GenerateContentConfig)
assert test_case[3].thinking_config is None

# Case 2: test with thinking config parameters provided
# There are two possible ways we could provide the thinking config parameters.
# We need to select from one of these to options:
dummy_prompt_dicts = [
# Either within the parameters dictionary
{
"id": "gemini_id",
"api": "gemini",
"model_name": "gemini_model_name",
"prompt": "test prompt",
"parameters": {
"temperature": 1,
"max_output_tokens": 100,
"thinking_budget": 1234,
"include_thoughts": True,
},
},
# OR as top-level keys within the prompt dictionary
{
"id": "gemini_id",
"api": "gemini",
"model_name": "gemini_model_name",
"prompt": "test prompt",
"thinking_budget": 1234,
"include_thoughts": True,
"parameters": {"temperature": 1, "max_output_tokens": 100},
},
]

for dummy_prompt_dict in dummy_prompt_dicts:
test_case = await gemini_api._obtain_model_inputs(dummy_prompt_dict)

assert isinstance(test_case, tuple)
assert isinstance(test_case[3], GenerateContentConfig)
assert isinstance(test_case[3].thinking_config, ThinkingConfig)
assert test_case[3].thinking_config.thinking_budget == 1234
assert test_case[3].thinking_config.include_thoughts is True


@pytest.mark.asyncio
async def test_gemini_obtain_model_inputs_safety_filters(
temporary_data_folders, monkeypatch
Expand Down