Repository navigation
Commit aa1dc53
Python: Fix OpenAI chat client compatibility with third-party endpoints and OTel 0.4.14 (microsoft#4161)
* Fix system message content sent as list instead of string
Some OpenAI-compatible endpoints (e.g. NVIDIA NIM) reject system messages
when content is a list of content parts. This change flattens system and
developer message content to a plain string in the Chat Completions client.
Fixes microsoft#1407
Co-authored-by: Copilot <[email protected]>
* Fix compatibility with opentelemetry-semantic-conventions-ai 0.4.14
Version 0.4.14 removed several LLM_* attributes from SpanAttributes
(LLM_SYSTEM, LLM_REQUEST_MODEL, LLM_RESPONSE_MODEL, LLM_REQUEST_MAX_TOKENS,
LLM_REQUEST_TEMPERATURE, LLM_REQUEST_TOP_P, LLM_TOKEN_TYPE).
Move these to the OtelAttr enum with their well-known gen_ai.* string values
and update all references in observability.py and tests.
Fixes microsoft#4160
Co-authored-by: Copilot <[email protected]>
* Flatten text-only message content to string for all roles
Extend the system/developer fix to all message roles. Text-only content
lists are now post-processed into plain strings, while multimodal content
(text + images/audio) remains as a list. This fixes compatibility with
OpenAI-like endpoints that cannot deserialize list content (e.g. Foundry
Local's Neutron backend).
Partially fixes microsoft#4084
Co-authored-by: Copilot <[email protected]>
* Fix streaming text lost when usage data in same chunk
Some providers (e.g. Gemini) include both usage data and text content
in the same streaming chunk. The early return on chunk.usage caused
text and tool call parsing to be skipped entirely. Remove the early
return and process usage alongside text/tool calls.
Fixes microsoft#3434
Co-authored-by: Copilot <[email protected]>
* Fix mypy errors in _chat_client.py
Rename shadowed variable 'args' in system/developer branch to 'sys_args'
and rename loop variable 'content' to 'msg_content' to avoid type conflict.
Co-authored-by: Copilot <[email protected]>
---------
Co-authored-by: Copilot <[email protected]>1 parent 2b1c5ab commit aa1dc53
4 files changed
Lines changed: 214 additions & 45 deletions
File tree
- python/packages/core
- agent_framework
- openai
- tests
- core
- openai
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
213 | 221 | | |
214 | 222 | | |
215 | 223 | | |
| |||
1175 | 1183 | | |
1176 | 1184 | | |
1177 | 1185 | | |
1178 | | - | |
| 1186 | + | |
1179 | 1187 | | |
1180 | 1188 | | |
1181 | 1189 | | |
| |||
1237 | 1245 | | |
1238 | 1246 | | |
1239 | 1247 | | |
1240 | | - | |
| 1248 | + | |
1241 | 1249 | | |
1242 | 1250 | | |
1243 | 1251 | | |
| |||
1611 | 1619 | | |
1612 | 1620 | | |
1613 | 1621 | | |
1614 | | - | |
| 1622 | + | |
1615 | 1623 | | |
1616 | 1624 | | |
1617 | 1625 | | |
1618 | 1626 | | |
1619 | 1627 | | |
1620 | | - | |
| 1628 | + | |
1621 | 1629 | | |
1622 | | - | |
1623 | | - | |
| 1630 | + | |
| 1631 | + | |
1624 | 1632 | | |
1625 | 1633 | | |
1626 | 1634 | | |
| |||
1633 | 1641 | | |
1634 | 1642 | | |
1635 | 1643 | | |
1636 | | - | |
| 1644 | + | |
1637 | 1645 | | |
1638 | 1646 | | |
1639 | 1647 | | |
| |||
1790 | 1798 | | |
1791 | 1799 | | |
1792 | 1800 | | |
1793 | | - | |
| 1801 | + | |
1794 | 1802 | | |
1795 | 1803 | | |
1796 | 1804 | | |
| |||
1802 | 1810 | | |
1803 | 1811 | | |
1804 | 1812 | | |
1805 | | - | |
1806 | | - | |
| 1813 | + | |
| 1814 | + | |
1807 | 1815 | | |
1808 | 1816 | | |
1809 | 1817 | | |
| |||
1821 | 1829 | | |
1822 | 1830 | | |
1823 | 1831 | | |
1824 | | - | |
| 1832 | + | |
1825 | 1833 | | |
1826 | 1834 | | |
1827 | | - | |
| 1835 | + | |
1828 | 1836 | | |
1829 | 1837 | | |
1830 | 1838 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
9 | 16 | | |
10 | 17 | | |
11 | 18 | | |
| |||
16 | 23 | | |
17 | 24 | | |
18 | 25 | | |
19 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
20 | 29 | | |
21 | 30 | | |
22 | 31 | | |
| |||
395 | 404 | | |
396 | 405 | | |
397 | 406 | | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | 407 | | |
412 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
413 | 419 | | |
414 | 420 | | |
415 | 421 | | |
| |||
532 | 538 | | |
533 | 539 | | |
534 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
535 | 552 | | |
536 | 553 | | |
537 | 554 | | |
| |||
568 | 585 | | |
569 | 586 | | |
570 | 587 | | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
571 | 597 | | |
572 | 598 | | |
573 | 599 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
48 | 47 | | |
49 | 48 | | |
50 | 49 | | |
51 | | - | |
52 | | - | |
| 50 | + | |
| 51 | + | |
53 | 52 | | |
54 | 53 | | |
55 | 54 | | |
| |||
213 | 212 | | |
214 | 213 | | |
215 | 214 | | |
216 | | - | |
| 215 | + | |
217 | 216 | | |
218 | 217 | | |
219 | 218 | | |
| |||
243 | 242 | | |
244 | 243 | | |
245 | 244 | | |
246 | | - | |
| 245 | + | |
247 | 246 | | |
248 | 247 | | |
249 | 248 | | |
| |||
392 | 391 | | |
393 | 392 | | |
394 | 393 | | |
395 | | - | |
| 394 | + | |
396 | 395 | | |
397 | 396 | | |
398 | 397 | | |
| |||
416 | 415 | | |
417 | 416 | | |
418 | 417 | | |
419 | | - | |
| 418 | + | |
420 | 419 | | |
421 | 420 | | |
422 | 421 | | |
| |||
491 | 490 | | |
492 | 491 | | |
493 | 492 | | |
494 | | - | |
| 493 | + | |
495 | 494 | | |
496 | 495 | | |
497 | 496 | | |
| |||
521 | 520 | | |
522 | 521 | | |
523 | 522 | | |
524 | | - | |
| 523 | + | |
525 | 524 | | |
526 | 525 | | |
527 | 526 | | |
| |||
1381 | 1380 | | |
1382 | 1381 | | |
1383 | 1382 | | |
1384 | | - | |
1385 | | - | |
1386 | 1383 | | |
1387 | 1384 | | |
1388 | 1385 | | |
| |||
1395 | 1392 | | |
1396 | 1393 | | |
1397 | 1394 | | |
1398 | | - | |
| 1395 | + | |
1399 | 1396 | | |
1400 | 1397 | | |
1401 | 1398 | | |
| |||
0 commit comments