|
1236 | 1236 | } |
1237 | 1237 | ], |
1238 | 1238 | "source": [ |
1239 | | - "for m in ms:\n", |
1240 | | - " display(f'=== {m} ===')\n", |
1241 | | - " chat = Chat(m, tools=[simple_add])\n", |
1242 | | - " res = chat(\"What's 5 + 3?\")\n", |
1243 | | - " display(res)" |
| 1239 | + "# for m in ms:\n", |
| 1240 | + "# display(f'=== {m} ===')\n", |
| 1241 | + "# chat = Chat(m, tools=[simple_add])\n", |
| 1242 | + "# res = chat(\"What's 5 + 3?\")\n", |
| 1243 | + "# display(res)" |
1244 | 1244 | ] |
1245 | 1245 | }, |
1246 | 1246 | { |
|
1287 | 1287 | } |
1288 | 1288 | ], |
1289 | 1289 | "source": [ |
1290 | | - "chat = Chat(ms[1], tools=[search_tool])\n", |
1291 | | - "res = chat(\"Search the web and tell me very briefly about otters\", stream=True)\n", |
1292 | | - "for o in res:\n", |
1293 | | - " if isinstance(o, ModelResponse): sleep(0.01); display(o)\n", |
1294 | | - " else: print(delta_text(o) or '',end='')" |
| 1290 | + "# chat = Chat(ms[1], tools=[search_tool])\n", |
| 1291 | + "# res = chat(\"Search the web and tell me very briefly about otters\", stream=True)\n", |
| 1292 | + "# for o in res:\n", |
| 1293 | + "# if isinstance(o, ModelResponse): sleep(0.01); display(o)\n", |
| 1294 | + "# else: print(delta_text(o) or '',end='')" |
1295 | 1295 | ] |
1296 | 1296 | }, |
1297 | 1297 | { |
|
1455 | 1455 | } |
1456 | 1456 | ], |
1457 | 1457 | "source": [ |
1458 | | - "chat = Chat(model, tools=[simple_add])\n", |
1459 | | - "res = chat(\"What's ((5 + 3)+7)+11? Work step by step\", return_all=True, max_tool_rounds=5)\n", |
1460 | | - "for r in res: display(r)" |
| 1458 | + "# chat = Chat(model, tools=[simple_add])\n", |
| 1459 | + "# res = chat(\"What's ((5 + 3)+7)+11? Work step by step\", return_all=True, max_tool_rounds=5)\n", |
| 1460 | + "# for r in res: display(r)" |
1461 | 1461 | ] |
1462 | 1462 | }, |
1463 | 1463 | { |
|
1610 | 1610 | } |
1611 | 1611 | ], |
1612 | 1612 | "source": [ |
1613 | | - "def multiply(a: int, b: int) -> int:\n", |
1614 | | - " \"Multiply two numbers\"\n", |
1615 | | - " print(f\"MULTIPLY: {a} * {b}\")\n", |
1616 | | - " return a * b\n", |
| 1613 | + "# def multiply(a: int, b: int) -> int:\n", |
| 1614 | + "# \"Multiply two numbers\"\n", |
| 1615 | + "# print(f\"MULTIPLY: {a} * {b}\")\n", |
| 1616 | + "# return a * b\n", |
1617 | 1617 | "\n", |
1618 | | - "chat = Chat(ms[-1], tools=[simple_add, multiply])\n", |
1619 | | - "res = chat(\"Calculate (5 + 3) * (7 + 2)\", max_tool_rounds=5, return_all=True)\n", |
1620 | | - "for r in res: display(r)" |
| 1618 | + "# chat = Chat(ms[-1], tools=[simple_add, multiply])\n", |
| 1619 | + "# res = chat(\"Calculate (5 + 3) * (7 + 2)\", max_tool_rounds=5, return_all=True)\n", |
| 1620 | + "# for r in res: display(r)" |
1621 | 1621 | ] |
1622 | 1622 | }, |
1623 | 1623 | { |
|
1759 | 1759 | } |
1760 | 1760 | ], |
1761 | 1761 | "source": [ |
1762 | | - "def divide(a: int, b: int) -> float:\n", |
1763 | | - " \"Divide two numbers\"\n", |
1764 | | - " display(f\"DIVIDE: {a} / {b}\")\n", |
1765 | | - " return a / b\n", |
| 1762 | + "# def divide(a: int, b: int) -> float:\n", |
| 1763 | + "# \"Divide two numbers\"\n", |
| 1764 | + "# display(f\"DIVIDE: {a} / {b}\")\n", |
| 1765 | + "# return a / b\n", |
1766 | 1766 | "\n", |
1767 | | - "chat = Chat(model, tools=[simple_add, multiply, divide])\n", |
1768 | | - "res = chat(\"Calculate ((10 + 5) * 3) / (2 + 1) step by step\", \n", |
1769 | | - " max_tool_rounds=2, return_all=True,\n", |
1770 | | - " final_prompt=\"Please summarize what you've calculated so far\")\n", |
1771 | | - "print(f\"Got {len(res)} responses\")\n", |
1772 | | - "for r in res: display(r)" |
| 1767 | + "# chat = Chat(model, tools=[simple_add, multiply, divide])\n", |
| 1768 | + "# res = chat(\"Calculate ((10 + 5) * 3) / (2 + 1) step by step\", \n", |
| 1769 | + "# max_tool_rounds=2, return_all=True,\n", |
| 1770 | + "# final_prompt=\"Please summarize what you've calculated so far\")\n", |
| 1771 | + "# print(f\"Got {len(res)} responses\")\n", |
| 1772 | + "# for r in res: display(r)" |
1773 | 1773 | ] |
1774 | 1774 | }, |
1775 | 1775 | { |
|
1912 | 1912 | } |
1913 | 1913 | ], |
1914 | 1914 | "source": [ |
1915 | | - "chat = AsyncChat(model=\"claude-sonnet-4-20250514\")\n", |
1916 | | - "await chat(\"What is 2+2?\")" |
| 1915 | + "# chat = AsyncChat(model=\"claude-sonnet-4-20250514\")\n", |
| 1916 | + "# await chat(\"What is 2+2?\")" |
1917 | 1917 | ] |
1918 | 1918 | }, |
1919 | 1919 | { |
|
2002 | 2002 | } |
2003 | 2003 | ], |
2004 | 2004 | "source": [ |
2005 | | - "chat_with_tools = AsyncChat(model=\"claude-sonnet-4-20250514\", tools=[async_add])\n", |
2006 | | - "res = await chat_with_tools(\"What is 5 + 7? Use the tool to calculate it.\", return_all=True)\n", |
2007 | | - "async for r in res: display(r)" |
| 2005 | + "# chat_with_tools = AsyncChat(model=\"claude-sonnet-4-20250514\", tools=[async_add])\n", |
| 2006 | + "# res = await chat_with_tools(\"What is 5 + 7? Use the tool to calculate it.\", return_all=True)\n", |
| 2007 | + "# async for r in res: display(r)" |
2008 | 2008 | ] |
2009 | 2009 | }, |
2010 | 2010 | { |
|
2033 | 2033 | } |
2034 | 2034 | ], |
2035 | 2035 | "source": [ |
2036 | | - "chat_with_tools = AsyncChat(model=\"claude-sonnet-4-20250514\", tools=[async_add])\n", |
2037 | | - "res = await chat_with_tools(\"What is 5 + 7? Use the tool to calculate it.\", stream=True)\n", |
2038 | | - "async for o in res: \n", |
2039 | | - " if isinstance(o,ModelResponseStream): print(delta_text(o) or '',end='')\n", |
2040 | | - " elif isinstance(o,dict): print(o)" |
| 2036 | + "# chat_with_tools = AsyncChat(model=\"claude-sonnet-4-20250514\", tools=[async_add])\n", |
| 2037 | + "# res = await chat_with_tools(\"What is 5 + 7? Use the tool to calculate it.\", stream=True)\n", |
| 2038 | + "# async for o in res: \n", |
| 2039 | + "# if isinstance(o,ModelResponseStream): print(delta_text(o) or '',end='')\n", |
| 2040 | + "# elif isinstance(o,dict): print(o)" |
2041 | 2041 | ] |
2042 | 2042 | }, |
2043 | 2043 | { |
|
2104 | 2104 | } |
2105 | 2105 | ], |
2106 | 2106 | "source": [ |
2107 | | - "chat = AsyncChat(model=\"claude-sonnet-4-20250514\")\n", |
2108 | | - "res = await chat(\"What's the most efficient way to sort a list of 1000 random integers?\", think='l',stream=True)\n", |
2109 | | - "async for o in res: \n", |
2110 | | - " if isinstance(o,ModelResponseStream): print(delta_text(o) or '',end='')\n", |
2111 | | - " elif isinstance(o,dict): print(o)" |
| 2107 | + "# chat = AsyncChat(model=\"claude-sonnet-4-20250514\")\n", |
| 2108 | + "# res = await chat(\"What's the most efficient way to sort a list of 1000 random integers?\", think='l',stream=True)\n", |
| 2109 | + "# async for o in res: \n", |
| 2110 | + "# if isinstance(o,ModelResponseStream): print(delta_text(o) or '',end='')\n", |
| 2111 | + "# elif isinstance(o,dict): print(o)" |
2112 | 2112 | ] |
2113 | 2113 | }, |
2114 | 2114 | { |
|
2143 | 2143 | } |
2144 | 2144 | ], |
2145 | 2145 | "source": [ |
2146 | | - "chat_stream_tools = AsyncChat(model=\"claude-sonnet-4-20250514\", tools=[search_tool])\n", |
2147 | | - "res = await chat_stream_tools(\"Search the web and tell me very briefly about otters\", stream=True)\n", |
2148 | | - "outp = ''\n", |
2149 | | - "async for o in res: \n", |
2150 | | - " if isinstance(o,ModelResponseStream): outp+=delta_text(o) or ''\n", |
2151 | | - " elif isinstance(o,dict): outp+=str(o)+'\\n'\n", |
2152 | | - " display(Markdown(outp),clear=True)" |
| 2146 | + "# chat_stream_tools = AsyncChat(model=\"claude-sonnet-4-20250514\", tools=[search_tool])\n", |
| 2147 | + "# res = await chat_stream_tools(\"Search the web and tell me very briefly about otters\", stream=True)\n", |
| 2148 | + "# outp = ''\n", |
| 2149 | + "# async for o in res: \n", |
| 2150 | + "# if isinstance(o,ModelResponseStream): outp+=delta_text(o) or ''\n", |
| 2151 | + "# elif isinstance(o,dict): outp+=str(o)+'\\n'\n", |
| 2152 | + "# display(Markdown(outp),clear=True)" |
2153 | 2153 | ] |
2154 | 2154 | }, |
2155 | 2155 | { |
|
0 commit comments