Skip to content

Commit 0b491c3

Browse files
committed
[Docs Agent] Bug fix - Fix the "index out of range" errors in Docs
Agent's chat web app.
1 parent 8824ddc commit 0b491c3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

examples/gemini/python/docs-agent/docs_agent/agents/docs_agent.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,11 @@ def query_vector_store_to_build(
439439
plain_token = 0
440440
sources = []
441441
final_pages = []
442-
for i in range(max_sources):
442+
# Quick fix: Ensure max_sources is not larger than the array size of search_result.
443+
this_range = len(search_result)
444+
if this_range > max_sources:
445+
this_range = max_sources
446+
for i in range(this_range):
443447
# The current section that is being built
444448
# eval turns str representation of array into an array
445449
curr_section_id = search_result[i].section.name_id

examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/chatui.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ def ask_model(question, agent, template: str = "chatui/index.html"):
472472
# Log debug information.
473473

474474
if docs_agent.config.enable_logs_for_debugging == "True":
475-
top_source_url = search_result[0].section.url
475+
top_source_url = ""
476+
if len(search_result) > 0:
477+
top_source_url = search_result[0].section.url
476478
source_urls = ""
477479
index = 1
478480
for result in search_result:

0 commit comments

Comments
 (0)