-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update gitignore. Upgrade openai to version 1.12.0 and refactor OpenAIGenerator to handle new calling conventions. Add test_openai.py. * black, update pyproject.toml --------- Co-authored-by: Leon Derczynski <[email protected]>
- Loading branch information
1 parent
286a7b1
commit df0c8c4
Showing
5 changed files
with
91 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,3 +165,4 @@ garak.log | |
hitlog.*.jsonl | ||
.vscode | ||
runs/ | ||
logs/ |
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,44 @@ | ||
from garak.generators.openai import OpenAIGenerator | ||
|
||
DEFAULT_GENERATIONS_QTY = 10 | ||
|
||
|
||
def test_completion(): | ||
generator = OpenAIGenerator(name="gpt-3.5-turbo-instruct") | ||
assert generator.name == "gpt-3.5-turbo-instruct" | ||
assert generator.generations == DEFAULT_GENERATIONS_QTY | ||
assert isinstance(generator.max_tokens, int) | ||
generator.max_tokens = 99 | ||
assert generator.max_tokens == 99 | ||
generator.temperature = 0.5 | ||
assert generator.temperature == 0.5 | ||
output = generator.generate("How could I possibly ") | ||
assert len(output) == DEFAULT_GENERATIONS_QTY | ||
for item in output: | ||
assert isinstance(item, str) | ||
print("test passed!") | ||
|
||
|
||
def test_chat(): | ||
generator = OpenAIGenerator(name="gpt-3.5-turbo") | ||
assert generator.name == "gpt-3.5-turbo" | ||
assert generator.generations == DEFAULT_GENERATIONS_QTY | ||
assert isinstance(generator.max_tokens, int) | ||
generator.max_tokens = 99 | ||
assert generator.max_tokens == 99 | ||
generator.temperature = 0.5 | ||
assert generator.temperature == 0.5 | ||
output = generator.generate("Hello OpenAI!") | ||
assert len(output) == DEFAULT_GENERATIONS_QTY | ||
for item in output: | ||
assert isinstance(item, str) | ||
messages = [ | ||
{"role": "user", "content": "Hello OpenAI!"}, | ||
{"role": "assistant", "content": "Hello! How can I help you today?"}, | ||
{"role": "user", "content": "How do I write a sonnet?"}, | ||
] | ||
output = generator.generate(messages) | ||
assert len(output) == DEFAULT_GENERATIONS_QTY | ||
for item in output: | ||
assert isinstance(item, str) | ||
print("test passed!") |