Skip to content

Commit 02c0c36

Browse files
committed
Remove error handling from while loop example, keep it only in errors example
1 parent cae4112 commit 02c0c36

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

spanish/function_calling_while_loop.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,10 @@ def lookup_movies(city_name: str | None = None, zip_code: str | None = None) ->
138138
raw_args = tool_call.function.arguments or "{}"
139139
print(f"Solicitud de herramienta: {fn_name}({raw_args})")
140140
target_tool = tool_mapping.get(fn_name)
141-
if not target_tool:
142-
tool_result: Any = f"ERROR: No hay implementación registrada para '{fn_name}'"
143-
else:
144-
try:
145-
parsed_args = json.loads(raw_args) if raw_args.strip() else {}
146-
except json.JSONDecodeError:
147-
parsed_args = {}
148-
try:
149-
tool_result = target_tool(**parsed_args)
150-
except Exception as e: # noqa: BLE001 - demostración educativa
151-
tool_result = f"Error ejecutando {fn_name}: {e}"
152-
153-
try:
154-
tool_result_str = json.dumps(tool_result, ensure_ascii=False)
155-
except Exception: # noqa: BLE001
156-
tool_result_str = json.dumps({"resultado": str(tool_result)}, ensure_ascii=False)
157-
141+
parsed_args = json.loads(raw_args)
142+
tool_result = target_tool(**parsed_args)
143+
tool_result_str = json.dumps(tool_result)
144+
# Agrega la respuesta de la herramienta a la conversación
158145
messages.append(
159146
{
160147
"role": "tool",

0 commit comments

Comments
 (0)