File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 11"""MLX Chat Wrapper."""
22
3+ import json
4+ import logging
35from typing import (
46 Any ,
57 Callable ,
3840
3941from langchain_community .llms .mlx_pipeline import MLXPipeline
4042
43+ logger = logging .getLogger (__name__ )
44+
4145DEFAULT_SYSTEM_PROMPT = """You are a helpful, respectful, and honest assistant."""
4246
4347
@@ -69,6 +73,25 @@ def __init__(self, **kwargs: Any):
6973 super ().__init__ (** kwargs )
7074 self .tokenizer = self .llm .tokenizer
7175
76+ def _parse_tool_args (self , arg_text : str ) -> Dict [str , Any ]:
77+ """Parse the arguments for a tool call.
78+
79+ Args:
80+ arg_text: JSON string representation of the tool arguments.
81+
82+ Returns:
83+ Parsed arguments dictionary. If parsing fails, returns a dict with
84+ the original text under the ``input`` key.
85+ """
86+ try :
87+ args = json .loads (arg_text )
88+ except json .JSONDecodeError :
89+ args = {"input" : arg_text }
90+ except Exception as e : # pragma: no cover - defensive
91+ logger .warning ("Unexpected error during tool argument parsing: %s" , e )
92+ args = {"input" : arg_text }
93+ return args
94+
7295 def _generate (
7396 self ,
7497 messages : List [BaseMessage ],
You can’t perform that action at this time.
0 commit comments