Given multiple function_call , why only one function_call is returned, and how to solve if the user has multiple needs.
Besides, is the official example missing a layer of arguments
Given multiple function_call , why only one function_call is returned, and how to solve if the user has multiple needs.
Besides, is the official example missing a layer of arguments
Additionally, it appears that chat.completion may go into an “infinite loop”:
I had two functions, “getNews” and “getCurrentDateTime”. I gave both functions to chat.completion in the “functions” parameter. (to be clear, both work well alone).
I then prompted “Please give me the current time and the latest economic news.”
when I do NOT provide the functions again, it simply requests a function_call for getCurrentDateTime, and then when provided, HALLUCINATES on some new stories to achieve its response.
if I DO provide the “functions” list again on subsequent trips, it properly asks for “getNews” after it receives “getCurrentDateTime”. HOWEVER, it then goes into an infinite loop, requesting the getNews again, then the getCurrentDateTime again - never STOPing!!!
Any help on stopping loops would be appreciated!!!
You can pass it an additional function_call
parameter to say which function it needs to call. If you set it to “none” it won’t call a function.
For example in my code I have it set up like so:
def respond(..., use_func = True):
...
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=msg,
functions=fun,
function_call="auto" if use_func else "none"
)
So when the function requires an API call, I pass False
to respond
so that it won’t cause a chain reaction.
@Bandit - Thanks for your feedback. I guess I’m a bit confused - if I can tell chatGPT to execute a function or not, I obviously already know what is required, and therefore can execute whatever query is required on my server myself rather than dealing with chatGPT. That makes the function_call irrelevant (am I missing something???).
I’m hoping you can provide clarification:
I create a situation whereby chatGPT should need to call two functions:
I am asking “Please give me the date and news”, which would require chatGPT to 1) to call the getCurrentDateTime function, and 2) to call the getNews function.
I understand that you can use “function_call=auto” or “none”, however, I am winding up in a infinite loop - chatGPT is returning “getCurrentDateTime” as its requested function and then “getNews” and rather than stopping, it is once again requesting “getCurrentDateTime” (an infinite loop). My hope would be that chatGPT could determine ALL the functions required in one single call, or it could request each function until fed enough information to stop requesting more function calls. Does that make sense?
Your solution seems to be a “gate” - you decide to allow chatGPT to use a function or not.
In my situation, I am hoping chatGPT can determine which function(s) to use (one or many or none).
Do you have any thoughts based upon this scenario? How to stop chatcompletion from going into an infinite loop?
Thank you!
The solution is obvious - just pass the date (which can be in a function role) yourself all the time without actually having the AI ask for the date.
@_j - I believe you’re missing the point. The goal of using openai functions is to potentially chain them together as openai/chatcompletion requests them. While my example is simple (getCurrentDateTime, getNews), the goal is to have chatcompletion “feed” itself with what it requires to complete the task.
To your simple solution, of course I could append chatcompletion with both the Current Date AND news (that is common knowledge), however, then there would be no reason for function_call functionality because I would have simply programmed them in advance and fed the data to chatcompletion as is the current paradigm.
I’m hoping someone might have a reply that answers the question (or if other people are also having this “infinite loop” issue when passing functions):
How can I get chatcompletion to 1) request the functions it requires (see above, for instance getCurrentDateTime and getNews, and 2) once presented with the data from all of required functions, stop requesting them and provide an answer (currently, chatcompletion goes into an infinite loop if I pass the “functions” back for each call - to be clear, it asks for getCurrentDateTime, I execute a function and return the data, it asks for getNews, I execute and return the data, then it starts the process over again rather than answering the question).
Perhaps it is only possible to provide a single function (which seems strange, since the function object must be a “list”), but then the question is, “what good are functions?” If they are simply executing predetermined logic, it is confined to me knowing the function it will require, which again, in my opinion, defeats the purpose of a list of functions for chatcompletion to choose from!
Thanks!
@leesatou I am looking for the same. Did you find a solution?
For anyone else having confusion about executing multiple functions in a chat pipeline, I’ve pushed a repo to Git which will hopefully assist you. Hopefully it may demystify the confusion around functions. This sample executes 3 functions (assuming you have a newsapi api key) and combines the data from all 3 functions.
While it doesn’t appear that I can include a link on this forum, you can find it at the link below :
https:__github.com_seanconnolly2000_openai-functions-wrapper (replace the underscores with slashes).
Hope this helps!