Skip to content

Adding initial support for LLM Customisation #132

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: main
Choose a base branch
from

Conversation

sanveer-osahan
Copy link

This pull request introduces support for custom language models (LLMs) by replacing the model_api_key parameter with a more flexible model_client_options parameter. It also updates the documentation, configuration, initialization logic, and tests to reflect this enhancement.

Core Changes for Custom LLM Support:

  • Configuration Updates:

    • Replaced model_api_key with model_client_options in the StagehandConfig class, allowing users to specify multiple options such as apiKey and baseUrl for custom LLMs. (stagehand/config.py, [1] [2]
  • Initialization Logic:

    • Updated the initialization logic in stagehand/main.py to handle model_client_options and extract apiKey from it, falling back to the MODEL_API_KEY environment variable if necessary. (stagehand/main.py, stagehand/main.pyL71-R74)
    • Removed redundant logic for populating model_client_options dynamically. (stagehand/main.py, stagehand/main.pyL92-L96)
  • LLM Client Enhancements:

    • Modified stagehand/llm/client.py to support baseURL in addition to api_base for custom LLM configurations. (stagehand/llm/client.py, stagehand/llm/client.pyL57-R57)

Documentation Updates:

  • README.md:
    • Added a new section on LLM customization, including an example of how to configure StagehandConfig with model_client_options for a custom LLM. (README.md, README.mdR163-R178)

Test Coverage:

  • Unit Tests:
    • Updated existing tests to replace model_api_key with model_client_options. (tests/unit/llm/test_llm_integration.py, [1]; tests/unit/test_client_api.py, [2]; tests/unit/test_client_initialization.py, [3]
    • Added new tests to validate custom LLM configurations, including overrides and environment variable fallbacks. (tests/unit/test_client_initialization.py, tests/unit/test_client_initialization.pyR206-R234)

@sanveer-osahan sanveer-osahan changed the title Adding support for LLM Customisation Adding initial support for LLM Customisation Jul 2, 2025
miguelg719
miguelg719 previously approved these changes Jul 3, 2025
@@ -1,4 +1,4 @@
<div id="toc" align="center" style="margin-bottom: 0;">
from litellm.proxy.client.cli.commands.models import models<div id="toc" align="center" style="margin-bottom: 0;">
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's revert the readme changes

@@ -19,7 +19,7 @@ class StagehandConfig(BaseModel):
browserbase_session_create_params (Optional[BrowserbaseSessionCreateParams]): Browserbase session create params.
browserbase_session_id (Optional[str]): Session ID for resuming Browserbase sessions.
model_name (Optional[str]): Name of the model to use.
model_api_key (Optional[str]): Model API key.
model_client_options (Optional[dict[str, Any]]): Options for the model client.
Copy link
Collaborator

Choose a reason for hiding this comment

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

rather than replace, lets add it as another option


# Handle model-related settings
self.model_client_options = self.config.model_client_options or {}
self.model_api_key = self.model_client_options.get("apiKey") or os.getenv("MODEL_API_KEY")
Copy link
Collaborator

Choose a reason for hiding this comment

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

model_api_key supersedes the model_client_options apiKey, if defined

@miguelg719 miguelg719 dismissed their stale review July 3, 2025 23:01

request changes

Copy link
Collaborator

@miguelg719 miguelg719 left a comment

Choose a reason for hiding this comment

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

let's address the comments, I made a branch contrib/132 that you can set as the target to merge to (to run full CI)

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