Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function calling example in SDK documentation gives INVALID_ARGUMENT error #81

Open
robince opened this issue Jan 6, 2025 · 1 comment · May be fixed by #86
Open

Function calling example in SDK documentation gives INVALID_ARGUMENT error #81

robince opened this issue Jan 6, 2025 · 1 comment · May be fixed by #86
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@robince
Copy link

robince commented Jan 6, 2025

Environment details

  • Programming language: Python
  • OS: Mac OS X 14.7.2 Apple Silicon
  • Language runtime version: Python 3.11.10
  • Package version: 0.3.0

Steps to reproduce

  1. Run verbatim the example code from the SDK documentation: https://googleapis.github.io/python-genai/#automatic-python-function-support (after fixing a typo
    function_reponse -> function_response)
  2. The final call to generate_content gives an error:
response = client.models.generate_content(
    model='gemini-2.0-flash-exp',
    contents=[
        types.Part.from_text("What is the weather like in Boston?"),
        function_call_part,
        function_response_part,
    ])

ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Please ensure that function call turn contains at least one function_call part which can not be mixed with function_response parts.', 'status': 'INVALID_ARGUMENT'}}
@robince robince added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 6, 2025
@robince robince changed the title Function calling example in SDK documentation gives INVALID_ARGUMENT errro Function calling example in SDK documentation gives INVALID_ARGUMENT error Jan 6, 2025
@robince
Copy link
Author

robince commented Jan 7, 2025

This works if I pass Contents instead of Parts:

user_prompt_content = types.Content(
    role="user", parts=[types.Part.from_text("What is the weather like in Boston?")]
)
function_call_content = response.candidates[0].content
function_response_content = types.Content(role="tool", parts=[function_response_part])

response = client.models.generate_content(
    model="gemini-2.0-flash-exp",
    contents=[
        user_prompt_content,
        function_call_content,
        function_response_content,
    ],
    config=types.GenerateContentConfig(
        tools=[tool],
    ),
)

@robince robince linked a pull request Jan 7, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant