Skip to content

Commit

Permalink
Install pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
marekzp committed Sep 11, 2024
1 parent 71b9f0b commit c6f0e31
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ venv
__pycache__
*.pyc

responses
responses
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
This project is licensed under the MIT Licence - see the [LICENCE](LICENCE) file for details.
6 changes: 2 additions & 4 deletions llm-debate/debater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -69,4 +67,4 @@ def conclude(self) -> str:
self.debate_history.append(
f"{self.position.capitalize()} conclusion: {response}"
)
return response
return response
5 changes: 4 additions & 1 deletion llm-debate/llm_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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}")
raise ValueError(f"Unsupported LLM type: {llm_type}")
2 changes: 1 addition & 1 deletion llm-debate/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ <h2>Debate Metadata</h2>
</div>
{debate_content}
</body>
</html>
</html>
27 changes: 13 additions & 14 deletions llm-debate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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'<div class="round"><h2>{round_title}</h2>'
for side, argument in round_data.items():
debate_content += f'''
debate_content += f"""
<div class="argument {side}">
<h3>{side.capitalize()}</h3>
<p>{argument}</p>
</div>'''
debate_content += '</div>'
</div>"""
debate_content += "</div>"

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
return html_content
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ docstring-code-line-length = 20

[tool.ruff.lint.isort]
combine-as-imports = true
known-first-party = ["debate"]
known-first-party = ["debate"]

0 comments on commit c6f0e31

Please sign in to comment.