Function calling but returning same function multiple times

functionDes = [
    {
        'name': 'get_picture',
        "description": "Gets a picture of somebody",
        "parameters": {
            "type": "object",
            "properties": {
                "person": {
                    "type": "string",
                    "description": "Person name, e.g. Sam",
                }
            },
            "required": ["person"],
        },
    }
]


completion = openai.ChatCompletion.create(
    model="gpt-3.5-turbo-0613",
    messages=[
        {"role": "user", "content": 'can u give me the pictures of sam and dave?'}],
    functions=functionDes,
    function_call="auto",
)

output = completion.choices[0].message
print(output)

I get

{
  "content": null,
  "function_call": {
    "arguments": "{\n  \"person\": \"sam\"\n}",
    "name": "get_picture"
  },
  "role": "assistant"
}

which it finds the first person mentioned, is there a way to run a function more than once, according to prompt?

When the second call to the AI is given enough context to see that it hasn’t obtained enough information to answer the question, it should continue calling functions.

That context provided to the AI can be these role messages:

user: I want to see Sam and Dave’s ugly mugs
assistant: synthetic reproduction of it calling the function "function_name(arguments you got)
function: response from API “picture of {person: sam} displayed to user”

The functions available should again be passed, so it can understand what it just did, and understand other answering information retrieval methods.

Then you’ll likely get the repeated calls to fulfill the user wishes, without explicit prompting to “operate” the specific functions needed yourself.

1 Like

so ur trying to say is that just call the API again as function which I should originally do, and then it will call for the last dude? (dave)

Yes, you submit the same input to the AI again with the original question, but you are adding:

  • role messages for “assistant” that show what the AI assistant would have actually output to call the function, and
  • the role message that is a return from the external function (where description of what it did is helpful).

The AI then can see what it has done so far, and what it needs to continue doing.

For example, if I have two search engine functions “bing” and “google”, and tell the AI in role messages that it already called Google and that the response from Google was “connection error”, the AI would try Bing to do the similar search and obtain the information it needs to answer the user’s question.