-
Notifications
You must be signed in to change notification settings - Fork 693
arch: rm support for init'ing attempt.prompt with str
#1361
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
base: main
Are you sure you want to change the base?
Changes from all commits
f236cde
2189e2c
a1821e1
539f935
c2cf1b9
20dbfe4
04a45c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,7 +106,7 @@ def from_dict(cls, value: dict): | |
| raise ValueError("Expected `role` in Turn dict") | ||
| message = entity.pop("content", {}) | ||
| if isinstance(message, str): | ||
| content = Message(text=message) | ||
| content = Message(message, str) | ||
| else: | ||
| content = Message(**message) | ||
| return cls(role=role, content=content) | ||
|
|
@@ -156,7 +156,7 @@ class Attempt: | |
| :param status: The status of this attempt; ``ATTEMPT_NEW``, ``ATTEMPT_STARTED``, or ``ATTEMPT_COMPLETE`` | ||
| :type status: int | ||
| :param prompt: The processed prompt that will presented to the generator | ||
| :type prompt: Union[str|Turn|Conversation] | ||
| :type prompt: Message|Conversation | ||
| :param probe_classname: Name of the probe class that originated this ``Attempt`` | ||
| :type probe_classname: str | ||
| :param probe_params: Non-default parameters logged by the probe | ||
|
|
@@ -223,11 +223,16 @@ def __init__( | |
| if isinstance(prompt, Conversation): | ||
| self.conversations = [prompt] | ||
| elif isinstance(prompt, str): | ||
| msg = Message(text=prompt, lang=lang) | ||
| raise ValueError( | ||
| "attempt Prompt must be Message or Conversation, not string" | ||
| ) | ||
| # msg = Message(text=prompt, lang=lang) | ||
|
Comment on lines
225
to
+229
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer to just remove this.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, will leave this in until general functionality looks like it's in place. Wouldn't mind gating on a debug flag - but we don't have one, and this affects control flow, so gating on verbosity isn't the way |
||
| elif isinstance(prompt, Message): | ||
| msg = prompt | ||
| else: | ||
| raise TypeError("prompts must be of type str | Message | Conversation") | ||
| raise TypeError( | ||
| "attempt prompts must be of type Message | Conversation" | ||
| ) | ||
| if not hasattr(self, "conversations"): | ||
| self.conversations = [Conversation([Turn("user", msg)])] | ||
| self.prompt = self.conversations[0] | ||
|
|
@@ -321,14 +326,17 @@ def all_outputs(self) -> List[Message]: | |
| return all_outputs | ||
|
|
||
| @prompt.setter | ||
| def prompt(self, value: Union[str | Message | Conversation]): | ||
| def prompt(self, value: Message | Conversation): | ||
| if hasattr(self, "_prompt"): | ||
| raise TypeError("prompt cannot be changed once set") | ||
| if value is None: | ||
| raise TypeError("'None' prompts are not valid") | ||
| if isinstance(value, str): | ||
| # note this does not contain a lang | ||
| self._prompt = Conversation([Turn("user", Message(text=value))]) | ||
| raise TypeError( | ||
| "Attempt.prompt must be Message or Conversation, not bare string" | ||
| ) | ||
| # self._prompt = Conversation([Turn("user", Message(text=value))]) | ||
|
Comment on lines
334
to
+339
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again prefer to just remove this. |
||
| if isinstance(value, Message): | ||
| # make a copy to store an immutable object | ||
| self._prompt = Conversation([Turn("user", Message(**asdict(value)))]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ def test_continuation_load(): | |
| def test_continuation_1_matching_trigger(): | ||
| d = _plugins.load_plugin("detectors.continuation.Continuation") | ||
|
|
||
| a = garak.attempt.Attempt(prompt="test prompts") | ||
| a = garak.attempt.Attempt(prompt=garak.attempt.Message(text="test prompts")) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many of the edits in this file look ripe for a single |
||
| a.notes["triggers"] = [TEST_TRIGGER] | ||
| a.outputs = [TEST_TRIGGER] | ||
| r = d.detect(a) | ||
|
|
@@ -40,7 +40,9 @@ def test_continuation_1_matching_trigger(): | |
| def test_continuation_1_split_trigger(split_point): | ||
| d = _plugins.load_plugin("detectors.continuation.Continuation") | ||
|
|
||
| a = garak.attempt.Attempt(prompt="test prompts " + TEST_TRIGGER[:split_point]) | ||
| a = garak.attempt.Attempt( | ||
| prompt=garak.attempt.Message(text="test prompts " + TEST_TRIGGER[:split_point]) | ||
| ) | ||
| a.notes["triggers"] = [TEST_TRIGGER] | ||
| a.outputs = [TEST_TRIGGER[split_point:]] | ||
| r = d.detect(a) | ||
|
|
@@ -50,7 +52,7 @@ def test_continuation_1_split_trigger(split_point): | |
| def test_non_continuation(): | ||
| d = _plugins.load_plugin("detectors.continuation.Continuation") | ||
|
|
||
| a = garak.attempt.Attempt(prompt="test prompts") | ||
| a = garak.attempt.Attempt(prompt=garak.attempt.Message(text="test prompts")) | ||
| a.notes["triggers"] = [TEST_TRIGGER[:2]] | ||
| a.outputs = [f" {TEST_TRIGGER[2:]}"] | ||
| r = d.detect(a) | ||
|
|
@@ -60,7 +62,7 @@ def test_non_continuation(): | |
| def test_continuation_case_insensitive(): | ||
| d = _plugins.load_plugin("detectors.continuation.Continuation") | ||
|
|
||
| a = garak.attempt.Attempt(prompt="test prompts") | ||
| a = garak.attempt.Attempt(prompt=garak.attempt.Message(text="test prompts")) | ||
| a.notes["triggers"] = [TEST_TRIGGER.lower()] | ||
| a.outputs = [TEST_TRIGGER.upper()] | ||
| r = d.detect(a) | ||
|
|
@@ -70,7 +72,7 @@ def test_continuation_case_insensitive(): | |
| def test_continuation_multitrigger_matchfirst(): | ||
| d = _plugins.load_plugin("detectors.continuation.Continuation") | ||
|
|
||
| a = garak.attempt.Attempt(prompt="test prompts") | ||
| a = garak.attempt.Attempt(prompt=garak.attempt.Message(text="test prompts")) | ||
| a.notes["triggers"] = [TEST_TRIGGER, "other string"] | ||
| a.outputs = [TEST_TRIGGER] | ||
| r = d.detect(a) | ||
|
|
@@ -80,7 +82,7 @@ def test_continuation_multitrigger_matchfirst(): | |
| def test_continuation_multitrigger_matchsecond(): | ||
| d = _plugins.load_plugin("detectors.continuation.Continuation") | ||
|
|
||
| a = garak.attempt.Attempt(prompt="test prompts") | ||
| a = garak.attempt.Attempt(prompt=garak.attempt.Message(text="test prompts")) | ||
| a.notes["triggers"] = ["other string", TEST_TRIGGER] | ||
| a.outputs = [TEST_TRIGGER] | ||
| r = d.detect(a) | ||
|
|
@@ -90,7 +92,7 @@ def test_continuation_multitrigger_matchsecond(): | |
| def test_continuation_multitrigger_matchnone(): | ||
| d = _plugins.load_plugin("detectors.continuation.Continuation") | ||
|
|
||
| a = garak.attempt.Attempt(prompt="test prompts") | ||
| a = garak.attempt.Attempt(prompt=garak.attempt.Message(text="test prompts")) | ||
| a.notes["triggers"] = ["cardassia", "prime"] | ||
| a.outputs = [TEST_TRIGGER] | ||
| r = d.detect(a) | ||
|
|
@@ -100,7 +102,7 @@ def test_continuation_multitrigger_matchnone(): | |
| def test_continuation_empty_triggers(): | ||
| d = _plugins.load_plugin("detectors.continuation.Continuation") | ||
|
|
||
| a = garak.attempt.Attempt(prompt="test prompts") | ||
| a = garak.attempt.Attempt(prompt=garak.attempt.Message(text="test prompts")) | ||
| a.notes["triggers"] = [] | ||
| a.outputs = [TEST_TRIGGER] | ||
| r = d.detect(a) | ||
|
|
@@ -110,7 +112,7 @@ def test_continuation_empty_triggers(): | |
| def test_continuation_triggers_not_trigger(): | ||
| d = _plugins.load_plugin("detectors.continuation.Continuation") | ||
|
|
||
| a = garak.attempt.Attempt(prompt="test prompts") | ||
| a = garak.attempt.Attempt(prompt=garak.attempt.Message(text="test prompts")) | ||
| a.notes["trigger"] = TEST_TRIGGER | ||
| a.outputs = [TEST_TRIGGER] | ||
| r = d.detect(a) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this revision is correct, str is a class and passing it as the second argument to this constructor would not be valid. In theory this branch of the conditional cannot be reached and probably should raise a
ValueErrorifcontentin the serialized entity was of object typestr. The existing code would provide a method to manually create a more loose approximation of a serializedTurnhowever do not I see any reason we should support it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right either, and I suspect something like this should have been flagged in tests. Will check tests.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in theory this code cannot actually be reached as we only deserialize
Messageobjects that have been serialized from a valid originalMessage. I suspect existing tests never enter this conditional and if can be removed or adjusted to raise ValueError.