Skip to content

Commit 152b333

Browse files
Add a check for empty matches for llm retrieval in hinting.py
1 parent 59d5e94 commit 152b333

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/agentlab/utils/hinting.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from agentlab.llm.chat_api import ChatModel
1515
import re
1616
from agentlab.llm.response_api import APIPayload
17+
1718
logger = logging.getLogger(__name__)
1819

1920

@@ -100,8 +101,13 @@ def choose_hints_llm(self, llm, goal: str, task_name: str) -> list[str]:
100101
response: str = llm(APIPayload(messages=[llm.msg.user().add_text(prompt)])).think
101102
try:
102103
matches = re.findall(r"<choice>(-?\d+)</choice>", response)
104+
if not matches:
105+
logger.error(f"No choice tags found in LLM response: {response}")
106+
return []
103107
if len(matches) > 1:
104-
logger.warning(f"LLM selected multiple topics for retrieval using only the first one.")
108+
logger.warning(
109+
f"LLM selected multiple topics for retrieval using only the first one."
110+
)
105111
topic_number = int(matches[0])
106112
if topic_number < 0 or topic_number >= len(hint_topics):
107113
logger.error(f"Wrong LLM hint id response: {response}, no hints")

0 commit comments

Comments
 (0)