|
68 | 68 | }, |
69 | 69 | { |
70 | 70 | "cell_type": "code", |
71 | | - "execution_count": 3, |
| 71 | + "execution_count": null, |
72 | 72 | "id": "82bdb67e-7187-45d8-8408-49102c8432c4", |
73 | 73 | "metadata": {}, |
74 | | - "outputs": [ |
75 | | - { |
76 | | - "name": "stdin", |
77 | | - "output_type": "stream", |
78 | | - "text": [ |
79 | | - "Enter your OpenAI API key: ········\n" |
80 | | - ] |
81 | | - } |
82 | | - ], |
| 74 | + "outputs": [], |
83 | 75 | "source": [ |
84 | 76 | "from getpass import getpass\n", |
85 | 77 | "import os\n", |
|
142 | 134 | " \"\"\"Add two numbers.\"\"\"\n", |
143 | 135 | " return a + b\n", |
144 | 136 | "\n", |
145 | | - "addition_tool = create_tool_from_function(\n", |
146 | | - " function=addition,\n", |
147 | | - " name=\"addition\",\n", |
148 | | - " description=\"Add two floats together.\",\n", |
149 | | - ")\n", |
| 137 | + "\n", |
| 138 | + "addition_tool = create_tool_from_function(function=addition, name=\"addition\", description=\"Add two floats together.\")\n", |
| 139 | + "\n", |
150 | 140 | "\n", |
151 | 141 | "def get_bank_balance(account_id: str) -> str:\n", |
152 | 142 | " \"\"\"Simulate fetching a bank balance.\"\"\"\n", |
153 | 143 | " return f\"Balance for account {account_id} is $1,234.56\"\n", |
154 | 144 | "\n", |
| 145 | + "\n", |
155 | 146 | "balance_tool = create_tool_from_function(\n", |
156 | | - " function=get_bank_balance,\n", |
157 | | - " name=\"get_bank_balance\",\n", |
158 | | - " description=\"Get the bank balance for a given account ID.\",\n", |
| 147 | + " function=get_bank_balance, name=\"get_bank_balance\", description=\"Get the bank balance for a given account ID.\"\n", |
159 | 148 | ")\n", |
160 | 149 | "\n", |
| 150 | + "\n", |
161 | 151 | "def get_phone_number(name: str) -> str:\n", |
162 | 152 | " \"\"\"Simulate fetching a phone number.\"\"\"\n", |
163 | 153 | " return f\"The phone number for {name} is (123) 456-7890\"\n", |
164 | 154 | "\n", |
| 155 | + "\n", |
165 | 156 | "phone_tool = create_tool_from_function(\n", |
166 | | - " function=get_phone_number,\n", |
167 | | - " name=\"get_phone_number\",\n", |
168 | | - " description=\"Get the phone number for a given name.\",\n", |
| 157 | + " function=get_phone_number, name=\"get_phone_number\", description=\"Get the phone number for a given name.\"\n", |
169 | 158 | ")" |
170 | 159 | ] |
171 | 160 | }, |
|
194 | 183 | " system_prompt=\"You are a helpful financial assistant. Use the provided tools to answer user questions.\",\n", |
195 | 184 | " confirmation_strategies={\n", |
196 | 185 | " balance_tool.name: BlockingConfirmationStrategy(\n", |
197 | | - " confirmation_policy=AlwaysAskPolicy(),\n", |
198 | | - " confirmation_ui=RichConsoleUI(console=cons),\n", |
| 186 | + " confirmation_policy=AlwaysAskPolicy(), confirmation_ui=RichConsoleUI(console=cons)\n", |
199 | 187 | " ),\n", |
200 | 188 | " addition_tool.name: BlockingConfirmationStrategy(\n", |
201 | | - " confirmation_policy=NeverAskPolicy(),\n", |
202 | | - " confirmation_ui=RichConsoleUI(console=cons),\n", |
| 189 | + " confirmation_policy=NeverAskPolicy(), confirmation_ui=RichConsoleUI(console=cons)\n", |
203 | 190 | " ),\n", |
204 | 191 | " phone_tool.name: BlockingConfirmationStrategy(\n", |
205 | | - " confirmation_policy=AskOncePolicy(),\n", |
206 | | - " confirmation_ui=RichConsoleUI(console=cons),\n", |
| 192 | + " confirmation_policy=AskOncePolicy(), confirmation_ui=RichConsoleUI(console=cons)\n", |
207 | 193 | " ),\n", |
208 | 194 | " },\n", |
209 | 195 | ")" |
|
232 | 218 | "\n", |
233 | 219 | "- **y**: Proceed with the tool execution as planned\n", |
234 | 220 | "- **n**: Cancel the tool execution; agent will try alternative approaches\n", |
235 | | - "- **m**: Edit the tool parameters before execution (advanced)\n", |
| 221 | + "- **m**: Edit the tool parameters before execution\n", |
236 | 222 | "\n", |
237 | 223 | "**NOTE**: Custom UIs and Policies can also be implemented by following the respective `ConfirmationUI` and `ConfirmationPolicy` protocols. This allows full flexibility for domain-specific workflows." |
238 | 224 | ] |
|
559 | 545 | "source": [ |
560 | 546 | "def expense(cost: float, description: str) -> float:\n", |
561 | 547 | " \"\"\"Submit an expense report that has a `cost` and `description`\"\"\"\n", |
562 | | - " # This is where we would add a real submission request \n", |
| 548 | + " # This is where we would add a real submission request\n", |
563 | 549 | " return \"Expense report submitted successfully!\"\n", |
564 | 550 | "\n", |
| 551 | + "\n", |
565 | 552 | "expense_tool = create_tool_from_function(\n", |
566 | | - " function=expense,\n", |
567 | | - " name=\"expense\",\n", |
568 | | - " description=\"Submit an expense report that has a `cost` and `description`\",\n", |
| 553 | + " function=expense, name=\"expense\", description=\"Submit an expense report that has a `cost` and `description`\"\n", |
569 | 554 | ")\n", |
570 | 555 | "\n", |
571 | 556 | "cons = Console()\n", |
|
580 | 565 | " ),\n", |
581 | 566 | " confirmation_strategies={\n", |
582 | 567 | " expense_tool.name: BlockingConfirmationStrategy(\n", |
583 | | - " confirmation_policy=BudgetBasedPolicy(cost_threshold=100.0),\n", |
584 | | - " confirmation_ui=RichConsoleUI(console=cons),\n", |
585 | | - " ),\n", |
| 568 | + " confirmation_policy=BudgetBasedPolicy(cost_threshold=100.0), confirmation_ui=RichConsoleUI(console=cons)\n", |
| 569 | + " )\n", |
586 | 570 | " },\n", |
587 | 571 | ")" |
588 | 572 | ] |
|
751 | 735 | "\n", |
752 | 736 | "(*Notebook by [Sebastian Husch Lee](https://github.com/sjrl)*)" |
753 | 737 | ] |
754 | | - }, |
755 | | - { |
756 | | - "cell_type": "code", |
757 | | - "execution_count": null, |
758 | | - "id": "27655802-50e2-44aa-904e-78ba1f9b77b8", |
759 | | - "metadata": {}, |
760 | | - "outputs": [], |
761 | | - "source": [] |
762 | 738 | } |
763 | 739 | ], |
764 | 740 | "metadata": { |
|
0 commit comments