-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
164 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Sequence | ||
from langchain_core.prompt_values import StringPromptValue | ||
|
||
from ..core import BaseConverter | ||
|
||
|
||
class SequenceConverter(BaseConverter): | ||
def __init__(self, *, converters: Sequence[BaseConverter] = []) -> None: | ||
self._converters = converters | ||
|
||
def _convert(self, prompt: str) -> str: | ||
converted_prompt = prompt | ||
for converter in self._converters: | ||
converted_prompt = converter.convert( | ||
StringPromptValue(text=converted_prompt) | ||
).to_string() | ||
|
||
return converted_prompt |
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,16 @@ | ||
from abc import ABC, abstractmethod | ||
from jinja2 import Template | ||
|
||
|
||
class BaseReport(ABC): | ||
def __init__(self, *, run_id: str) -> None: | ||
self.run_id = run_id | ||
|
||
@abstractmethod | ||
def _ipython_display_(self): | ||
pass | ||
|
||
def _render_template(self, template_path) -> str: | ||
with open(template_path, "r", encoding="utf8") as tpl_file: | ||
template = Template(tpl_file.read()) | ||
return template.render(report=self) |
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,32 @@ | ||
from typing import List, Optional | ||
from dataclasses import dataclass | ||
from ..core import BaseReport, BasePromptValue, Score | ||
|
||
|
||
@dataclass | ||
class RedTeamReportEntry: | ||
attempt: int | ||
prompt: BasePromptValue | ||
response: str | ||
score: Score | ||
|
||
|
||
class RedTeamReport(BaseReport): | ||
entries: List[RedTeamReportEntry] | ||
|
||
def __init__(self, *, run_id: str) -> None: | ||
super().__init__(run_id=run_id) | ||
self.entries = [] | ||
|
||
def add_entry(self, entry: RedTeamReportEntry): | ||
self.entries.append(entry) | ||
|
||
@property | ||
def final_score(self) -> Optional[Score]: | ||
last_entry = self.entries[-1] | ||
if last_entry: | ||
return last_entry.score | ||
return None | ||
|
||
def _ipython_display_(self): | ||
print("TODO") |
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
Oops, something went wrong.