-
Notifications
You must be signed in to change notification settings - Fork 65
Add support for default llm kwargs for all models. #1303
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
Conversation
These kwargs can be passed to the constructor of the LLM object and will then be used for each generate call. Arguments passed via the generate_* methods will override the defaults. The integ tests verify that the default arguments do in fact get applied by greatly restricting the max output tokens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support for default LLM keyword arguments that are merged with per-call overrides across all model implementations.
- Introduces
default_llm_kwargs
parameter in the baseLLM
class and all subclasses. - Implements
_merge_llm_kwargs
to combine defaults with method-specific kwargs. - Updates all
generate
,generate_async
, andgenerate_batch
methods to merge defaults before invoking the provider, and adds unit/integration tests to verify behavior.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
lib/sycamore/sycamore/llms/llms.py | Added default_llm_kwargs to base LLM and _merge_llm_kwargs helper. |
lib/sycamore/sycamore/llms/openai.py | Passed default_llm_kwargs through constructor and merged in all generate methods. |
lib/sycamore/sycamore/llms/gemini.py | Added default_llm_kwargs support and merged defaults in metadata, generate, and async methods. |
lib/sycamore/sycamore/llms/bedrock.py | Added default_llm_kwargs support and merged defaults in metadata method. |
lib/sycamore/sycamore/llms/anthropic.py | Added default_llm_kwargs support and merged defaults in metadata, generate, and batch methods. |
lib/sycamore/sycamore/tests/unit/transforms/test_base_llm.py | Extended fake LLM in tests to capture merged kwargs. |
lib/sycamore/sycamore/tests/unit/llms/test_llms.py | New test for _merge_llm_kwargs . |
lib/sycamore/sycamore/tests/integration/llms/*.py | Integration tests for each provider to assert max_tokens (or provider equivalent) are enforced. |
Comments suppressed due to low confidence (4)
lib/sycamore/sycamore/llms/bedrock.py:63
- [nitpick] Remove this
print
or replace it with alogging.debug
/logging.info
call to avoid side effects in library code.
print(f"cache return {ret}")
lib/sycamore/sycamore/llms/llms.py:26
- The class docstring should be updated to document the new
default_llm_kwargs
constructor parameter and describe its behavior.
"""Abstract representation of an LLM instance. and should be subclassed to implement specific LLM providers."""
lib/sycamore/sycamore/llms/openai.py:16
- Add
default_llm_kwargs
to theArgs:
section of the class docstring so consumers know they can pass default call parameters.
"""An LLM interface to OpenAI models."""
lib/sycamore/sycamore/tests/unit/llms/test_llms.py:62
- [nitpick] Consider adding a corresponding unit test for the
generate_async
path (usingFakeLLM.generate_async
) to ensure defaults are merged there as well.
def test_merge_llm_kwargs():
async def generate_async(self, *, prompt: RenderedPrompt, llm_kwargs: Optional[dict] = None) -> str: | ||
from anthropic import RateLimitError, APIConnectionError | ||
|
||
self._merge_llm_kwargs(llm_kwargs) |
Copilot
AI
May 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In generate_async
, _merge_llm_kwargs
is called but its return value is not assigned back to llm_kwargs
, so default arguments are never applied. It should be llm_kwargs = self._merge_llm_kwargs(llm_kwargs)
.
self._merge_llm_kwargs(llm_kwargs) | |
llm_kwargs = self._merge_llm_kwargs(llm_kwargs) |
Copilot uses AI. Check for mistakes.
These kwargs can be passed to the constructor of the LLM object and will then be used for each generate call. Arguments passed via the generate_* methods will override the defaults.
The integ tests verify that the default arguments do in fact get applied by greatly restricting the max output tokens.