Skip to content

Comments

Fix google call params error 936#937

Merged
willbakst merged 8 commits intoMirascope:mainfrom
ionflow:fix-google-call-params-error-936
Apr 2, 2025
Merged

Fix google call params error 936#937
willbakst merged 8 commits intoMirascope:mainfrom
ionflow:fix-google-call-params-error-936

Conversation

@ionflow
Copy link
Contributor

@ionflow ionflow commented Mar 28, 2025

Closes: #936

Fix: Improve handling of configuration parameters in Google API calls

Issue: Error when calling google with call_params #936

Description

This PR fixes an issue where the Google API would fail with an AsyncModels.generate_content() got an unexpected keyword argument 'generation_config' error when using call_params.

The root problem was in how common parameters were being transferred from the conversion function to the actual API call configuration. By addressing this at the source, we've created a more robust solution that follows the codebase's established patterns.

Changes

  • Implemented a cleaner approach to handling parameters in _setup_call.py by properly transferring generation_config parameters to the API's required config object
  • Ensured stop sequences are always correctly formatted as arrays in _convert_common_call_params.py to match Google API requirements

Tests

  • Fixed the existing test file tests/core/google/test_call_params.py to properly type-cast parameters
  • Verified API compatibility with careful parameter handling

This code now doesn't fail:

from mirascope import llm
from mirascope.core import google
from pydantic import BaseModel
from dotenv import load_dotenv
import os
import asyncio

load_dotenv()

class Book(BaseModel):
    title: str
    author: str

os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")

@llm.call(
    provider="google",
    model="gemini-2.0-flash",
    json_mode=True,
    response_model=Book,
)
async def recommend_book(genre: str) -> str:
    return f"Recommend a {genre} book"

async def main():
    override_response = await llm.override(
        recommend_book,
        provider="google",
        model="gemini-2.0-flash",
        call_params={"max_tokens": 100, "temperature": 0.7},
    )("fantasy")
    
    print(override_response)

if __name__ == "__main__":
    asyncio.run(main())

@ionflow ionflow requested a review from willbakst March 28, 2025 23:25
@ionflow ionflow requested a review from willbakst March 31, 2025 19:26
willbakst
willbakst previously approved these changes Apr 1, 2025
@codecov
Copy link

codecov bot commented Apr 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (093ebb5) to head (f1fde32).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #937   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          515       515           
  Lines        21070     21109   +39     
=========================================
+ Hits         21070     21109   +39     
Flag Coverage Δ
tests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- test_convert_common_call_params.py already tests that the call parameters are correctly converted
- test_setup_call.py tests that call parameters are correctly passed through to setup_call
@willbakst willbakst merged commit ba163f6 into Mirascope:main Apr 2, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when calling google with call_params

2 participants