diff --git a/.gitignore b/.gitignore index 644df79..5da8204 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ venv __pycache__ *.pyc -responses \ No newline at end of file +responses diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..42a4dd9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.2 + hooks: + - id: ruff + args: [--fix] + - id: ruff-format + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: "v4.3.0" + hooks: + - id: check-merge-conflict + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace diff --git a/LICENSE b/LICENSE index 2986da3..9b06cae 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/README.md b/README.md index ccf2503..b42364d 100644 --- a/README.md +++ b/README.md @@ -115,4 +115,4 @@ Contributions to this project are welcome. Please ensure you follow the existing ## Licence -This project is licensed under the MIT Licence - see the [LICENCE](LICENCE) file for details. \ No newline at end of file +This project is licensed under the MIT Licence - see the [LICENCE](LICENCE) file for details. diff --git a/llm-debate/debater.py b/llm-debate/debater.py index 50a82c1..89cfcba 100644 --- a/llm-debate/debater.py +++ b/llm-debate/debater.py @@ -48,9 +48,7 @@ def respond_to(self, opponent_argument: str) -> str: response: str = self.llm_client.get_response(prompt, self.model) self.responses.append(response) - self.debate_history.append( - f"{self.position.capitalize()} response: {response}" - ) + self.debate_history.append(f"{self.position.capitalize()} response: {response}") return response def conclude(self) -> str: @@ -69,4 +67,4 @@ def conclude(self) -> str: self.debate_history.append( f"{self.position.capitalize()} conclusion: {response}" ) - return response \ No newline at end of file + return response diff --git a/llm-debate/llm_clients.py b/llm-debate/llm_clients.py index cf50921..9eeef9d 100644 --- a/llm-debate/llm_clients.py +++ b/llm-debate/llm_clients.py @@ -11,6 +11,7 @@ class LLMClient(ABC): def get_response(self, prompt: str, model: str) -> str: pass + class OpenAIClient(LLMClient): def __init__(self) -> None: self.api_key: Optional[str] = os.getenv("OPENAI_API_KEY") @@ -25,6 +26,7 @@ def get_response(self, prompt: str, model: str) -> str: ) return response.choices[0].message.content + class AnthropicClient(LLMClient): def __init__(self) -> None: self.api_key: Optional[str] = os.getenv("ANTHROPIC_API_KEY") @@ -40,10 +42,11 @@ def get_response(self, prompt: str, model: str) -> str: ) return response.content[0].text + def get_llm_client(llm_type: str) -> LLMClient: if llm_type == "openai": return OpenAIClient() elif llm_type == "anthropic": return AnthropicClient() else: - raise ValueError(f"Unsupported LLM type: {llm_type}") \ No newline at end of file + raise ValueError(f"Unsupported LLM type: {llm_type}") diff --git a/llm-debate/template.html b/llm-debate/template.html index 7047586..255953e 100644 --- a/llm-debate/template.html +++ b/llm-debate/template.html @@ -59,4 +59,4 @@

Debate Metadata

{debate_content} - \ No newline at end of file + diff --git a/llm-debate/utils.py b/llm-debate/utils.py index b411904..2b647ad 100644 --- a/llm-debate/utils.py +++ b/llm-debate/utils.py @@ -34,8 +34,8 @@ def save_html(data: Dict[str, Any], filename: str) -> str: def generate_html(data: Dict[str, Any]) -> str: """Generate HTML content for the debate results.""" current_dir = os.path.dirname(os.path.abspath(__file__)) - template_path = os.path.join(current_dir, 'template.html') - + template_path = os.path.join(current_dir, "template.html") + try: with open(template_path) as file: html_template = file.read() @@ -44,25 +44,24 @@ def generate_html(data: Dict[str, Any]) -> str: return "HTML template file not found" debate_content = "" - for round_name, round_data in data['debate'].items(): + for round_name, round_data in data["debate"].items(): round_title = round_name.replace("_", " ").title() debate_content += f'

{round_title}

' for side, argument in round_data.items(): - debate_content += f''' + debate_content += f"""

{side.capitalize()}

{argument}

-
''' - debate_content += '
' + """ + debate_content += "" - html_content = html_template.replace('{topic}', data['metadata']['topic']) - html_content = html_content.replace('{llm_type}', data['metadata']['llm_type']) - html_content = html_content.replace('{model}', data['metadata']['model']) - html_content = html_content.replace('{date}', data['metadata']['date']) + html_content = html_template.replace("{topic}", data["metadata"]["topic"]) + html_content = html_content.replace("{llm_type}", data["metadata"]["llm_type"]) + html_content = html_content.replace("{model}", data["metadata"]["model"]) + html_content = html_content.replace("{date}", data["metadata"]["date"]) html_content = html_content.replace( - '{time_taken}', - f"{data['metadata']['time_taken']:.2f}" + "{time_taken}", f"{data['metadata']['time_taken']:.2f}" ) - html_content = html_content.replace('{debate_content}', debate_content) + html_content = html_content.replace("{debate_content}", debate_content) - return html_content \ No newline at end of file + return html_content diff --git a/pyproject.toml b/pyproject.toml index 2f8b87d..dc3e55c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,4 +27,4 @@ docstring-code-line-length = 20 [tool.ruff.lint.isort] combine-as-imports = true -known-first-party = ["debate"] \ No newline at end of file +known-first-party = ["debate"]