Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
9 changes: 8 additions & 1 deletion 9 examples/clients/simple-chatbot/mcp_simple_chatbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,15 @@ async def process_llm_response(self, llm_response: str) -> str:
"""
import json

def _clean_json_string(json_string: str) -> str:
"""Remove ```json ... ``` or ``` ... ``` wrappers if the LLM response is fenced."""
import re

pattern = r"^```(?:\s*json)?\s*(.*?)\s*```$"
return re.sub(pattern, r"\1", json_string, flags=re.DOTALL | re.IGNORECASE).strip()

try:
tool_call = json.loads(llm_response)
tool_call = json.loads(_clean_json_string(llm_response))
if "tool" in tool_call and "arguments" in tool_call:
logging.info(f"Executing tool: {tool_call['tool']}")
logging.info(f"With arguments: {tool_call['arguments']}")
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.