You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,6 +101,37 @@ Project consists of:
101
101
- communication layer for processing audio in and out
102
102
- a boilerplate view for starting to build your apps and view logs
103
103
104
+
## Handling Context with Incomplete Turns
105
+
106
+
When working with the Live API, you might want to send contextual text data while continuing to stream real-time input. This is useful when you want to provide additional context to the model without ending the current conversation turn.
107
+
108
+
### Example: Sending Context Without Completing a Turn
109
+
110
+
```typescript
111
+
// Send context without completing the turn
112
+
client.sendContext([{ text: "The user is looking at a laptop." }]);
113
+
114
+
// Continue with real-time input (will force complete the turn if needed)
115
+
client.sendRealtimeInput([
116
+
{
117
+
mimeType: "audio/pcm;rate=16000",
118
+
data: audioData,
119
+
}
120
+
]);
121
+
122
+
// Check if there's an incomplete turn
123
+
if (client.hasIncompleteTurn()) {
124
+
// Manually complete a turn if needed
125
+
client.completeTurn();
126
+
}
127
+
```
128
+
129
+
### Differences Between send(), sendContext(), and sendRealtimeInput()
130
+
131
+
-`send(parts, turnComplete = true)`: Standard method to send text data. By default completes the turn.
132
+
-`sendContext(parts)`: A convenience method that calls `send(parts, false)`. Used when providing context without completing the turn.
133
+
-`sendRealtimeInput(chunks, completeTurn = true)`: Sends real-time media data. The `completeTurn` parameter determines if any incomplete turns should be automatically completed first.
0 commit comments