#Assistants API function calling with user confirmation

1 messages · Page 1 of 1 (latest)

manic tide
#

User
cdsuze
2h

Hello there,

I successfully use the assistants API with function calls to process user requests. In my use case, they ask to register the clock-out time using natural language.

Now, I have two scenarios that I haven’t been able to identify how to develop, and also couldn’t find something in the forum:

Before I store the information in the DB, I need to ask the user for a confirmation (example: Do you want to register Today 11pm? Confirm with yes or no). The key point is, I show the data to register and then ask for confirmation. How do I manage this step?

I’m using assistant API and threads.

This is my function now:

{
“type”: “function”,
“function”: {
“name”: “registerClockOut”,
“description”: “Register the exit time of a user on current or previous day”,
“parameters”: {
“type”: “object”,
“properties”: {
“clockOutTime”: {
“type”: “string”,
“pattern”: “^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$”, // YYYY-MM-DD HH:mm format
“description”: “Clock-out time like 2023-12-24 23:05”
}
},
“required”: [“clockOutTime”]
}
}
}

static briarBOT
#

Hi @manic tide. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the extracts, it seems that you're looking to add a confirmation step before executing a function call in the Assistant API. While the extracts don't provide a direct solution to this, they do provide some insights into how the Assistant API works, which can guide us in formulating a potential solution.

Here's a general approach you could consider:

  1. When the user asks to register the clock-out time, instead of immediately calling the registerClockOut function, you could have the assistant respond with a confirmation message. This message would include the data to be registered and ask the user to confirm.

  2. If the user responds with a confirmation (e.g., "yes"), you could then proceed to call the registerClockOut function with the provided data.

  3. If the user does not confirm (e.g., responds with "no"), you could have the assistant ask for new data or cancel the operation.

This approach would involve managing the conversation flow within your application code, using the responses from the Assistant API to guide the user through the process.

Here's a simplified example of how this might look in code, based on the Python SDK examples provided in the extracts:

from openai import OpenAI

client = OpenAI()

# ... set up assistant and thread ...

# User asks to register clock-out time
user_message = {
  "role": "user",
  "content": "I want to register my clock-out time as 11pm."
}

# Assistant responds with confirmation message
assistant_message = {
  "role": "assistant",
  "content": "Do you want to register Today 11pm? Confirm with yes or no."
}

# ... add messages to thread ...
#

If user confirms, call the registerClockOut function

if user_confirms:
function_call = {
"type": "function",
"function": {
"name": "registerClockOut",
"parameters": {
"clockOutTime": "2023-12-24 23:05"
}
}
}

... add function call to thread and execute ...


Please note that this is a simplified example and you would need to adapt it to your specific use case, including handling user input, managing the conversation flow, and error handling.

For more detailed information on how to use the Assistant API, you can refer to the **OpenAI documentation** (<https://platform.openai.com/docs/guides/assistants>) and the **OpenAI Cookbook** (<https://github.com/openai/openai-cookbook/blob/main/examples/Assistants_API_overview_python.ipynb>) examples provided in the extracts.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
#

@manic tide kapa.ai is still learning and improving, please let us know how it did by reacting below

manic tide
#

@static briar {
"type": "function",
"function": {
"name": "registerClockOut",
"description": "Generate a confirmation prompt for registering the exit time of a user",
"parameters": {
"type": "object",
"properties": {
"clockOutTime": {
"type": "string",
"pattern": "^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$", // YYYY-MM-DD HH:mm format
"description": "Clock-out time like 2023-12-24 23:05"
}
},
"required": ["clockOutTime"]
},
"output": {
"type": "object",
"properties": {
"confirmationMessage": {
"type": "string",
"description": "Message asking user to confirm the clock-out time"
}
}
}
}
}

static briarBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Based on the information provided in the extracts, it seems that you're looking to generate a confirmation prompt for registering the clock-out time of a user. While the extracts don't provide a direct solution to this, they do provide some insights into how the Assistant API works, which can guide us in formulating a potential solution.

Here's a general approach you could consider:

  1. When the registerClockOut function is called with a clockOutTime parameter, instead of immediately registering the time, you could generate a confirmation message. This message would include the data to be registered and ask the user to confirm.

  2. If the user responds with a confirmation (e.g., "yes"), you could then proceed to register the clock-out time with the provided data.

  3. If the user does not confirm (e.g., responds with "no"), you could ask for new data or cancel the operation.

This approach would involve managing the conversation flow within your application code, using the responses from the Assistant API to guide the user through the process.

Here's a simplified example of how this might look in code, based on the Python SDK examples provided in the extracts:

from openai import OpenAI

client = OpenAI()

# ... set up assistant and thread ...

# User asks to register clock-out time
user_message = {
  "role": "user",
  "content": "I want to register my clock-out time as 11pm."
}

# Assistant responds with confirmation message
assistant_message = {
  "role": "assistant",
  "content": "Do you want to register Today 11pm? Confirm with yes or no."
}

# ... add messages to thread ...

# If user confirms, call the registerClockOut function
if user_confirms:
  function_call = {
    "type": "function",
    "function": {
      "name": "registerClockOut",
      "parameters": {
        "clockOutTime": "2023-12-24 23:05"
      }
    }
  }
#

... add function call to thread and execute ...


Please note that this is a simplified example and you would need to adapt it to your specific use case, including handling user input, managing the conversation flow, and error handling.

For more detailed information on how to use the Assistant API, you can refer to the **OpenAI documentation** (<https://platform.openai.com/docs/guides/assistants>) and the **OpenAI Cookbook** (<https://github.com/openai/openai-cookbook/blob/main/examples/Assistants_API_overview_python.ipynb>) examples provided in the extracts.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
#

@manic tide kapa.ai is still learning and improving, please let us know how it did by reacting below