|
176 | 176 | }, |
177 | 177 | { |
178 | 178 | "cell_type": "code", |
179 | | - "execution_count": null, |
| 179 | + "execution_count": 1, |
180 | 180 | "id": "a6da6e33-e3dd-45d3-abad-ad48a617b1db", |
181 | 181 | "metadata": {}, |
182 | 182 | "outputs": [], |
|
285 | 285 | }, |
286 | 286 | { |
287 | 287 | "cell_type": "code", |
288 | | - "execution_count": 5, |
| 288 | + "execution_count": 26, |
289 | 289 | "id": "4c7f6986-347b-4e50-94bb-31272e798130", |
290 | 290 | "metadata": {}, |
291 | 291 | "outputs": [], |
|
299 | 299 | " \"country\" and \"since_date\" to limit the returned customer list. The where clause can also \n", |
300 | 300 | " be followed by a limit clause to limit the number of returned names. \n", |
301 | 301 | "\n", |
302 | | - " :param string where_clause: the string containing the where and optionally limit clauses in SQL query format\n", |
| 302 | + " :param where_clause: the string containing the where and optionally limit clauses in SQL query format\n", |
| 303 | + " :type where_clause: string\n", |
303 | 304 | " :return: a list of matching customer names\n", |
304 | | - " :rtype: list of strings\n", |
| 305 | + " :rtype: array\n", |
305 | 306 | " \"\"\"\n", |
306 | 307 | " return [\"Monica Schmidt\", \"Harald Mueller\"]\n" |
307 | 308 | ] |
308 | 309 | }, |
309 | 310 | { |
310 | 311 | "cell_type": "code", |
311 | | - "execution_count": 6, |
| 312 | + "execution_count": 27, |
312 | 313 | "id": "0cbe8851", |
313 | 314 | "metadata": {}, |
314 | 315 | "outputs": [ |
|
330 | 331 | }, |
331 | 332 | { |
332 | 333 | "cell_type": "code", |
333 | | - "execution_count": 7, |
| 334 | + "execution_count": 28, |
334 | 335 | "id": "4722fb91", |
335 | 336 | "metadata": {}, |
336 | 337 | "outputs": [ |
|
340 | 341 | "['Monica Schmidt', 'Harald Mueller']" |
341 | 342 | ] |
342 | 343 | }, |
343 | | - "execution_count": 7, |
| 344 | + "execution_count": 28, |
344 | 345 | "metadata": {}, |
345 | 346 | "output_type": "execute_result" |
346 | 347 | } |
|
351 | 352 | }, |
352 | 353 | { |
353 | 354 | "cell_type": "code", |
354 | | - "execution_count": 8, |
| 355 | + "execution_count": 29, |
355 | 356 | "id": "b49ca6c6-e5ef-4a92-81b2-307c4c01143a", |
356 | 357 | "metadata": {}, |
357 | 358 | "outputs": [ |
|
367 | 368 | " 'required': ['where_clause']}}}]" |
368 | 369 | ] |
369 | 370 | }, |
370 | | - "execution_count": 8, |
| 371 | + "execution_count": 29, |
371 | 372 | "metadata": {}, |
372 | 373 | "output_type": "execute_result" |
373 | 374 | } |
|
379 | 380 | }, |
380 | 381 | { |
381 | 382 | "cell_type": "code", |
382 | | - "execution_count": 9, |
| 383 | + "execution_count": 30, |
383 | 384 | "id": "b2b274f9-a160-4074-a022-3d377fdc82fa", |
384 | 385 | "metadata": {}, |
385 | 386 | "outputs": [ |
|
389 | 390 | "True" |
390 | 391 | ] |
391 | 392 | }, |
392 | | - "execution_count": 9, |
| 393 | + "execution_count": 30, |
393 | 394 | "metadata": {}, |
394 | 395 | "output_type": "execute_result" |
395 | 396 | } |
|
400 | 401 | }, |
401 | 402 | { |
402 | 403 | "cell_type": "code", |
403 | | - "execution_count": 10, |
| 404 | + "execution_count": 31, |
404 | 405 | "id": "07928eb2", |
405 | 406 | "metadata": {}, |
406 | 407 | "outputs": [ |
|
410 | 411 | "False" |
411 | 412 | ] |
412 | 413 | }, |
413 | | - "execution_count": 10, |
| 414 | + "execution_count": 31, |
414 | 415 | "metadata": {}, |
415 | 416 | "output_type": "execute_result" |
416 | 417 | } |
|
421 | 422 | }, |
422 | 423 | { |
423 | 424 | "cell_type": "code", |
424 | | - "execution_count": 11, |
| 425 | + "execution_count": 32, |
425 | 426 | "id": "930d815e-d4fc-4a2e-aba0-4d4593900f50", |
426 | 427 | "metadata": {}, |
427 | 428 | "outputs": [ |
|
432 | 433 | " 'role': 'user'}]" |
433 | 434 | ] |
434 | 435 | }, |
435 | | - "execution_count": 11, |
| 436 | + "execution_count": 32, |
436 | 437 | "metadata": {}, |
437 | 438 | "output_type": "execute_result" |
438 | 439 | } |
|
444 | 445 | }, |
445 | 446 | { |
446 | 447 | "cell_type": "code", |
447 | | - "execution_count": 12, |
| 448 | + "execution_count": 33, |
448 | 449 | "id": "338e3b72-2ccc-47a0-9248-c422a232fdd4", |
449 | 450 | "metadata": {}, |
450 | 451 | "outputs": [ |
451 | | - { |
452 | | - "name": "stdout", |
453 | | - "output_type": "stream", |
454 | | - "text": [ |
455 | | - "DEBUG: cost for this call 0.0007250000000000001\n", |
456 | | - "DEBUG: checking for tool_calls: Message(content=None, role='assistant', tool_calls=[ChatCompletionMessageToolCall(function=Function(arguments='{\"where_clause\":\"city = \\'New York\\' AND since_date <= \\'2023-01-01\\'\"}', name='query_names'), id='call_QW2BQE2zqPZq0w7AG5FK7DwW', type='function')], function_call=None, provider_specific_fields={'refusal': None}, annotations=[]), have tools: True\n", |
457 | | - "DEBUG: got 1 tool calls:\n", |
458 | | - "DEBUG: ChatCompletionMessageToolCall(function=Function(arguments='{\"where_clause\":\"city = \\'New York\\' AND since_date <= \\'2023-01-01\\'\"}', name='query_names'), id='call_QW2BQE2zqPZq0w7AG5FK7DwW', type='function')\n", |
459 | | - "DEBUG: appending response message: Message(content=None, role='assistant', tool_calls=[ChatCompletionMessageToolCall(function=Function(arguments='{\"where_clause\":\"city = \\'New York\\' AND since_date <= \\'2023-01-01\\'\"}', name='query_names'), id='call_QW2BQE2zqPZq0w7AG5FK7DwW', type='function')], function_call=None, provider_specific_fields={'refusal': None}, annotations=[])\n", |
460 | | - "DEBUG: tool call query_names\n", |
461 | | - "DEBUG: calling query_names with args {'where_clause': \"city = 'New York' AND since_date <= '2023-01-01'\"}\n", |
462 | | - "DEBUG: got response ['Monica Schmidt', 'Harald Mueller']\n", |
463 | | - "DEBUG: recursively calling query with messages:\n", |
464 | | - "DEBUG: Message 0: {'content': 'Give me the names of customers in New York which have been customers since 2023 or longer', 'role': 'user'}\n", |
465 | | - "DEBUG: Message 1: Message(content=None, role='assistant', tool_calls=[ChatCompletionMessageToolCall(function=Function(arguments='{\"where_clause\":\"city = \\'New York\\' AND since_date <= \\'2023-01-01\\'\"}', name='query_names'), id='call_QW2BQE2zqPZq0w7AG5FK7DwW', type='function')], function_call=None, provider_specific_fields={'refusal': None}, annotations=[])\n", |
466 | | - "DEBUG: Message 2: {'tool_call_id': 'call_QW2BQE2zqPZq0w7AG5FK7DwW', 'role': 'tool', 'name': 'query_names', 'content': '[\"Monica Schmidt\", \"Harald Mueller\"]'}\n", |
467 | | - "DEBUG: recursively_call_info is {'start': 1745344687.546055, 'cost': 0.0007250000000000001, 'n_completion_tokens': 33, 'n_prompt_tokens': 158, 'n_total_tokens': 191}\n" |
468 | | - ] |
469 | | - }, |
470 | 452 | { |
471 | 453 | "name": "stderr", |
472 | 454 | "output_type": "stream", |
473 | 455 | "text": [ |
474 | 456 | "/home/johann/software/anaconda/envs/llms_wrapper/lib/python3.11/site-packages/pydantic/main.py:463: UserWarning: Pydantic serializer warnings:\n", |
475 | | - " PydanticSerializationUnexpectedValue(Expected `ChatCompletionMessageToolCall` - serialized value may not be as expected [input_value={'function': {'arguments'...wW', 'type': 'function'}, input_type=dict])\n", |
| 457 | + " PydanticSerializationUnexpectedValue(Expected `ChatCompletionMessageToolCall` - serialized value may not be as expected [input_value={'function': {'arguments'...xq', 'type': 'function'}, input_type=dict])\n", |
476 | 458 | " return self.__pydantic_serializer__.to_python(\n" |
477 | 459 | ] |
478 | 460 | }, |
479 | | - { |
480 | | - "name": "stdout", |
481 | | - "output_type": "stream", |
482 | | - "text": [ |
483 | | - "DEBUG: cost for this call 0.00083\n", |
484 | | - "DEBUG: checking for tool_calls: Message(content='Here are the names of customers in New York who have been customers since 2023 or longer:\\n\\n1. Monica Schmidt\\n2. Harald Mueller', role='assistant', tool_calls=None, function_call=None, provider_specific_fields={'refusal': None}, annotations=[]), have tools: True\n", |
485 | | - "DEBUG: got 0 tool calls:\n" |
486 | | - ] |
487 | | - }, |
488 | 461 | { |
489 | 462 | "data": { |
490 | 463 | "text/plain": [ |
491 | | - "('Here are the names of customers in New York who have been customers since 2023 or longer:\\n\\n1. Monica Schmidt\\n2. Harald Mueller',\n", |
| 464 | + "('The customers in New York who have been customers since 2023 or longer are:\\n\\n- Monica Schmidt\\n- Harald Mueller',\n", |
492 | 465 | " '')" |
493 | 466 | ] |
494 | 467 | }, |
495 | | - "execution_count": 12, |
| 468 | + "execution_count": 33, |
496 | 469 | "metadata": {}, |
497 | 470 | "output_type": "execute_result" |
498 | 471 | } |
499 | 472 | ], |
500 | 473 | "source": [ |
501 | | - "ret = llms.query(\"openai/gpt-4o\", messages=msgs, tools=tools, debug=True, return_cost=True)\n", |
| 474 | + "ret = llms.query(\"openai/gpt-4o\", messages=msgs, tools=tools, return_cost=True)\n", |
502 | 475 | "ret[\"answer\"], ret[\"error\"]" |
503 | 476 | ] |
504 | 477 | }, |
|
511 | 484 | { |
512 | 485 | "data": { |
513 | 486 | "text/plain": [ |
514 | | - "{'elapsed_time': 0.8021302223205566,\n", |
515 | | - " 'cost': 0.0008800000000000001,\n", |
516 | | - " 'n_completion_tokens': 27,\n", |
517 | | - " 'n_prompt_tokens': 244,\n", |
518 | | - " 'n_total_tokens': 271,\n", |
| 487 | + "{'elapsed_time': 1.8553009033203125,\n", |
| 488 | + " 'cost': 0.0015425,\n", |
| 489 | + " 'n_completion_tokens': 63,\n", |
| 490 | + " 'n_prompt_tokens': 365,\n", |
| 491 | + " 'n_total_tokens': 428,\n", |
519 | 492 | " 'finish_reason': 'stop',\n", |
520 | | - " 'answer': 'The customers in New York who have been with us since 2023 or longer are:\\n\\n- Monica Schmidt\\n- Harald Mueller',\n", |
| 493 | + " 'answer': 'Here are the names of customers in New York who have been customers since 2023 or longer:\\n\\n1. Monica Schmidt\\n2. Harald Mueller',\n", |
521 | 494 | " 'error': '',\n", |
522 | 495 | " 'ok': True}" |
523 | 496 | ] |
|
546 | 519 | "metadata": {}, |
547 | 520 | "outputs": [], |
548 | 521 | "source": [] |
| 522 | + }, |
| 523 | + { |
| 524 | + "cell_type": "code", |
| 525 | + "execution_count": null, |
| 526 | + "id": "aeec211c", |
| 527 | + "metadata": {}, |
| 528 | + "outputs": [], |
| 529 | + "source": [] |
549 | 530 | } |
550 | 531 | ], |
551 | 532 | "metadata": { |
|
0 commit comments