ema
05/13/2024, 2:17 PMVapi Support
05/13/2024, 2:17 PMVapi Support
05/13/2024, 2:18 PMfunction-call
messages which Vapi sends when it wants to trigger an action on your server [(1)]() .
3. Respond to Vapi:
- Ensure your function sends a response back to Vapi in the expected format. If your function was triggered by a function-call
, the response should contain the results of the function call, which Vapi can then use in the conversation [(2)]() .
Here's an example of how you could modify your function to work with Vapi, based on handling a `function-call`:Vapi Support
05/13/2024, 2:18 PMpython
from flask import Flask, request, jsonify
import requests
app = Flask(__name__)
@app.route("/your-function-endpoint", methods=["POST"])
def vapi_function():
data = request.get_json()
# Assuming 'data' contains a 'function-call' from Vapi
function_name = data['call']['functionCall']['name']
if function_name == "your_function_name_here":
# Process the call
response_data = {'nom': 'X Y'}
response = requests.post("https://function/", json=response_data)
# Prepare the response for Vapi
vapi_response = {
"results": [
{
"toolCallId": data['call']['id'],
"result": response.json()
}
]
}
return jsonify(vapi_response)
return jsonify({"error": "Function not recognized"}), 400
if __name__ == "__main__":
app.run(debug=True)
[(1)]() , [(2)]()
Remember, you'll need to adapt the "your_function_name_here"
and the endpoint "/your-function-endpoint"
to match your configuration in Vapi.
This example assumes you're using Flask for your serverless function and that you've already set up the necessary configurations in Vapi to call this function.ema
05/13/2024, 2:20 PMVapi Support
05/13/2024, 2:20 PMVapi Support
05/13/2024, 2:21 PMjson
{
"type": "function",
"messages": [
{
"type": "request-start",
"content": "Initiating action..."
},
{
"type": "request-complete",
"content": "Action completed."
}
],
"function": {
"name": "call_my_fastapi_function",
"server": {
"url": "https://your-fastapi-endpoint-url.com/path"
}
},
"async": false
}
Vapi Support
05/13/2024, 2:21 PMema
05/13/2024, 2:25 PMVapi Support
05/13/2024, 2:25 PMVapi Support
05/13/2024, 2:26 PMjson
{
"functions": [
{
"name": "myCustomFunction",
"description": "Send data to my endpoint for processing.",
"parameters": {
"type": "object",
"properties": {
"nom": {
"type": "string",
"description": "A name to be processed by the function."
},
// Include other parameters here as needed
}
}
}
]
}
Vapi Support
05/13/2024, 2:26 PMmyCustomFunction
that expects data, such as a name (nom
), to be sent to it. When setting up the call to this function within your conversation flow or assistant logic, you would specify the actual values for these parameters based on the conversation context or static values as needed.
This JSON configuration is conceptual and needs to be adapted to your specific setup with Vapi and how you've structured your assistant and endpoint. The key is to ensure that your FastAPI endpoint is prepared to accept these parameters from Vapi and process them accordingly.
Remember to specify the URL where Vapi should send these function calls, which would be your FastAPI endpoint, in the tool or function configuration on the Vapi platform.
For detailed instructions on setting up custom functions and sending data to them, refer to Vapi's documentation on [Function Calling]() [(1)]() and [Tools Calling]() [(2)]() . These sections provide insights into how to structure your requests and configure your assistant to interact with external services like your FastAPI endpoint.ema
05/13/2024, 2:41 PMVapi Support
05/13/2024, 2:41 PMVapi Support
05/13/2024, 2:41 PMSahil
05/13/2024, 3:54 PM