diff --git a/fern/assistants/personalization.mdx b/fern/assistants/personalization.mdx index 6b719de7..44dde42a 100644 --- a/fern/assistants/personalization.mdx +++ b/fern/assistants/personalization.mdx @@ -105,7 +105,7 @@ This approach is ideal for use cases like customer support, account management, name: "Dynamic Customer Support Assistant", model: { provider: "openai", - model: "gpt-4", + model: "gpt-4o", messages: [{ role: "system", content: `You are helping ${customer.name}, a ${customer.tier} member since ${customer.createdAt}.` diff --git a/fern/customization/custom-llm/tool-calling-integration.mdx b/fern/customization/custom-llm/tool-calling-integration.mdx index 4ec070e2..252343fe 100644 --- a/fern/customization/custom-llm/tool-calling-integration.mdx +++ b/fern/customization/custom-llm/tool-calling-integration.mdx @@ -241,7 +241,7 @@ Once your endpoints are set up, try testing them with these cURL commands. curl -X POST https://custom-llm-url/chat/completions \ -H "Content-Type: application/json" \ -d '{ - "model": "gpt-3.5-turbo", + "model": "gpt-4o", "messages": [ {"role": "user", "content": "I need a payment link."} ], @@ -268,7 +268,7 @@ Streaming chunks eventually include the result (e.g., a payment link) returned b curl -X POST https://custom-llm-url/chat/completions \ -H "Content-Type: application/json" \ -d '{ - "model": "gpt-3.5-turbo", + "model": "gpt-4o", "messages": [ {"role": "user", "content": "Please transfer my call."} ], @@ -423,4 +423,4 @@ By building each layer step by step and testing with cURL, you can fine-tune you For your convenience, you can find the complete source code for this Custom LLM integration here: **[Custom LLM with Vapi Integration – Complete Code](https://codesandbox.io/p/devbox/gfwztp)** -``` \ No newline at end of file +``` diff --git a/fern/customization/custom-transcriber.mdx b/fern/customization/custom-transcriber.mdx index 24e14855..6157c8e8 100644 --- a/fern/customization/custom-transcriber.mdx +++ b/fern/customization/custom-transcriber.mdx @@ -63,8 +63,26 @@ You'll learn how to: mkdir vapi-custom-transcriber cd vapi-custom-transcriber npm init -y + ``` + + + ```bash title="npm" npm install ws express dotenv @deepgram/sdk ``` + + ```bash title="yarn" + yarn add ws express dotenv @deepgram/sdk + ``` + + ```bash title="pnpm" + pnpm add ws express dotenv @deepgram/sdk + ``` + + ```bash title="bun" + bun add ws express dotenv @deepgram/sdk + ``` + + Create a `.env` file with the following content: ```env DEEPGRAM_API_KEY=your_deepgram_api_key diff --git a/fern/customization/jwt-authentication.mdx b/fern/customization/jwt-authentication.mdx index 70261c57..3535854d 100644 --- a/fern/customization/jwt-authentication.mdx +++ b/fern/customization/jwt-authentication.mdx @@ -31,7 +31,7 @@ For example, it can be used to restrict which API endpoints the token can access As of writing, the only publicly scoped API endpoint is - https://api.vapi.ai//call/web, which is used for Web Call creation. All other + https://api.vapi.ai/call/web, which is used for Web Call creation. All other endpoints are privately scoped. @@ -136,18 +136,7 @@ If you set the scope to `public`, you can use it to make authenticated API reque ``` import Vapi from '@vapi-ai/web'; -const vapi = new Vapi({ - token: 'your-jwt-token', -}); +const vapi = new Vapi('your-jwt-token'); vapi.start('your-assistant-id'); ``` - -## Notes - -- With the generated token, you can authenticate API requests to any endpoint requiring authentication. The token will be valid for the duration specified in the options (1 hour in this case). -- If you don't specify `token` in the JWT payload, the token will be public. - -## Conclusion - -This documentation covered the basics of generating a JWT token and demonstrated how to use the token to make authenticated API requests. Ensure that your environment variables (e.g., `ORG_ID` and `PRIVATE_KEY`) are correctly set up before running the code. diff --git a/fern/docs.yml b/fern/docs.yml index 9c0b446b..5b3214ce 100644 --- a/fern/docs.yml +++ b/fern/docs.yml @@ -746,15 +746,13 @@ redirects: - source: "/multilingual/introduction" destination: "/multilingual" - source: "/outbound_sales" - destination: "/examples/outbound-sales" + destination: "/examples/lead-qualification" - source: "/technical_support" destination: "/examples/inbound-support" - source: "/pizza_website" destination: "/examples/inbound-support" - source: "/examples/pizza-website" destination: "/examples/inbound-support" - - source: "/outbound_call_python" - destination: "/examples/outbound-call-python" - source: "/voice_widget" destination: "/examples/voice-widget" - source: "/clients" diff --git a/fern/examples/docs-agent.mdx b/fern/examples/docs-agent.mdx index 26e54cb3..1b21f4ae 100644 --- a/fern/examples/docs-agent.mdx +++ b/fern/examples/docs-agent.mdx @@ -8,7 +8,7 @@ Try our live implementation using the voice widget in the bottom-right corner of ## Overview -Build a voice-powered documentation assistant step by step. Use API requests (shown below) or the [Vapi Dashboard](https://dashboard.vapi.ai/). +Build a voice-powered documentation assistant step by step. Choose between using the Dashboard interface or programmatic APIs to suit your workflow. You'll learn to: - Index your docs with LlamaCloud @@ -20,7 +20,7 @@ You'll learn to: ## Prerequisites - [Vapi account](https://dashboard.vapi.ai/) with API access -- Documentation content - use your `llms-full.txt` file ([example](https://docs.vapi.ai/llms-full.txt)), available out-of-box on [Fern](https://buildwithfern.com/learn/docs/developer-tools/llms-txt) or [Mintlify](https://mintlify.com/docs/ai-ingestion#%2Fllms-full-txt) +- Documentation content - `llms.txt` file ([example](https://docs.vapi.ai/llms.txt)) could work great; it could be available out-of-box with your documentation framework (e.g. [Fern](https://buildwithfern.com/learn/docs/developer-tools/llms-txt), [Mintlify](https://mintlify.com/docs/ai-ingestion#%2Fllms-full-txt)) - [LlamaCloud account](https://cloud.llamaindex.ai/) for indexing ## Get started @@ -41,177 +41,682 @@ You'll learn to: - Create a tool that connects your assistant to your LlamaCloud index using the [Tools API](/api-reference/tools/create). - - You can also create this tool in the [Vapi Dashboard](https://dashboard.vapi.ai/). - ```bash - curl -X POST https://api.vapi.ai/tool \ - -H "Authorization: Bearer YOUR_VAPI_API_KEY" \ - -H "Content-Type: application/json" \ - -d '{ - "type": "apiRequest", - "name": "docsquery", - "function": { - "name": "docsquery", - "parameters": { - "type": "object", - "properties": { - "query": { - "type": "string", - "description": "The search query to find relevant documentation" + Create a tool that connects your assistant to your LlamaCloud index. + + + + 1. Navigate to **Tools** in your [Vapi Dashboard](https://dashboard.vapi.ai/) + 2. Click **Create Tool** + 3. Select **API Request** as the tool type + 4. Configure the tool: + - **Name**: `docsquery` + - **Function Name**: `docsquery` + - **Description**: `Search through documentation to find relevant information` + - **URL**: `https://api.cloud.llamaindex.ai/api/v1/pipelines/YOUR_PIPELINE_ID/retrieve` + - **Method**: `POST` + - **Headers**: Add `Authorization: Bearer YOUR_LLAMACLOUD_API_KEY` + - **Body**: Configure to send the query parameter + 5. Save the tool and note the tool ID + + + ```typescript + import { VapiClient } from "@vapi-ai/server-sdk"; + + // Initialize Vapi server SDK + const vapi = new VapiClient({ token: "YOUR_VAPI_API_KEY" }); + + // Create the documentation query tool + const tool = await vapi.tools.create({ + type: "function", + function: { + name: "docsquery", + parameters: { + type: "object", + properties: { + query: { + type: "string", + description: "The search query to find relevant documentation" + } + }, + required: ["query"] + } + }, + server: { + // LlamaCloud API endpoint for your pipeline + url: `https://api.cloud.llamaindex.ai/api/v1/pipelines/${YOUR_PIPELINE_ID}/retrieve`, + method: "POST", + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${YOUR_LLAMACLOUD_API_KEY}` + }, + // Send user query to LlamaCloud + body: { + query: "{{query}}" + } + } + }); + + console.log(`Tool created with ID: ${tool.id}`); + ``` + + + ```python + from vapi import Vapi + + # Initialize Vapi server SDK + client = Vapi(token="YOUR_VAPI_API_KEY") + + # Define system prompt for documentation assistant + system_prompt = """You are a helpful documentation assistant. Use the docsquery tool to find relevant information when users ask questions about the documentation. + +Guidelines: +- Always be helpful, friendly, and concise +- Provide accurate information based on the documentation +- When you don't know something, say so clearly +- Keep responses conversational for voice interaction +- Use the docsquery tool whenever users ask specific questions about features, setup, or implementation +- Summarize complex information in an easy-to-understand way +- Ask clarifying questions if the user's request is unclear +- Provide step-by-step guidance when explaining processes""" + + # Create the documentation assistant + assistant = client.assistants.create( + name="Docs agent", + model={ + "provider": "anthropic", + "model": "claude-3-5-sonnet-20241022", # Valid Claude model + "maxTokens": 400, + "messages": [ + { + "role": "system", + "content": system_prompt + } + ], + "toolIds": [YOUR_TOOL_ID_FROM_STEP_2] # Replace with actual tool ID + }, + // Configure voice settings + voice={ + "provider": "vapi", + "voice_id": "Harry" + }, + // Configure transcription + transcriber={ + "provider": "deepgram", + "model": "nova-2", + "language": "en" + }, + // Set greeting message + first_message="Hey I'm Harry, a support agent. How can I help you today? You can ask me questions about Vapi, how to get started or our documentation.", + end_call_message="Goodbye.", + background_sound="off", + // Enable call analysis for continuous improvement + analysis_plan={ + "summaryPlan": { + "enabled": True, + "prompt": "Summarize this documentation support call, focusing on the user's questions and how well they were answered." + }, + "successEvaluationPlan": { + "enabled": True, + "prompt": "Evaluate if this documentation support call was successful. Did the user get helpful answers to their questions?", + "rubric": "NumericScale" + } + } + ) + + print(f"Assistant created with ID: {assistant.id}") + ``` + + + ```bash + curl -X POST https://api.vapi.ai/tool \ + -H "Authorization: Bearer YOUR_VAPI_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "type": "apiRequest", + "name": "docsquery", + "function": { + "name": "docsquery", + "parameters": { + "type": "object", + "properties": { + "query": { + "type": "string", + "description": "The search query to find relevant documentation" + } + }, + "required": ["query"] } }, - "required": ["query"] - } - }, - "url": "https://api.cloud.llamaindex.ai/api/v1/pipelines/YOUR_PIPELINE_ID/retrieve", - "method": "POST", - "headers": { - "type": "object", - "properties": { - "Content-Type": { - "type": "string", - "value": "application/json" + "url": "https://api.cloud.llamaindex.ai/api/v1/pipelines/YOUR_PIPELINE_ID/retrieve", + "method": "POST", + "headers": { + "type": "object", + "properties": { + "Content-Type": { + "type": "string", + "value": "application/json" + }, + "Authorization": { + "type": "string", + "value": "Bearer YOUR_LLAMACLOUD_API_KEY" + } + } }, - "Authorization": { - "type": "string", - "value": "Bearer YOUR_LLAMACLOUD_API_KEY" - } - } - }, - "body": { - "type": "object", - "properties": { - "query": { - "type": "string", - "value": "{{query}}" + "body": { + "type": "object", + "properties": { + "query": { + "type": "string", + "value": "{{query}}" + } + } } - } - } - }' - ``` + }' + ``` + + Replace `YOUR_PIPELINE_ID` with your LlamaCloud pipeline ID and `YOUR_LLAMACLOUD_API_KEY` with your API key. Save the tool ID from the response for the next step. - Create an assistant using the [Assistant API](/api-reference/assistants/create) with the RAG tool attached. - - You can also create this assistant in the [Vapi Dashboard](https://dashboard.vapi.ai/). - - ```bash - curl -X POST https://api.vapi.ai/assistant \ - -H "Authorization: Bearer YOUR_VAPI_API_KEY" \ - -H "Content-Type: application/json" \ - -d '{ - "name": "Docs agent", - "model": { - "provider": "anthropic", - "model": "claude-3-5-sonnet-20241022", - "maxTokens": 400, - "messages": [ - { - "role": "system", - "content": "You are a helpful documentation assistant. Use the docsquery tool to find relevant information. Always be helpful, friendly, and concise. Provide accurate information based on the documentation. When you don'\''t know something, say so clearly. Keep responses conversational for voice interaction." + Create an assistant with the RAG tool attached. + + + + 1. Navigate to **Assistants** in your [Vapi Dashboard](https://dashboard.vapi.ai/) + 2. Click **Create Assistant** + 3. Configure the assistant: + - **Name**: `Docs agent` + - **Model**: Claude Sonnet 4 (Anthropic) + - **Voice**: Harry (Vapi) + - **First Message**: `Hey I'm Harry, a support agent. How can I help you today? You can ask me questions about Vapi, how to get started or our documentation.` + - **System Prompt**: Use a helpful documentation assistant prompt with guidelines for using the docsquery tool + 4. Add the `docsquery` tool in the Tools section + 5. Configure analysis plan for call monitoring + 6. Publish the assistant + + + ```typescript + import { VapiClient } from "@vapi-ai/server-sdk"; + + // Initialize Vapi server SDK + const vapi = new VapiClient({ token: "YOUR_VAPI_API_KEY" }); + + // Define system prompt for documentation assistant + const systemPrompt = `You are a helpful documentation assistant. Use the docsquery tool to find relevant information when users ask questions about the documentation. + +Guidelines: +- Always be helpful, friendly, and concise +- Provide accurate information based on the documentation +- When you don't know something, say so clearly +- Keep responses conversational for voice interaction +- Use the docsquery tool whenever users ask specific questions about features, setup, or implementation +- Summarize complex information in an easy-to-understand way +- Ask clarifying questions if the user's request is unclear +- Provide step-by-step guidance when explaining processes`; + + // Create the documentation assistant + const assistant = await vapi.assistants.create({ + name: "Docs agent", + model: { + provider: "anthropic", + model: "claude-3-5-sonnet-20241022", # Valid Claude model + maxTokens: 400, + messages: [ + { + role: "system", + content: systemPrompt + } + ], + toolIds: [YOUR_TOOL_ID_FROM_STEP_2] // Replace with actual tool ID + }, + // Configure voice settings + voice: { + provider: "vapi", + voice_id: "Harry" + }, + // Configure transcription + transcriber: { + provider: "deepgram", + model: "nova-2", + language: "en" + }, + // Set greeting message + firstMessage: "Hey I'm Harry, a support agent. How can I help you today? You can ask me questions about Vapi, how to get started or our documentation.", + endCallMessage: "Goodbye.", + backgroundSound: "off", + // Enable call analysis for continuous improvement + analysisPlan: { + summaryPlan: { + enabled: true, + prompt: "Summarize this documentation support call, focusing on the user's questions and how well they were answered." + }, + successEvaluationPlan: { + enabled: true, + prompt: "Evaluate if this documentation support call was successful. Did the user get helpful answers to their questions?", + rubric: "NumericScale" + } + } + }); + + console.log(`Assistant created with ID: ${assistant.id}`); + ``` + + + ```python + from vapi import Vapi + + # Initialize Vapi server SDK + client = Vapi(token="YOUR_VAPI_API_KEY") + + # Define system prompt for documentation assistant + system_prompt = """You are a helpful documentation assistant. Use the docsquery tool to find relevant information when users ask questions about the documentation. + +Guidelines: +- Always be helpful, friendly, and concise +- Provide accurate information based on the documentation +- When you don't know something, say so clearly +- Keep responses conversational for voice interaction +- Use the docsquery tool whenever users ask specific questions about features, setup, or implementation +- Summarize complex information in an easy-to-understand way +- Ask clarifying questions if the user's request is unclear +- Provide step-by-step guidance when explaining processes""" + + # Create the documentation assistant + assistant = client.assistants.create( + name="Docs agent", + model={ + "provider": "anthropic", + "model": "claude-3-5-sonnet-20241022", # Valid Claude model + "maxTokens": 400, + "messages": [ + { + "role": "system", + "content": system_prompt + } + ], + "toolIds": [YOUR_TOOL_ID_FROM_STEP_2] # Replace with actual tool ID + }, + // Configure voice settings + voice={ + "provider": "vapi", + "voice_id": "Harry" + }, + // Configure transcription + transcriber={ + "provider": "deepgram", + "model": "nova-2", + "language": "en" + }, + // Set greeting message + first_message="Hey I'm Harry, a support agent. How can I help you today? You can ask me questions about Vapi, how to get started or our documentation.", + end_call_message="Goodbye.", + background_sound="off", + // Enable call analysis for continuous improvement + analysis_plan={ + "summaryPlan": { + "enabled": True, + "prompt": "Summarize this documentation support call, focusing on the user's questions and how well they were answered." + }, + "successEvaluationPlan": { + "enabled": True, + "prompt": "Evaluate if this documentation support call was successful. Did the user get helpful answers to their questions?", + "rubric": "NumericScale" + } + } + ) + + print(f"Assistant created with ID: {assistant.id}") + ``` + + + ```bash + curl -X POST https://api.vapi.ai/tool \ + -H "Authorization: Bearer YOUR_VAPI_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "type": "apiRequest", + "name": "docsquery", + "function": { + "name": "docsquery", + "parameters": { + "type": "object", + "properties": { + "query": { + "type": "string", + "description": "The search query to find relevant documentation" + } + }, + "required": ["query"] + } + }, + "url": "https://api.cloud.llamaindex.ai/api/v1/pipelines/YOUR_PIPELINE_ID/retrieve", + "method": "POST", + "headers": { + "type": "object", + "properties": { + "Content-Type": { + "type": "string", + "value": "application/json" + }, + "Authorization": { + "type": "string", + "value": "Bearer YOUR_LLAMACLOUD_API_KEY" + } + } + }, + "body": { + "type": "object", + "properties": { + "query": { + "type": "string", + "value": "{{query}}" + } + } } - ], - "toolIds": ["YOUR_TOOL_ID_FROM_STEP_2"] - }, - "voice": { - "provider": "vapi", - "voiceId": "Harry" - }, - "transcriber": { - "provider": "deepgram", - "model": "nova-3", - "language": "en" - }, - "firstMessage": "Hey I'\''m Harry, a support agent. How can I help you today? You can ask me questions about Vapi, how to get started or our documentation.", - "endCallMessage": "Goodbye.", - "backgroundSound": "off", - "analysisPlan": { - "summaryPlan": { - "enabled": true, - "prompt": "Summarize this documentation support call, focusing on the user'\''s questions and how well they were answered." - }, - "successEvaluationPlan": { - "enabled": true, - "prompt": "Evaluate if this documentation support call was successful. Did the user get helpful answers to their questions?", - "rubric": "NumericScale" - } - } - }' - ``` - - Replace `YOUR_TOOL_ID_FROM_STEP_2` with the tool ID from step 2. Save the assistant ID from the response for the next step. + }' + ``` + + - - See our [complete documentation agent prompt](/docs-agent-prompt.txt) that includes detailed personality, style guidelines, and interaction patterns. - + Replace `YOUR_PIPELINE_ID` with your LlamaCloud pipeline ID and `YOUR_LLAMACLOUD_API_KEY` with your API key. Save the tool ID from the response for the next step. - - Use the Vapi Web SDK to create a voice widget. - - ```bash - npm install @vapi-ai/web - ``` - - Replace `YOUR_PUBLIC_API_KEY` and `YOUR_ASSISTANT_ID` with your actual values: - - ```typescript - import { useState, useEffect } from 'react'; - import Vapi from '@vapi-ai/web'; - - export default function VoiceWidget() { - const [vapi, setVapi] = useState(null); - const [isConnected, setIsConnected] = useState(false); - const [transcript, setTranscript] = useState([]); + + Customize your assistant's behavior and responses after creation. + + + + 1. Navigate to your assistant in the [Vapi Dashboard](https://dashboard.vapi.ai/) + 2. Edit any properties like system prompt, first message, or voice settings + 3. Changes apply immediately - no republishing needed + + + ```typescript + import { VapiClient } from "@vapi-ai/server-sdk"; + + const vapi = new VapiClient({ token: "YOUR_VAPI_API_KEY" }); + + // Update the assistant's first message + const updatedAssistant = await vapi.assistants.update("YOUR_ASSISTANT_ID", { + firstMessage: "Hello! I'm your documentation assistant. What would you like to know about our platform?", + // Update system prompt for better responses + model: { + provider: "anthropic", + model: "claude-3-5-sonnet-20241022", + messages: [ + { + role: "system", + content: "Enhanced system prompt with more specific guidelines for documentation assistance" + } + ] + } + }); - useEffect(() => { - const vapiInstance = new Vapi('YOUR_PUBLIC_API_KEY'); - setVapi(vapiInstance); + console.log("Assistant updated successfully"); + ``` + + + ```python + import requests + + # Update assistant properties + url = f"https://api.vapi.ai/assistant/{YOUR_ASSISTANT_ID}" + headers = { + "Authorization": f"Bearer {YOUR_VAPI_API_KEY}", + "Content-Type": "application/json" + } + + # Update first message and system prompt + data = { + "firstMessage": "Hello! I'\''m your documentation assistant. What would you like to know about our platform?", + "model": { + "provider": "anthropic", + "model": "claude-3-5-sonnet-20241022", + "messages": [ + { + "role": "system", + "content": "Enhanced system prompt with more specific guidelines for documentation assistance" + } + ] + } + } + + response = requests.patch(url, headers=headers, json=data) + print("Assistant updated successfully") + ``` + + + ```bash + curl -X PATCH https://api.vapi.ai/assistant/YOUR_ASSISTANT_ID \ + -H "Authorization: Bearer YOUR_VAPI_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "firstMessage": "Hello! I'\''m your documentation assistant. What would you like to know about our platform?", + "model": { + "provider": "anthropic", + "model": "claude-3-5-sonnet-20241022", + "messages": [ + { + "role": "system", + "content": "Enhanced system prompt with more specific guidelines for documentation assistance" + } + ] + } + }' + ``` + + + + + SDK changes apply immediately. Unlike Dashboard publishing, programmatic updates take effect right away. + + - vapiInstance.on('call-start', () => setIsConnected(true)); - vapiInstance.on('call-end', () => setIsConnected(false)); - vapiInstance.on('message', (msg) => { - if (msg.type === 'transcript') { - setTranscript(prev => [...prev, { role: msg.role, text: msg.transcript }]); - } + + Create test scenarios to validate your documentation assistant's responses. + + + + 1. Navigate to **Test** > **Voice Test Suites** in your dashboard + 2. Click **Create Test Suite** + 3. Add test scenarios with expected behaviors + 4. Run tests to validate assistant performance + + + ```typescript + import { VapiClient } from "@vapi-ai/server-sdk"; + + const vapi = new VapiClient({ token: "YOUR_VAPI_API_KEY" }); + + // Create test suite for documentation assistant + const testSuite = await vapi.testSuites.create({ + name: "Documentation Assistant Tests", + assistantId: "YOUR_ASSISTANT_ID", + testCases: [ + { + name: "Basic greeting test", + scenario: "User says hello", + expectedBehavior: "Assistant responds with greeting and asks how to help" + }, + { + name: "Documentation query test", + scenario: "User asks about API endpoints", + expectedBehavior: "Assistant uses docsquery tool and provides relevant information" + }, + { + name: "Unknown topic test", + scenario: "User asks about unrelated topic", + expectedBehavior: "Assistant politely redirects to documentation topics" + } + ] }); - return () => vapiInstance?.stop(); - }, []); - - const startCall = () => vapi?.start('YOUR_ASSISTANT_ID'); - const endCall = () => vapi?.stop(); - - return ( -
- {!isConnected ? ( - - ) : ( -
-
- {transcript.map((msg, i) => ( -
- - {msg.text} - + console.log(`Test suite created with ID: ${testSuite.id}`); + console.log("Next: Go to Dashboard to run the test suite"); + ``` + + + ```python + import requests + + # Create test suite for documentation assistant + url = "https://api.vapi.ai/test-suite" + headers = { + "Authorization": f"Bearer {YOUR_VAPI_API_KEY}", + "Content-Type": "application/json" + } + + data = { + "name": "Documentation Assistant Tests", + "assistantId": "YOUR_ASSISTANT_ID", + "testCases": [ + { + "name": "Basic greeting test", + "scenario": "User says hello", + "expectedBehavior": "Assistant responds with greeting and asks how to help" + }, + { + "name": "Documentation query test", + "scenario": "User asks about API endpoints", + "expectedBehavior": "Assistant uses docsquery tool and provides relevant information" + }, + { + "name": "Unknown topic test", + "scenario": "User asks about unrelated topic", + "expectedBehavior": "Assistant politely redirects to documentation topics" + } + ] + } + + response = requests.post(url, headers=headers, json=data) + test_suite = response.json() + print(f"Test suite created with ID: {test_suite['id']}") + print("Next: Go to Dashboard to run the test suite") + ``` + + + ```bash + curl -X POST https://api.vapi.ai/test-suite \ + -H "Authorization: Bearer YOUR_VAPI_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "Documentation Assistant Tests", + "assistantId": "YOUR_ASSISTANT_ID", + "testCases": [ + { + "name": "Basic greeting test", + "scenario": "User says hello", + "expectedBehavior": "Assistant responds with greeting and asks how to help" + }, + { + "name": "Documentation query test", + "scenario": "User asks about API endpoints", + "expectedBehavior": "Assistant uses docsquery tool and provides relevant information" + }, + { + "name": "Unknown topic test", + "scenario": "User asks about unrelated topic", + "expectedBehavior": "Assistant politely redirects to documentation topics" + } + ] + }' + ``` + + + + + Test suites can only be executed through the Dashboard. Navigate to **Test** > **Voice Test Suites** to run your created tests. + + + + + Use the Vapi Web SDK to create a voice widget for your documentation assistant. + + + + + ```bash title="npm" + npm install @vapi-ai/web + ``` + + ```bash title="yarn" + yarn add @vapi-ai/web + ``` + + ```bash title="pnpm" + pnpm add @vapi-ai/web + ``` + + ```bash title="bun" + bun add @vapi-ai/web + ``` + + + Replace `YOUR_PUBLIC_API_KEY` and `YOUR_ASSISTANT_ID` with your actual values: + + ```typescript + import { useState, useEffect } from 'react'; + import Vapi from '@vapi-ai/web'; + + export default function VoiceWidget() { + const [vapi, setVapi] = useState(null); + const [isConnected, setIsConnected] = useState(false); + const [transcript, setTranscript] = useState([]); + + useEffect(() => { + // Initialize Vapi Web SDK for client-side voice interactions + const vapiInstance = new Vapi('YOUR_PUBLIC_API_KEY'); + setVapi(vapiInstance); + + // Handle call lifecycle events + vapiInstance.on('call-start', () => setIsConnected(true)); + vapiInstance.on('call-end', () => setIsConnected(false)); + + // Handle real-time conversation messages + vapiInstance.on('message', (msg) => { + if (msg.type === 'transcript') { + setTranscript(prev => [...prev, { role: msg.role, text: msg.transcript }]); + } + }); + + // Cleanup on component unmount + return () => vapiInstance?.stop(); + }, []); + + // Start voice conversation with documentation assistant + const startCall = () => vapi?.start('YOUR_ASSISTANT_ID'); + const endCall = () => vapi?.stop(); + + return ( +
+ {!isConnected ? ( + + ) : ( +
+
+ {transcript.map((msg, i) => ( +
+ + {msg.text} + +
+ ))}
- ))} -
- + +
+ )}
- )} -
- ); - } - ``` + ); + } + ``` + + For a complete implementation with waveform visualization, real-time transcripts, and responsive design, check out our [voice widget component](https://github.com/VapiAI/docs/blob/7879817ad2789d5929842cecff4ef3f4ec82acae/fern/widget/voice-widget.tsx) on GitHub. @@ -221,20 +726,106 @@ You'll learn to: Vapi automatically analyzes every call. The assistant above includes an [`analysisPlan`](/api-reference/assistants/create#request.body.analysisPlan) with summary and success evaluation configured. - Configure additional analysis options in your assistant: - - **Summary plan**: Custom prompts for call summaries - - **Structured data plan**: Extract specific information using JSON schemas - - **Success evaluation plan**: Score calls with custom rubrics - - **Structured data multi plan**: Multiple extraction schemas - - Retrieve analysis results using the [Get Call API](/api-reference/calls/get#response.body.analysis): - - ```bash - curl https://api.vapi.ai/call/{CALL_ID} \ - -H "Authorization: Bearer YOUR_VAPI_API_KEY" - ``` - - The response includes `call.analysis` with your configured analysis results. Learn more about [call analysis configuration](/assistants/call-analysis). + + + 1. Navigate to **Logs** > **Calls** in your dashboard + 2. Click on any completed call to view analysis + 3. Review summary and success evaluation + 4. Use insights to improve your assistant's prompts and responses + + + ```typescript + import { VapiClient } from "@vapi-ai/server-sdk"; + + const vapi = new VapiClient({ token: "YOUR_VAPI_API_KEY" }); + + // Retrieve call analysis for continuous improvement + async function getCallAnalysis(callId: string) { + try { + const call = await vapi.calls.get(callId); + + if (call.analysis) { + console.log("Call Summary:", call.analysis.summary); + console.log("Success Score:", call.analysis.successEvaluation); + + // Use analysis data to improve prompts + return { + summary: call.analysis.summary, + successScore: call.analysis.successEvaluation, + improvements: extractImprovements(call.analysis) + }; + } + } catch (error) { + console.error("Error fetching call analysis:", error); + } + + return call; + } + + // Extract improvement suggestions from analysis + function extractImprovements(analysis: any) { + // Analyze patterns to suggest prompt improvements + return { + promptSuggestions: "Based on call analysis...", + commonQueries: "Users frequently ask about...", + successFactors: "Successful calls typically..." + }; + } + + // Get analysis for a specific call + const analysis = await getCallAnalysis("CALL_ID"); + ``` + + + ```python + import requests + + def get_call_analysis(call_id): + """Retrieve and analyze call data for continuous improvement""" + url = f"https://api.vapi.ai/call/{call_id}" + headers = {"Authorization": f"Bearer {YOUR_VAPI_API_KEY}"} + + try: + response = requests.get(url, headers=headers) + call_data = response.json() + + if 'analysis' in call_data: + print("Call Summary:", call_data['analysis']['summary']) + print("Success Score:", call_data['analysis']['successEvaluation']) + + # Extract insights for improvement + return { + 'summary': call_data['analysis']['summary'], + 'success_score': call_data['analysis']['successEvaluation'], + 'improvements': extract_improvements(call_data['analysis']) + } + + except Exception as error: + print(f"Error fetching call analysis: {error}") + + return call_data + + def extract_improvements(analysis): + """Extract improvement suggestions from analysis data""" + return { + 'prompt_suggestions': "Based on call analysis...", + 'common_queries': "Users frequently ask about...", + 'success_factors': "Successful calls typically..." + } + + # Get analysis for a specific call + analysis = get_call_analysis("CALL_ID") + ``` + + + Retrieve analysis results using the Get Call API: + + ```bash + curl https://api.vapi.ai/call/CALL_ID \ + -H "Authorization: Bearer YOUR_VAPI_API_KEY" + ``` + + **Iterative improvements:** - Review analysis summaries to identify common user questions diff --git a/fern/examples/inbound-support.mdx b/fern/examples/inbound-support.mdx index df3a751e..d8628ade 100644 --- a/fern/examples/inbound-support.mdx +++ b/fern/examples/inbound-support.mdx @@ -26,7 +26,6 @@ Build a banking support agent with function tools, CSV knowledge bases, and voic We will be creating a customer support agent for VapiBank, a bank that wants to provide 24/7 support to consumers. - --- ## 1. Create a Knowledge Base @@ -42,36 +41,193 @@ We will be creating a customer support agent for VapiBank, a bank that wants to
- - In your Vapi dashboard, click `Files` in the left sidebar. - - - - Click `Choose file`. Upload both `accounts.csv` and `transactions.csv` files. - - Note the file IDs. We'll need them later to create tools. + + + + 1. Navigate to **Files** in your [Vapi Dashboard](https://dashboard.vapi.ai/) + 2. Click **Choose file** and upload both `accounts.csv` and `transactions.csv` + 3. Note the file IDs for use in creating tools + + + + ```typescript + import { VapiClient } from "@vapi-ai/server-sdk"; + import fs from 'fs'; + + const vapi = new VapiClient({ token: "YOUR_VAPI_API_KEY" }); + + async function uploadFile(filePath: string) { + try { + const file = await vapi.files.create({ + file: fs.createReadStream(filePath) + }); + + console.log(`File ${filePath} uploaded with ID: ${file.id}`); + return file; + } catch (error) { + console.error(`Error uploading file ${filePath}:`, error); + throw error; + } + } + + // Upload both files + const accountsFile = await uploadFile("accounts.csv"); + const transactionsFile = await uploadFile("transactions.csv"); + + console.log(`Accounts file ID: ${accountsFile.id}`); + console.log(`Transactions file ID: ${transactionsFile.id}`); + ``` + + + ```python + import requests + + def upload_file(file_path): + url = "https://api.vapi.ai/file" + headers = {"Authorization": f"Bearer {YOUR_VAPI_API_KEY}"} + + with open(file_path, 'rb') as file: + files = {'file': file} + response = requests.post(url, headers=headers, files=files) + return response.json() + + # Upload both files + accounts_file = upload_file("accounts.csv") + transactions_file = upload_file("transactions.csv") + + print(f"Accounts file ID: {accounts_file['id']}") + print(f"Transactions file ID: {transactions_file['id']}") + ``` + + + ```bash + # Upload accounts.csv + curl -X POST https://api.vapi.ai/file \ + -H "Authorization: Bearer YOUR_VAPI_API_KEY" \ + -F "file=@accounts.csv" + + # Upload transactions.csv + curl -X POST https://api.vapi.ai/file \ + -H "Authorization: Bearer YOUR_VAPI_API_KEY" \ + -F "file=@transactions.csv" + ``` + + - - + def create_phone_number(name, assistant_id): + url = "https://api.vapi.ai/phone-number" + headers = { + "Authorization": f"Bearer {YOUR_VAPI_API_KEY}", + "Content-Type": "application/json" + } + + data = { + "name": name, + "assistantId": assistant_id + } + + response = requests.post(url, headers=headers, json=data) + return response.json() -