Skip to content

Commit

Permalink
adds a check using regex to remove delimiters if they are returned by…
Browse files Browse the repository at this point in the history
… the LLM
  • Loading branch information
lauraschauer committed Jul 4, 2024
1 parent 53638d3 commit 38060fb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions prospector/llm/llm_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import validators
from langchain_core.language_models.llms import LLM
from langchain_core.output_parsers import StrOutputParser
Expand Down Expand Up @@ -59,6 +61,12 @@ def get_repository_url(self, advisory_description, advisory_references) -> str:
)
logger.info(f"LLM returned the following URL: {url}")

# delimiters are often returned by the LLM, remove them, if the case
pattern = r"<output>\s*(https?://[^\s]+)\s*</output>"
match = re.search(pattern, url)
if match:
return match.group(1)

if not validators.url(url):
raise TypeError(f"LLM returned invalid URL: {url}")

Expand Down

0 comments on commit 38060fb

Please sign in to comment.