|
31 | 31 | ClientEventResponseCancel,
|
32 | 32 | ClientEventResponseCreate,
|
33 | 33 | ClientEventSessionUpdate,
|
| 34 | + ConversationRequestItem, |
| 35 | + ResponseCreateParams, |
34 | 36 | )
|
35 | 37 | from azure.core.credentials import AzureKeyCredential, TokenCredential
|
36 | 38 | from azure.core.exceptions import AzureError
|
@@ -198,21 +200,33 @@ def __init__(self, connection: "VoiceLiveConnection") -> None:
|
198 | 200 | """
|
199 | 201 | self._connection = connection
|
200 | 202 |
|
201 |
| - def create(self, *, response: Optional[Mapping[str, Any]] = None, event_id: Optional[str] = None) -> None: |
202 |
| - """Create a new response. |
| 203 | + def create( |
| 204 | + self, |
| 205 | + *, |
| 206 | + response: Optional[Union[ResponseCreateParams, Mapping[str, Any]]] = None, |
| 207 | + event_id: Optional[str] = None, |
| 208 | + additional_instructions: Optional[str] = None, |
| 209 | + ) -> None: |
| 210 | + """ |
| 211 | + Create a new response. |
203 | 212 |
|
204 |
| - :keyword response: Optional mapping of response parameters to send. |
205 |
| - :keyword type response: Mapping[str, Any] or None |
| 213 | + :keyword response: Optional response parameters to send. |
| 214 | + :keyword type response: ~azure.ai.voicelive.models.ResponseCreateParams or Mapping[str, Any] or None |
206 | 215 | :keyword event_id: Optional ID for the event.
|
207 | 216 | :keyword type event_id: str or None
|
208 |
| - :return: None |
| 217 | + :keyword additional_instructions: Extra system prompt appended to the session's default, for this response only. |
| 218 | + :keyword type additional_instructions: str or None |
209 | 219 | :rtype: None
|
210 | 220 | """
|
211 |
| - event = ClientEventResponseCreate() |
212 |
| - if response: |
213 |
| - event["response"] = dict(response) |
214 |
| - if event_id: |
215 |
| - event["event_id"] = event_id |
| 221 | + if response is not None and not isinstance(response, ResponseCreateParams): |
| 222 | + response = ResponseCreateParams(**dict(response)) |
| 223 | + |
| 224 | + # Use constructor kwargs (typed) instead of item-assignment |
| 225 | + event = ClientEventResponseCreate( |
| 226 | + event_id=event_id, |
| 227 | + response=response, |
| 228 | + additional_instructions=additional_instructions, |
| 229 | + ) |
216 | 230 | self._connection.send(event)
|
217 | 231 |
|
218 | 232 | def cancel(self, *, response_id: Optional[str] = None, event_id: Optional[str] = None) -> None:
|
@@ -323,24 +337,31 @@ def __init__(self, connection: "VoiceLiveConnection") -> None:
|
323 | 337 | self._connection = connection
|
324 | 338 |
|
325 | 339 | def create(
|
326 |
| - self, *, item: Mapping[str, Any], previous_item_id: Optional[str] = None, event_id: Optional[str] = None |
| 340 | + self, |
| 341 | + *, |
| 342 | + item: Mapping[str, Any], |
| 343 | + previous_item_id: Optional[str] = None, |
| 344 | + event_id: Optional[str] = None |
327 | 345 | ) -> None:
|
328 | 346 | """Create a new conversation item.
|
329 | 347 |
|
330 | 348 | :keyword item: The item to create (message, function call, etc.).
|
331 |
| - :keyword type item: Mapping[str, Any] |
| 349 | + :keyword ConversationRequestItem | Mapping[str, Any] item: The item to create (message/functions/etc.). |
332 | 350 | :keyword previous_item_id: Insert after this item, if provided.
|
333 | 351 | :keyword type previous_item_id: str or None
|
334 | 352 | :keyword event_id: Optional ID for the event.
|
335 | 353 | :keyword type event_id: str or None
|
336 | 354 | :return: None
|
337 | 355 | :rtype: None
|
338 | 356 | """
|
339 |
| - event = ClientEventConversationItemCreate({"item": dict(item)}) |
340 |
| - if previous_item_id: |
341 |
| - event["previous_item_id"] = previous_item_id |
342 |
| - if event_id: |
343 |
| - event["event_id"] = event_id |
| 357 | + if not isinstance(item, ConversationRequestItem): |
| 358 | + item = ConversationRequestItem(**dict(item)) |
| 359 | + |
| 360 | + event = ClientEventConversationItemCreate( |
| 361 | + event_id=event_id, |
| 362 | + previous_item_id=previous_item_id, |
| 363 | + item=item, |
| 364 | + ) |
344 | 365 | self._connection.send(event)
|
345 | 366 |
|
346 | 367 | def delete(self, *, item_id: str, event_id: Optional[str] = None) -> None:
|
|
0 commit comments