Skip to content

Commit 45afab7

Browse files
committed
Remove example.com from LLM responses
1 parent 04e6150 commit 45afab7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

gramps_webapi/api/llm/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ def get_client(config: dict) -> OpenAI:
1616
return OpenAI(base_url=config.get("LLM_BASE_URL"))
1717

1818

19+
def sanitize_answer(answer: str) -> str:
20+
"""Sanitize the LLM answer."""
21+
# some models convert relative URLs to absolute URLs with this domain
22+
answer = answer.replace("https://www.example.com", "")
23+
return answer
24+
25+
1926
def answer_prompt(prompt: str, system_prompt: str, config: dict | None = None) -> str:
2027
"""Answer a question given a system prompt."""
2128
if not config:
@@ -61,7 +68,7 @@ def answer_prompt(prompt: str, system_prompt: str, config: dict | None = None) -
6168
except (KeyError, IndexError):
6269
abort_with_message(500, "Error parsing chat API response.")
6370

64-
return answer
71+
return sanitize_answer(answer)
6572

6673

6774
def answer_prompt_with_context(prompt: str, context: str) -> str:

0 commit comments

Comments
 (0)