Skip to content

Commit

Permalink
refactor: improve tag extraction and type annotations
Browse files Browse the repository at this point in the history
- Ensures tag extraction is case-insensitive
- Adds type annotations for better code clarity and maintainability
  • Loading branch information
liblaf committed Nov 29, 2024
1 parent 54a311e commit f1fbca3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/llm_cli/utils/_extract_between_tags.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
def extract_between_tags(content: str | None, tag: str = "Answer") -> str:
if content is None:
return ""
start: int = content.find("<" + tag + ">")
content_lower: str = content.lower()
opening_tag: str = f"<{tag}>".lower()
start: int = content_lower.find(opening_tag)
if start >= 0:
start += len(tag) + 2
start += len(opening_tag)
content = content[start:]
end: int = content.find("</" + tag + ">")
closing_tag: str = f"</{tag}>".lower()
end: int = content_lower.find(closing_tag)
if end >= 0:
content = content[:end]
return content.strip()
5 changes: 3 additions & 2 deletions src/llm_cli/utils/_get_prompt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import importlib.resources
from importlib.resources.abc import Traversable


def get_prompt(name: str) -> str:
prompts_dir = importlib.resources.files("llm_cli.assets.prompts")
fpath = prompts_dir / f"{name}.md"
prompts_dir: Traversable = importlib.resources.files("llm_cli.assets.prompts")
fpath: Traversable = prompts_dir / f"{name}.md"
return fpath.read_text()

0 comments on commit f1fbca3

Please sign in to comment.