Skip to content
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

Feature: configuration based rest proxy support #1073

Merged
merged 3 commits into from
Jan 16, 2025

Conversation

jmartin-tech
Copy link
Collaborator

@jmartin-tech jmartin-tech commented Jan 13, 2025

Adds configuration based support for proxies to the rest.RestGenerator.

This extracts the proxy capability from @au70ma70n's PR #878

Verification

example rest_config.json, add any required configuration for your rest endpoint found here:

{
    "rest": {
        "RestGenerator": {
           "uri": "http://my_internal_llm_endpoint",
           "proxies": {
              "http": "http://localhost:8080",
              "https": "https://localhost:8443",
           }
        }
    }
}
  • garak -m rest -G rest_config.json -p lmrc
  • Verify test with a proxy if possible, consider a simple port forward for http proxy.

In theory this capability is possible to drive via environment variables as noted in the requests library docs, this PR enables a configuration based method for when environment variables are not available for the user to set, or instance if garak were to be wrapped in an executor service.

au70ma70n and others added 2 commits January 10, 2025 14:48
validates the `proxies` value if provided is a `dict` and passed on
to the requests call
garak/generators/rest.py Show resolved Hide resolved
garak/generators/rest.py Show resolved Hide resolved
@jmartin-tech
Copy link
Collaborator Author

Note that this PR also suggest additional possible sensitive configuration details that may deserve warnings similar to #1049, the format for proxy endpoints can accept a basic auth proxy in a format like http://user:[email protected]:1080 as noted in the library doc examples.

Copy link
Collaborator

@leondz leondz left a comment

Choose a reason for hiding this comment

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

few minor points in comments, lgtm

docs/source/garak.generators.rest.rst Outdated Show resolved Hide resolved
garak/generators/rest.py Show resolved Hide resolved
_config.plugins.generators["rest"]["RestGenerator"]["proxies"] = test_proxies
with pytest.raises(GarakException) as exc_info:
_plugins.load_plugin("generators.rest.RestGenerator", config_root=_config)
assert "not in the required format" in str(exc_info.value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

good thinking

)
generator._call_model("Who is Enabran Tain's son?")
mock_http_function.assert_called_once()
assert mock_http_function.call_args_list[0].kwargs["proxies"] == test_proxies
Copy link
Collaborator

Choose a reason for hiding this comment

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

i guess maybe this isn't the strongest possible test we can do (we could check mock proxy logs), but validation shows that the code works (by tailing proxy logs)

@jmartin-tech jmartin-tech merged commit 7ed485c into NVIDIA:main Jan 16, 2025
9 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2025
@jmartin-tech jmartin-tech deleted the feature/rest-proxy-support branch January 16, 2025 23:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants