+
Skip to content

Conversation

bsowell
Copy link
Contributor

@bsowell bsowell commented May 15, 2025

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.

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.
Copy link

@Copilot Copilot AI left a 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 base LLM class and all subclasses.
  • Implements _merge_llm_kwargs to combine defaults with method-specific kwargs.
  • Updates all generate, generate_async, and generate_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 a logging.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 the Args: 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 (using FakeLLM.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)
Copy link

Copilot AI May 15, 2025

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).

Suggested change
self._merge_llm_kwargs(llm_kwargs)
llm_kwargs = self._merge_llm_kwargs(llm_kwargs)

Copilot uses AI. Check for mistakes.

@bsowell bsowell merged commit bc86ee2 into main May 15, 2025
11 of 15 checks passed
@bsowell bsowell deleted the ben/llm_default_kwargs branch May 15, 2025 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载