autogen icon indicating copy to clipboard operation
autogen copied to clipboard

Json format error when using function call

Open sunyq1995 opened this issue 2 years ago • 4 comments

Hi, I'm running the given example named agentchat_function_call.ipynb in the notebook, and meet the error that " You argument should follow json format.". It looks like the assistant agent return wrong format of code, could anyone help? Thanks!

All returns:

user_proxy (to chatbot):

Draw two agents chatting with each other with an example dialog. Don't add plt.show().

--------------------------------------------------------------------------------
chatbot (to user_proxy):

***** Suggested function Call: python *****
Arguments: 
import matplotlib.pyplot as plt


fig, ax = plt.subplots()

ax.text(0.5, 0.5, "Agent 1", ha="center", va="center", fontsize=14, bbox=dict(facecolor='blue', edgecolor='blue', boxstyle='round,pad=0.5'))


ax.text(0.5, 0.4, "Agent 2", ha="center", va="center", fontsize=14, bbox=dict(facecolor='red', edgecolor='red', boxstyle='round,pad=0.5'))

ax.text(0.5, 0.55, "Agent 1: Hey, how are you?", ha="center", va="center")
ax.text(0.5, 0.45, "Agent 2: I'm good, thanks! How about you?", ha="center", va="center")


ax.set_xlim(0, 1)
ax.set_ylim(0, 1)


ax.axis('off')


plt.savefig('chat.png')
plt.close()
*******************************************

--------------------------------------------------------------------------------
user_proxy (to chatbot):

***** Response from calling function "python" *****
Error: Expecting value: line 1 column 1 (char 0)
 You argument should follow json format.
***************************************************
--------------------------------------------------------------------------------
chatbot (to user_proxy):

***** Suggested function Call: sh *****
Arguments: 
pip install matplotlib
***************************************

--------------------------------------------------------------------------------
user_proxy (to chatbot):

***** Response from calling function "sh" *****
Error: Expecting value: line 1 column 1 (char 0)
 You argument should follow json format.
***********************************************

--------------------------------------------------------------------------------

sunyq1995 avatar Oct 20 '23 09:10 sunyq1995

This can happen sometimes, especially with weak models. Is gpt-3.5 in use?

sonichi avatar Oct 21 '23 00:10 sonichi

Hi @sonichi, thanks for your reply. I've tried to use gpt4, however, it returned same error as gpt3.5. and I'm also curious where is the return format provided to gpt?

sunyq1995 avatar Oct 22 '23 04:10 sunyq1995

@kevin666aa could you follow up?

sonichi avatar Oct 22 '23 04:10 sonichi

have the same issue. please can you either resolve that issue, i.e. ensuring always json format for function calling or advise on how we can force/wrap/... the assistant return or user-proxy function call to be the required json (or make python function call accept also pure python code. in the meantime had to write separate function python call as the standard python code_execution seems to fail arbitrarily. propose to try to accept also pure function code or detecting missing json and auto-transform it.

ewagner70 avatar Jan 25 '24 00:01 ewagner70

seems like a misunderstanding of what the model is capable of...

rysweet avatar Oct 12 '24 02:10 rysweet

seems like a misunderstanding of what the model is capable of...

Can you please elaborate and ideally finish a started sentence?

ewagner70 avatar Oct 12 '24 06:10 ewagner70

seems like a misunderstanding of what the model is capable of...

Can you please elaborate and ideally finish a started sentence?

@ewagner70 model capability has evolved over the last year. Does this problem still happen? What Ryan meant to say is the model you were using didn't generate the right code format. So the mitigation is to update the system prompt.

ekzhu avatar Oct 12 '24 15:10 ekzhu

seems like a misunderstanding of what the model is capable of...

Can you please elaborate and ideally finish a started sentence?

@ewagner70 model capability has evolved over the last year. Does this problem still happen? What Ryan meant to say is the model you were using didn't generate the right code format. So the mitigation is to update the system prompt.

thank you ... now I understand what was meant ... and yes you're right, json format return works now much better via prompting and/or enforcing pydantic approaches ...

ewagner70 avatar Oct 12 '24 15:10 ewagner70