-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/hf_formats
- Loading branch information
Showing
12 changed files
with
108 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
|
||
from garak import _config | ||
from garak import _plugins | ||
import garak.generators.base | ||
import garak.generators.nvcf | ||
|
||
PLUGINS = ("NvcfChat", "NvcfCompletion") | ||
|
||
|
||
@pytest.mark.parametrize("klassname", PLUGINS) | ||
def test_instantiate(klassname): | ||
_config.plugins.generators["nvcf"] = {} | ||
_config.plugins.generators["nvcf"][klassname] = {} | ||
_config.plugins.generators["nvcf"][klassname]["name"] = "placeholder name" | ||
_config.plugins.generators["nvcf"][klassname]["api_key"] = "placeholder key" | ||
g = _plugins.load_plugin(f"generators.nvcf.{klassname}") | ||
assert isinstance(g, garak.generators.base.Generator) | ||
|
||
|
||
@pytest.mark.parametrize("klassname", PLUGINS) | ||
def test_version_endpoint(klassname): | ||
name = "feedfacedeadbeef" | ||
version = "cafebabe" | ||
_config.plugins.generators["nvcf"] = {} | ||
_config.plugins.generators["nvcf"][klassname] = {} | ||
_config.plugins.generators["nvcf"][klassname]["name"] = name | ||
_config.plugins.generators["nvcf"][klassname]["api_key"] = "placeholder key" | ||
_config.plugins.generators["nvcf"][klassname]["version_id"] = version | ||
g = _plugins.load_plugin(f"generators.nvcf.{klassname}") | ||
assert g.invoke_url == f"{g.invoke_url_base}{name}/versions/{version}" | ||
|
||
|
||
@pytest.mark.parametrize("klassname", PLUGINS) | ||
def test_custom_keys(klassname): | ||
name = "feedfacedeadbeef" | ||
params = {"n": 1, "model": "secret/model_1.8t"} | ||
_config.plugins.generators["nvcf"] = {} | ||
_config.plugins.generators["nvcf"][klassname] = {} | ||
_config.plugins.generators["nvcf"][klassname]["name"] = name | ||
_config.plugins.generators["nvcf"][klassname]["api_key"] = "placeholder key" | ||
_config.plugins.generators["nvcf"][klassname]["extra_params"] = params | ||
g = _plugins.load_plugin(f"generators.nvcf.{klassname}") | ||
test_payload = g._build_payload("whatever prompt") | ||
for k, v in params.items(): | ||
assert test_payload[k] == v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters