|
7 | 7 | "metadata": {
|
8 | 8 | "collapsed": true,
|
9 | 9 | "ExecuteTime": {
|
10 |
| - "end_time": "2023-11-30T11:56:53.238031Z", |
11 |
| - "start_time": "2023-11-30T11:56:53.081526Z" |
| 10 | + "end_time": "2023-11-30T12:09:18.938Z", |
| 11 | + "start_time": "2023-11-30T12:09:18.762167Z" |
12 | 12 | }
|
13 | 13 | },
|
14 | 14 | "outputs": [],
|
|
49 | 49 | "name": "stdout",
|
50 | 50 | "output_type": "stream",
|
51 | 51 | "text": [
|
52 |
| - "created action: object='Action' action_id='bFBd4I6YoHOiIgEnTpICAgC8' schema={'info': {'title': 'Numbers API', 'version': '1.0.0', 'description': 'API for fetching interesting number facts'}, 'paths': {'/{number}': {'get': {'summary': 'Get fact about a number', 'responses': {'200': {'content': {'text/plain': {'schema': {'type': 'string'}}}, 'description': 'A fact about the number'}}, 'parameters': [{'in': 'path', 'name': 'number', 'schema': {'type': 'integer'}, 'required': True, 'description': 'The number to get the fact for'}]}}}, 'openapi': '3.0.0', 'servers': [{'url': 'http://numbersapi.com'}], 'security': [], 'components': {}} authentication=ActionAuthentication(type=<ActionAuthenticationType.none: 'none'>, secret=None, content=None) created_timestamp=1701345415792\n" |
| 52 | + "created action: object='Action' action_id='bFBdHBaYSXzuiLjn4WsFQdKx' schema={'info': {'title': 'Numbers API', 'version': '1.0.0', 'description': 'API for fetching interesting number facts'}, 'paths': {'/{number}': {'get': {'summary': 'Get fact about a number', 'responses': {'200': {'content': {'text/plain': {'schema': {'type': 'string'}}}, 'description': 'A fact about the number'}}, 'parameters': [{'in': 'path', 'name': 'number', 'schema': {'type': 'integer'}, 'required': True, 'description': 'The number to get the fact for'}]}}}, 'openapi': '3.0.0', 'servers': [{'url': 'http://numbersapi.com'}], 'security': [], 'components': {}} authentication=ActionAuthentication(type=<ActionAuthenticationType.none: 'none'>, secret=None, content=None) created_timestamp=1701346163304\n" |
53 | 53 | ]
|
54 | 54 | }
|
55 | 55 | ],
|
|
113 | 113 | "metadata": {
|
114 | 114 | "collapsed": false,
|
115 | 115 | "ExecuteTime": {
|
116 |
| - "end_time": "2023-11-30T11:56:55.907860Z", |
117 |
| - "start_time": "2023-11-30T11:56:54.639041Z" |
| 116 | + "end_time": "2023-11-30T12:09:23.498384Z", |
| 117 | + "start_time": "2023-11-30T12:09:21.928940Z" |
118 | 118 | }
|
119 | 119 | },
|
120 | 120 | "id": "3b2fda39ba58c5e9"
|
|
127 | 127 | "name": "stdout",
|
128 | 128 | "output_type": "stream",
|
129 | 129 | "text": [
|
130 |
| - "created assistant: object='Assistant' assistant_id='X5lMUSFLWzESDvTmy0SwOx0v' model_id='Gk1145Bl' name='My Assistant' description='A assistant who knows the meaning of various numbers.' system_prompt_template=['You know the meaning of various numbers.', \"No matter what the user's language is, you will use the {{langugae}} to explain.\"] tools=[AssistantTool(type=<AssistantToolType.action: 'action'>, id='bFBd4I6YoHOiIgEnTpICAgC8')] retrievals=[] metadata={'foo': 'bar'} created_timestamp=1701345417694\n" |
| 130 | + "created assistant: object='Assistant' assistant_id='X5lMf7ClPfuFxRLQqXiwukim' model_id='Gk1145Bl' name='My Assistant' description='A assistant who knows the meaning of various numbers.' system_prompt_template=['You know the meaning of various numbers.', \"No matter what the user's language is, you will use the {{langugae}} to explain.\"] tools=[AssistantTool(type=<AssistantToolType.action: 'action'>, id='bFBdHBaYSXzuiLjn4WsFQdKx')] retrievals=[] metadata={'foo': 'bar'} created_timestamp=1701346165503\n" |
131 | 131 | ]
|
132 | 132 | }
|
133 | 133 | ],
|
|
157 | 157 | "metadata": {
|
158 | 158 | "collapsed": false,
|
159 | 159 | "ExecuteTime": {
|
160 |
| - "end_time": "2023-11-30T11:56:57.786789Z", |
161 |
| - "start_time": "2023-11-30T11:56:56.560889Z" |
| 160 | + "end_time": "2023-11-30T12:09:25.600307Z", |
| 161 | + "start_time": "2023-11-30T12:09:24.021512Z" |
162 | 162 | }
|
163 | 163 | },
|
164 | 164 | "id": "3b3df0f232021283"
|
|
181 | 181 | "name": "stdout",
|
182 | 182 | "output_type": "stream",
|
183 | 183 | "text": [
|
184 |
| - "created chat: SdELqszTR3IXt51rBj0svkSq\n" |
| 184 | + "created chat: SdELoFCq7a8er2LphedC6ANK\n" |
185 | 185 | ]
|
186 | 186 | }
|
187 | 187 | ],
|
|
194 | 194 | "metadata": {
|
195 | 195 | "collapsed": false,
|
196 | 196 | "ExecuteTime": {
|
197 |
| - "end_time": "2023-11-30T11:56:59.106482Z", |
198 |
| - "start_time": "2023-11-30T11:56:58.723727Z" |
| 197 | + "end_time": "2023-11-30T12:09:26.676705Z", |
| 198 | + "start_time": "2023-11-30T12:09:26.256500Z" |
199 | 199 | }
|
200 | 200 | },
|
201 | 201 | "id": "f1e2f0b2af8b1d8d"
|
202 | 202 | },
|
203 | 203 | {
|
204 | 204 | "cell_type": "code",
|
205 |
| - "execution_count": 5, |
206 |
| - "outputs": [ |
207 |
| - { |
208 |
| - "name": "stdout", |
209 |
| - "output_type": "stream", |
210 |
| - "text": [ |
211 |
| - "User: hi\n", |
212 |
| - "Assistant: Hello! How can I assist you today?\n", |
213 |
| - "User: what is the meaning of 12\n", |
214 |
| - "Assistant: The number 12 is often associated with various meanings depending on the context. Here are some interpretations:\n", |
215 |
| - "\n", |
216 |
| - "1. Numerology: In numerology, 12 is considered a powerful number associated with completion, harmony, and a sense of wholeness. It is often seen as a symbol of perfection, balance, and divine guidance.\n", |
217 |
| - "\n", |
218 |
| - "2. Time: There are 12 months in a year, and this is based on the approximate time it takes for the moon to complete its cycle around the Earth. Additionally, there are 12 hours on a clock face, both in the morning and in the evening.\n", |
219 |
| - "\n", |
220 |
| - "3. Mathematics: 12 is divisible by 1, 2, 3, 4, 6, and itself, making it a highly composite number. It also has a prime factorization of 2^2 × 3, which is significant in number theory.\n", |
221 |
| - "\n", |
222 |
| - "4. Religion and Mythology: In many religious beliefs and mythologies, there are groups or sets of 12. For instance, there are 12 disciples of Jesus in Christianity, 12 signs of the zodiac in astrology, and 12 Olympian gods in Greek mythology.\n", |
223 |
| - "\n", |
224 |
| - "5. Measurement: The duodecimal numerical system, based on the number 12, was historically used in some cultures for counting and measurements. This system is still present in modern times in certain contexts, such as inches in a foot (12 inches) and the number of members in a jury (often 12).\n", |
225 |
| - "\n", |
226 |
| - "These are just a few examples of the meaning associated with the number 12. The interpretation can vary depending on the cultural, historical, or personal perspectives.\n", |
227 |
| - "User: thanks\n", |
228 |
| - "Assistant: You're welcome! If you have any more questions, feel free to ask.\n" |
229 |
| - ] |
230 |
| - } |
231 |
| - ], |
| 205 | + "execution_count": 6, |
| 206 | + "outputs": [], |
232 | 207 | "source": [
|
233 | 208 | "from taskingai.assistant import Message, MessageChunk\n",
|
234 |
| - "\n", |
235 | 209 | "user_input = input(\"User Input: \")\n",
|
236 | 210 | "while user_input != \"q\":\n",
|
237 | 211 | " # create user message\n",
|
|
257 | 231 | "metadata": {
|
258 | 232 | "collapsed": false,
|
259 | 233 | "ExecuteTime": {
|
260 |
| - "end_time": "2023-11-30T11:57:37.676466Z", |
261 |
| - "start_time": "2023-11-30T11:57:00.619700Z" |
| 234 | + "end_time": "2023-11-30T12:09:42.827896Z", |
| 235 | + "start_time": "2023-11-30T12:09:41.040732Z" |
262 | 236 | }
|
263 | 237 | },
|
264 | 238 | "id": "b26e30b79b71697a"
|
265 | 239 | },
|
266 | 240 | {
|
267 | 241 | "cell_type": "code",
|
268 |
| - "execution_count": 6, |
| 242 | + "execution_count": 7, |
269 | 243 | "outputs": [
|
270 | 244 | {
|
271 | 245 | "name": "stdout",
|
272 | 246 | "output_type": "stream",
|
273 | 247 | "text": [
|
274 |
| - "User: what about 127\n", |
275 |
| - "Assistant: The number 127 is the atomic number of Unbiseptium, an element that has not yet been discovered. In the periodic table of elements, each unique element has an atomic number that corresponds to the number of protons in its nucleus. However, as of now, no element with 127 protons has been confirmed or named. Therefore, 127 represents a theoretical element that scientists have not yet observed or identified.\n", |
276 |
| - "message_id: Mah1zSgBZpDuLvpEnVhEmWZy\n", |
277 |
| - "User: bye\n", |
278 |
| - "Assistant: Goodbye! If you have any more questions in the future, feel free to ask. Have a great day!\n", |
279 |
| - "message_id: Mah1uIUcePTL7gvPjzl6JtpM\n" |
| 248 | + "User: what is the meaning of 127\n", |
| 249 | + "Assistant: {'object': 'MessageGenerationLog', 'type': 'tool_call', 'session_id': 'D9JshtlLZk4vluhm93bhsn9m', 'created_timestamp': 1701346187791, 'tool': {'tool_id': 'bFBdHBaYSXzuiLjn4WsFQdKx', 'type': 'action', 'name': 'get_by', 'input': '{\"number\": 127}', 'output': None}}\n" |
| 250 | + ] |
| 251 | + }, |
| 252 | + { |
| 253 | + "ename": "ValidationError", |
| 254 | + "evalue": "1 validation error for MessageGenerationLog\nretrieval\n Field required [type=missing, input_value={'object': 'MessageGenera... 127}', 'output': None}}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.5/v/missing", |
| 255 | + "output_type": "error", |
| 256 | + "traceback": [ |
| 257 | + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", |
| 258 | + "\u001B[0;31mValidationError\u001B[0m Traceback (most recent call last)", |
| 259 | + "Cell \u001B[0;32mIn[7], line 25\u001B[0m\n\u001B[1;32m 14\u001B[0m assistant_message_response \u001B[38;5;241m=\u001B[39m taskingai\u001B[38;5;241m.\u001B[39massistant\u001B[38;5;241m.\u001B[39mgenerate_assistant_message(\n\u001B[1;32m 15\u001B[0m assistant_id\u001B[38;5;241m=\u001B[39massistant\u001B[38;5;241m.\u001B[39massistant_id,\n\u001B[1;32m 16\u001B[0m chat_id\u001B[38;5;241m=\u001B[39mchat\u001B[38;5;241m.\u001B[39mchat_id,\n\u001B[0;32m (...)\u001B[0m\n\u001B[1;32m 21\u001B[0m debug\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m,\n\u001B[1;32m 22\u001B[0m )\n\u001B[1;32m 24\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mAssistant:\u001B[39m\u001B[38;5;124m\"\u001B[39m, end\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m \u001B[39m\u001B[38;5;124m\"\u001B[39m, flush\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m)\n\u001B[0;32m---> 25\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m item \u001B[38;5;129;01min\u001B[39;00m assistant_message_response:\n\u001B[1;32m 27\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(item, MessageChunk):\n\u001B[1;32m 28\u001B[0m \u001B[38;5;28mprint\u001B[39m(item\u001B[38;5;241m.\u001B[39mdelta, end\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m\"\u001B[39m, flush\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m)\n", |
| 260 | + "File \u001B[0;32m~/tasking_ai_backend/taskingai-python-client-231106/taskingai/client/stream.py:47\u001B[0m, in \u001B[0;36mStream.__iter__\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 46\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21m__iter__\u001B[39m(\u001B[38;5;28mself\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m Iterator[Dict]:\n\u001B[0;32m---> 47\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m item \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_iterator:\n\u001B[1;32m 48\u001B[0m \u001B[38;5;28;01myield\u001B[39;00m item\n", |
| 261 | + "File \u001B[0;32m~/tasking_ai_backend/taskingai-python-client-231106/taskingai/client/stream.py:68\u001B[0m, in \u001B[0;36mStream.__stream__\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 62\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(data, Dict) \u001B[38;5;129;01mand\u001B[39;00m data\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124merror\u001B[39m\u001B[38;5;124m\"\u001B[39m):\n\u001B[1;32m 63\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m ApiException(\n\u001B[1;32m 64\u001B[0m status\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m400\u001B[39m, \u001B[38;5;66;03m# or appropriate status code\u001B[39;00m\n\u001B[1;32m 65\u001B[0m reason\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mAn error occurred during streaming\u001B[39m\u001B[38;5;124m\"\u001B[39m,\n\u001B[1;32m 66\u001B[0m )\n\u001B[0;32m---> 68\u001B[0m \u001B[38;5;28;01myield\u001B[39;00m \u001B[43m_cast\u001B[49m\u001B[43m(\u001B[49m\u001B[43mdata\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 70\u001B[0m \u001B[38;5;66;03m# Ensure the entire stream is consumed\u001B[39;00m\n\u001B[1;32m 71\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m sse \u001B[38;5;129;01min\u001B[39;00m iterator:\n", |
| 262 | + "File \u001B[0;32m~/tasking_ai_backend/taskingai-python-client-231106/taskingai/client/stream.py:30\u001B[0m, in \u001B[0;36m_cast\u001B[0;34m(item)\u001B[0m\n\u001B[1;32m 28\u001B[0m \u001B[38;5;28;01melif\u001B[39;00m item\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mobject\u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mMessageGenerationLog\u001B[39m\u001B[38;5;124m\"\u001B[39m:\n\u001B[1;32m 29\u001B[0m \u001B[38;5;28mprint\u001B[39m(item)\n\u001B[0;32m---> 30\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mMessageGenerationLog\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[38;5;241;43m*\u001B[39;49m\u001B[43mitem\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 31\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m 32\u001B[0m \u001B[38;5;66;03m# cannot cast, keep the original dict\u001B[39;00m\n\u001B[1;32m 33\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m item\n", |
| 263 | + "File \u001B[0;32m~/opt/anaconda3/envs/taskingai-python-client-231106/lib/python3.10/site-packages/pydantic/main.py:164\u001B[0m, in \u001B[0;36mBaseModel.__init__\u001B[0;34m(__pydantic_self__, **data)\u001B[0m\n\u001B[1;32m 162\u001B[0m \u001B[38;5;66;03m# `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks\u001B[39;00m\n\u001B[1;32m 163\u001B[0m __tracebackhide__ \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mTrue\u001B[39;00m\n\u001B[0;32m--> 164\u001B[0m \u001B[43m__pydantic_self__\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m__pydantic_validator__\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mvalidate_python\u001B[49m\u001B[43m(\u001B[49m\u001B[43mdata\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mself_instance\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m__pydantic_self__\u001B[49m\u001B[43m)\u001B[49m\n", |
| 264 | + "\u001B[0;31mValidationError\u001B[0m: 1 validation error for MessageGenerationLog\nretrieval\n Field required [type=missing, input_value={'object': 'MessageGenera... 127}', 'output': None}}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.5/v/missing" |
280 | 265 | ]
|
281 | 266 | }
|
282 | 267 | ],
|
283 | 268 | "source": [
|
284 |
| - "# response in stream\n", |
| 269 | + "from taskingai.assistant import MessageGenerationLog\n", |
285 | 270 | "\n",
|
286 | 271 | "user_input = input(\"User Input: \")\n",
|
287 | 272 | "while user_input != \"q\":\n",
|
|
301 | 286 | " \"language\": \"English\"\n",
|
302 | 287 | " },\n",
|
303 | 288 | " stream=True,\n",
|
| 289 | + " debug=True,\n", |
304 | 290 | " )\n",
|
305 | 291 | " \n",
|
306 | 292 | " print(f\"Assistant:\", end=\" \", flush=True)\n",
|
|
309 | 295 | " if isinstance(item, MessageChunk):\n",
|
310 | 296 | " print(item.delta, end=\"\", flush=True)\n",
|
311 | 297 | " \n",
|
| 298 | + " elif isinstance(item, MessageGenerationLog):\n", |
| 299 | + " print(f\"\\nlog: {item}\")\n", |
| 300 | + " \n", |
312 | 301 | " elif isinstance(item, Message):\n",
|
313 | 302 | " print(f\"\\nmessage_id: {item.message_id}\")\n",
|
314 | 303 | " \n",
|
|
319 | 308 | "metadata": {
|
320 | 309 | "collapsed": false,
|
321 | 310 | "ExecuteTime": {
|
322 |
| - "end_time": "2023-11-30T11:58:24.864156Z", |
323 |
| - "start_time": "2023-11-30T11:57:58.379023Z" |
| 311 | + "end_time": "2023-11-30T12:09:48.761608Z", |
| 312 | + "start_time": "2023-11-30T12:09:44.158846Z" |
324 | 313 | }
|
325 | 314 | },
|
326 | 315 | "id": "c7d73e0b138e3eba"
|
|
0 commit comments