Skip to content

fix: remove stream_usage from text completion #1285

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nemoguardrails/llm/models/langchain_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ def _init_text_completion_model(
if provider_cls is None:
raise ValueError()
kwargs = _update_model_kwargs(provider_cls, model_name, kwargs)
# remove stream_usage parameter as it's not supported by text completion APIs
# (e.g., OpenAI's AsyncCompletions.create() doesn't accept this parameter)
kwargs.pop("stream_usage", None)
Copy link
Preview

Copilot AI Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting the "stream_usage" key into a shared constant or documenting it in the function docstring to avoid magic strings and make the removal rationale more discoverable.

Suggested change
kwargs.pop("stream_usage", None)
kwargs.pop(STREAM_USAGE_KEY, None)

Copilot uses AI. Check for mistakes.

return provider_cls(**kwargs)


Expand Down