Commit 4ed8111
Changed files (1)
src
llm
gemini
src/llm/gemini/utils.py
@@ -56,16 +56,18 @@ async def add_grounding_results(answers: str, grounding_chunks: list[dict], grou
except Exception as e:
logger.warning(e)
index2url = urls
+ logger.trace(f"Grounding URLs: {index2url}")
for support in grounding_supports:
indices: list[int] = support.get("grounding_chunk_indices", [])
- indices_with_url = " ".join([f"[[{idx + 1}]]({index2url[idx]})" for idx in indices])
+ logger.trace(f"Add grounding indices: {indices}")
+ indices_with_url = " ".join([f"[[{idx + 1}]]({glom(index2url, str(idx), default='https://www.google.com')})" for idx in indices])
if segment := glom(support, "segment.text", default=""):
answers = answers.replace(segment, f"{segment}{indices_with_url}", 1)
for idx, grounding in enumerate(grounding_chunks):
if idx > 9:
break
title = glom(grounding, "web.title", default="Web")
- url = index2url[idx]
+ url = glom(index2url, str(idx), default="https://www.google.com")
if url in answers:
answers += f"\n{number_to_emoji(idx + 1)}[{title}]({url})"
return answers