-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(cerebras, xai): expose reasoning_format for parity with reasoning_effort #6106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dfe25a0
837e846
258fde2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Caller-provided extra_body in extra_kwargs is silently overridden by opts.extra_body Pre-existing behavior: if a caller passes (Refers to lines 975-980) Was this helpful? React with 👍 or 👎 to provide feedback. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from livekit.agents.llm import ChatContext | ||
| from livekit.plugins.cerebras import LLM as CerebrasLLM | ||
| from livekit.plugins.openai import LLM as OpenAILLM | ||
|
|
||
| pytestmark = pytest.mark.unit | ||
|
|
||
|
|
||
| def _chat_ctx() -> ChatContext: | ||
| chat_ctx = ChatContext() | ||
| chat_ctx.add_message(role="user", content="hi") | ||
| return chat_ctx | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_cerebras_reasoning_format_in_request() -> None: | ||
| """``reasoning_format`` is forwarded to the request body via ``extra_body``.""" | ||
| llm = CerebrasLLM( | ||
| model="gpt-oss-120b", | ||
| api_key="test-key", | ||
| reasoning_format="hidden", | ||
| gzip_compression=False, | ||
| msgpack_encoding=False, | ||
| ) | ||
| stream = llm.chat(chat_ctx=_chat_ctx()) | ||
| try: | ||
| extra_body = stream._extra_kwargs.get("extra_body", {}) | ||
| assert extra_body.get("reasoning_format") == "hidden" | ||
| finally: | ||
| await stream.aclose() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_cerebras_reasoning_format_omitted_by_default() -> None: | ||
| """No ``reasoning_format`` is sent when the option is not set.""" | ||
| llm = CerebrasLLM( | ||
| model="gpt-oss-120b", | ||
| api_key="test-key", | ||
| gzip_compression=False, | ||
| msgpack_encoding=False, | ||
| ) | ||
| stream = llm.chat(chat_ctx=_chat_ctx()) | ||
| try: | ||
| extra_body = stream._extra_kwargs.get("extra_body", {}) | ||
| assert "reasoning_format" not in extra_body | ||
| finally: | ||
| await stream.aclose() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_openai_with_cerebras_reasoning_format_in_request() -> None: | ||
| """``LLM.with_cerebras`` forwards ``reasoning_format`` to the request body.""" | ||
| llm = OpenAILLM.with_cerebras( | ||
| model="gpt-oss-120b", | ||
| api_key="test-key", | ||
| reasoning_format="hidden", | ||
| ) | ||
| stream = llm.chat(chat_ctx=_chat_ctx()) | ||
| try: | ||
| extra_body = stream._extra_kwargs.get("extra_body", {}) | ||
| assert extra_body.get("reasoning_format") == "hidden" | ||
| finally: | ||
| await stream.aclose() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_xai_reasoning_format_in_request() -> None: | ||
| """``LLM.with_x_ai`` forwards ``reasoning_format`` to the request body.""" | ||
| llm = OpenAILLM.with_x_ai( | ||
| model="grok-4-1-fast-reasoning", | ||
| api_key="test-key", | ||
| reasoning_format="parsed", | ||
| ) | ||
| stream = llm.chat(chat_ctx=_chat_ctx()) | ||
| try: | ||
| extra_body = stream._extra_kwargs.get("extra_body", {}) | ||
| assert extra_body.get("reasoning_format") == "parsed" | ||
| finally: | ||
| await stream.aclose() |
Uh oh!
There was an error while loading. Please reload this page.