Skip to content

Commit

Permalink
update pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzLaurer committed Oct 27, 2024
1 parent 9e8741d commit c90c5c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
17 changes: 9 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# .pre-commit-config.yaml
#poetry run pre-commit run --all-files

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.1
hooks:
- id: ruff
#args: [--fix]
args: [--fix]
- id: ruff-format
args: [--check] # Only check formatting, don't modify
#args: [--check] # Only check formatting, don't modify


#- repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.13.0
# hooks:
# - id: mypy
# additional_dependencies: [types-PyYAML==6.0.12.20240917]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
additional_dependencies: [types-PyYAML==6.0.12.20240917]
args: ["--config-file=pyproject.toml"]
exclude: ^tests/
16 changes: 14 additions & 2 deletions hf_hub_prompts/prompt_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import re
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Union
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Match, Optional, Union

import yaml

Expand Down Expand Up @@ -80,7 +80,7 @@ def _fill_placeholders(self, template_part: Any, input_variables: Dict[str, Any]

if isinstance(template_part, str):
# fill placeholders in strings
def replacer(match):
def replacer(match: Match[str]) -> str:
key = match.group(1).strip()
return str(input_variables.get(key, match.group(0)))

Expand Down Expand Up @@ -121,6 +121,12 @@ def _validate_input_variables(self, input_variables: Dict[str, Any]) -> None:
class TextPromptTemplate(BasePromptTemplate):
"""A class representing a standard prompt template."""

# Declare types for mypy because attributes are set dynamically via setattr in parent's __init__.
# These declarations don't create the attributes, they just tell mypy about their types.
template: str
input_variables: Optional[List[str]]
metadata: Optional[Dict[str, Any]]

def __init__(self, full_yaml_content: Optional[Dict[str, Any]] = None, **kwargs: Any) -> None:
if "template" not in kwargs:
raise ValueError("You must always provide 'template' to TextPromptTemplate.")
Expand Down Expand Up @@ -167,6 +173,12 @@ def to_langchain_template(self) -> "LC_PromptTemplate":
class ChatPromptTemplate(BasePromptTemplate):
"""A class representing a chat prompt template that can be formatted and used with various LLM clients."""

# Declare types for mypy because attributes are set dynamically via setattr in parent's __init__.
# These declarations don't create the attributes, they just tell mypy about their types.
messages: List[Dict[str, Any]]
input_variables: Optional[List[str]]
metadata: Optional[Dict[str, Any]]

def __init__(self, full_yaml_content: Optional[Dict[str, Any]] = None, **kwargs: Any) -> None:
if "messages" not in kwargs:
raise ValueError("You must always provide 'messages' to ChatPromptTemplate.")
Expand Down

0 comments on commit c90c5c7

Please sign in to comment.