Skip to content

The agent engineering platform.

[Doc] Improvement: Fix docs of `ChatMLX` (#28884)

ZhangShenao4b4d09f82b54
diff --git a/docs/docs/integrations/chat/mlx.ipynb b/docs/docs/integrations/chat/mlx.ipynb
index a5945dffae..dc852da549 100644
--- a/docs/docs/integrations/chat/mlx.ipynb
+++ b/docs/docs/integrations/chat/mlx.ipynb
@@ -155,8 +155,48 @@
"tools = load_tools([\"serpapi\", \"llm-math\"], llm=llm)\n",
"\n",
"# setup ReAct style prompt\n",
- "prompt = hub.pull(\"hwchase17/react-json\")\n",
- "prompt = prompt.partial(\n",
+ "# Based on 'hwchase17/react' prompt modification, cause mlx does not support the `System` role\n",
+ "human_prompt = \"\"\"\n",
+ "Answer the following questions as best you can. You have access to the following tools:\n",
+ "\n",
+ "{tools}\n",
+ "\n",
+ "The way you use the tools is by specifying a json blob.\n",
+ "Specifically, this json should have a `action` key (with the name of the tool to use) and a `action_input` key (with the input to the tool going here).\n",
+ "\n",
+ "The only values that should be in the \"action\" field are: {tool_names}\n",
+ "\n",
+ "The $JSON_BLOB should only contain a SINGLE action, do NOT return a list of multiple actions. Here is an example of a valid $JSON_BLOB:\n",
+ "\n",
+ "```\n",
+ "{{\n",
+ " \"action\": $TOOL_NAME,\n",
+ " \"action_input\": $INPUT\n",
+ "}}\n",
+ "```\n",
+ "\n",
+ "ALWAYS use the following format:\n",
+ "\n",
+ "Question: the input question you must answer\n",
+ "Thought: you should always think about what to do\n",
+ "Action:\n",
+ "```\n",
+ "$JSON_BLOB\n",
+ "```\n",
+ "Observation: the result of the action\n",
+ "... (this Thought/Action/Observation can repeat N times)\n",
+ "Thought: I now know the final answer\n",
+ "Final Answer: the final answer to the original input question\n",
+ "\n",
+ "Begin! Reminder to always use the exact characters `Final Answer` when responding.\n",
+ "\n",
+ "{input}\n",
+ "\n",
+ "{agent_scratchpad}\n",
+ "\n",
+ "\"\"\"\n",
+ "\n",
+ "prompt = human_prompt.partial(\n",
" tools=render_text_description(tools),\n",
" tool_names=\", \".join([t.name for t in tools]),\n",
")\n",
@@ -207,7 +247,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.9.18"
+ "version": "3.12.7"
}
},
"nbformat": 4,