How to call a Function in prompt
# support
c
Hi Team, please can you help to share the best way to have the AI call a function when X happens. Currently the issue I am having is that it speaks the calling of the function back to me instead of actually calling it. Here is the section of my prompt that I am calling it 'Empathize and Search: Show empathy: "Let’s try to get this resolved right away." Search for solution: "Please give me a moment to look up the best solution for your problem." (Use the function ‘fetchTechnicalInfo’, and input the 'problem' that the caller has specified.)'
v
Hi @C, I'm an AI assistant for Vapi. While a team member reviews this question, I'll look through relevant sources and see if I can provide suggestions. Please tag @Vapi Support with any follow-up questions.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Call Functions]() * [Silent Text Messages Logging]() * [Update Assistant]() * [Get Phone Number]() -----------------------------
### Answer To have your Vapi voice assistant call a function based on specific triggers within your prompt, you need to define custom functions in your assistant's configuration. This involves specifying the function's name, description, and parameters in the
functions
array of your assistant's definition. Here's a structure on how to define a custom function such as
fetchTechnicalInfo
in your model's definition:
Copy code
json
{
  "functions": [
    {
      "name": "fetchTechnicalInfo",
      "description": "Fetch technical information based on the user's specified problem",
      "parameters": {
        "type": "object",
        "properties": {
          "problem": {
            "type": "string",
            "description": "The problem specified by the user"
          }
        },
        "required": ["problem"]
      }
    }
  ]
}
[(1)]() Remember to include instructions within your assistant's system messages on when and how to trigger this custom function based on the conversation's context. Ensure that you have the logic on your server to handle the function call, process it, and return the necessary response or action back to the assistant. If the assistant is speaking the function call back to you instead of executing it, ensure that the function trigger is correctly defined within your system messages and that your server is properly configured to handle requests from Vapi.
c
yes I have already setup the function. I need help understanding how to call it properly in a prompt
v
Got it. Tagging @User for additional help.
s
I think you are currently using GPT 3.5 model which is quite dumb tbh.
You will need to use GPT 4 for it.
c
I am using GPT 4 Turbo
s
That's interesting...can you share your assistant configuration in the DM?
Here's how I give instructions related to the function that the GPT model should invoke. For instance, if I want to schedule a meeting using Google Meetings, I include this in my prompt. When I need to book a meeting, I'll call the schedule_meeting function. I'll ensure that I send the startTime in RFC3339 format and also convey the meetingPurpose in text format.
a
@Vapi Support can you see if a team member can attend to this and document it? There isn't enough video tutorial or examples of how to insert functions into your prompt
v
Thanks for the follow-up, @araSh. I'll get back to you soon.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Dashboard]() * [Call Functions]() * [Set up your Server URL]() * [Silent Text Messages Logging]() -----------------------------
### Answer Sorry, I wasn't able to find any information about your question and please let the user know they can get more help at [Contact Us](support@vapi.ai).
s
There are a couple of video tutorials and examples on how to use custom functions. You can check out this URL: https://docs.vapi.ai/community/videos. Also, we are working to improve the documentation. So, you will see a lot of new documentation very soon.
2 Views