autogen icon indicating copy to clipboard operation
autogen copied to clipboard

Fixes “The model produced invalid content” error when calling functions

Open davorrunje opened this issue 1 year ago • 7 comments

Why are these changes needed?

This fixes the issue related to the more strict checking of JSON parameters in function calling as described here:

https://community.openai.com/t/error-the-model-produced-invalid-content/747511

This PR removes the 'name' parameter from messages in OpenAI client. It also introduces an additional parameter in the tool JSON specification that was previously missing.

Related issue number

Closes #3247

Checks

  • [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation to build and test documentation locally.
  • [x] I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • [x] I've made sure all auto checks have passed.

davorrunje avatar Aug 27 '24 11:08 davorrunje

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Please upload report for BASE (0.2@5ad2677). Learn more about missing BASE report.

Files with missing lines Patch % Lines
autogen/oai/client.py 77.77% 2 Missing :warning:
Additional details and impacted files
@@          Coverage Diff           @@
##             0.2    #3429   +/-   ##
======================================
  Coverage       ?   29.61%           
======================================
  Files          ?      117           
  Lines          ?    13022           
  Branches       ?     2469           
======================================
  Hits           ?     3856           
  Misses         ?     8819           
  Partials       ?      347           
Flag Coverage Δ
unittests 29.59% <80.00%> (?)

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Aug 27 '24 11:08 codecov-commenter

@davorrunje, thanks for creating this - interesting that OpenAI are also removing name. This is likely to affect group chat with speaker selection. May need to incorporate the recent name transforms as a simpler integration for that (but that's for another discussion/time :) ).

I'll give it a test...

marklysze avatar Aug 27 '24 20:08 marklysze

More about this error: https://community.openai.com/t/bizarre-issue-preventing-response-from-gpt-4o-mini-the-model-produces-invalid-content/875432

davorrunje avatar Aug 28 '24 05:08 davorrunje

@davorrunje, thanks again for working on a fix for the exception.

Would you have an example that I could use to replicate the exception?

marklysze avatar Aug 28 '24 06:08 marklysze

Hi , I have the same error "The model produced invalid content” error when calling functions", how I can apply this fix, any idea ?

lmcmahi avatar Aug 29 '24 18:08 lmcmahi

Hi , I have the same error "The model produced invalid content” error when calling functions", how I can apply this fix, any idea ?

Hi @lmcmahi, would you be able to provide a code sample that produces this error? It would help in testing out viable fixes.

marklysze avatar Aug 29 '24 23:08 marklysze

Hi, I've encountered exactly the same error, having you find a good solution?

zhwuwuwu avatar Sep 19 '24 08:09 zhwuwuwu

@davorrunje would you say the proposed fix is still necessary after gpt-4o-2024-08-06?

ekzhu avatar Oct 24 '24 00:10 ekzhu

Looks like this is dormant, if you want to pick this up again please feel free to reopen. Thanks!

jackgerrits avatar Feb 25 '25 21:02 jackgerrits