({
provider,
language,
voice,
outputModalities,
temperature,
maxOutputTokens,
semanticEagerness,
}: {
provider: Provider
language?: string
voice?: string
outputModalities?: Array<'audio' | 'text'>
temperature?: number
maxOutputTokens?: number | 'inf'
semanticEagerness?: 'low' | 'medium' | 'high'
})
| 54 | } |
| 55 | |
| 56 | export function useRealtime({ |
| 57 | provider, |
| 58 | language, |
| 59 | voice, |
| 60 | outputModalities, |
| 61 | temperature, |
| 62 | maxOutputTokens, |
| 63 | semanticEagerness, |
| 64 | }: { |
| 65 | provider: Provider |
| 66 | language?: string |
| 67 | voice?: string |
| 68 | outputModalities?: Array<'audio' | 'text'> |
| 69 | temperature?: number |
| 70 | maxOutputTokens?: number | 'inf' |
| 71 | semanticEagerness?: 'low' | 'medium' | 'high' |
| 72 | }) { |
| 73 | return useRealtimeChat({ |
| 74 | getToken: () => |
| 75 | getRealtimeTokenFn({ |
| 76 | data: { |
| 77 | provider, |
| 78 | ...(provider === 'elevenlabs' && language ? { language } : {}), |
| 79 | }, |
| 80 | }), |
| 81 | adapter: adapterForProvider(provider), |
| 82 | instructions: `You are a helpful, friendly voice assistant with access to several tools. |
| 83 | |
| 84 | You can: |
| 85 | - Tell the user the current time and date (getCurrentTime) |
| 86 | - Get weather information for any location (getWeather) |
| 87 | - Set reminders for the user (setReminder) |
| 88 | - Search a knowledge base for information (searchKnowledge) |
| 89 | |
| 90 | Keep your responses concise and conversational since this is a voice interface. |
| 91 | When using tools, briefly explain what you're doing and then share the results naturally. |
| 92 | If the user sends an image, describe what you see and answer any questions about it. |
| 93 | Be friendly and engaging!`, |
| 94 | voice: voice ?? (provider === 'grok' ? 'eve' : 'alloy'), |
| 95 | tools: realtimeClientTools, |
| 96 | outputModalities, |
| 97 | temperature, |
| 98 | maxOutputTokens, |
| 99 | semanticEagerness, |
| 100 | onError: (err) => { |
| 101 | console.error('Realtime error:', err) |
| 102 | }, |
| 103 | }) |
| 104 | } |
no test coverage detected