Skip to content

Commit d9cebc1

Browse files
committed
fix(huggingface): Capture streamed tool calls
1 parent cb2f835 commit d9cebc1

10 files changed

Lines changed: 1144 additions & 142 deletions

e2e/scenarios/huggingface-instrumentation/__snapshots__/huggingface-v281.log-payloads.json

Lines changed: 197 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@
318318
"id": "<span:14>",
319319
"log_id": "g",
320320
"metadata": {
321-
"operation": "text-generation-stream",
321+
"operation": "chat-stream-tool-call",
322322
"testRunId": "<run:1>"
323323
},
324324
"metrics": {
@@ -328,7 +328,7 @@
328328
"root_span_id": "<span:2>",
329329
"span_attributes": {
330330
"exec_counter": 5,
331-
"name": "huggingface-text-generation-stream-operation"
331+
"name": "huggingface-chat-stream-tool-call-operation"
332332
},
333333
"span_id": "<span:15>",
334334
"span_parents": [
@@ -353,13 +353,41 @@
353353
"context": {},
354354
"created": "<timestamp>",
355355
"id": "<span:16>",
356-
"input": "The capital of France is",
356+
"input": [
357+
{
358+
"content": "What is the weather in San Francisco? Call the get_current_weather tool.",
359+
"role": "user"
360+
}
361+
],
357362
"log_id": "g",
358363
"metadata": {
359-
"endpointUrl": "https://router.huggingface.co/featherless-ai/v1/completions",
360-
"max_tokens": 4,
361-
"model": "arcee-ai/Trinity-Large-Thinking",
362-
"provider": "huggingface"
364+
"endpointUrl": "https://router.huggingface.co",
365+
"max_tokens": 64,
366+
"model": "meta-llama/Llama-3.1-8B-Instruct",
367+
"provider": "featherless-ai",
368+
"temperature": 0,
369+
"tool_choice": "required",
370+
"tools": [
371+
{
372+
"function": {
373+
"description": "Get the current weather for a location.",
374+
"name": "get_current_weather",
375+
"parameters": {
376+
"properties": {
377+
"location": {
378+
"description": "City and state or city and country.",
379+
"type": "string"
380+
}
381+
},
382+
"required": [
383+
"location"
384+
],
385+
"type": "object"
386+
}
387+
},
388+
"type": "function"
389+
}
390+
]
363391
},
364392
"metrics": {
365393
"start": "<timestamp>"
@@ -368,7 +396,7 @@
368396
"root_span_id": "<span:2>",
369397
"span_attributes": {
370398
"exec_counter": 6,
371-
"name": "huggingface.text_generation_stream",
399+
"name": "huggingface.chat_completion_stream",
372400
"type": "llm"
373401
},
374402
"span_id": "<span:17>",
@@ -381,10 +409,14 @@
381409
"id": "<span:16>",
382410
"log_id": "g",
383411
"metrics": {
384-
"completion_tokens": 4,
385-
"prompt_tokens": 6,
412+
"completion_accepted_prediction_tokens": 0,
413+
"completion_reasoning_tokens": 0,
414+
"completion_rejected_prediction_tokens": 0,
415+
"completion_tokens": 20,
416+
"prompt_cached_tokens": 384,
417+
"prompt_tokens": 394,
386418
"time_to_first_token": "<number>",
387-
"tokens": 10
419+
"tokens": 414
388420
},
389421
"project_id": "<project_id>",
390422
"root_span_id": "<span:2>",
@@ -398,11 +430,29 @@
398430
"id": "<span:16>",
399431
"log_id": "g",
400432
"metadata": {
401-
"finish_reason": "length"
433+
"created": 0,
434+
"id": "<span:19>",
435+
"model": "llama3.1-8b",
436+
"object": "chat.completion.chunk"
402437
},
403438
"output": {
404-
"finish_reason": "length",
405-
"generated_text": "<string>"
439+
"choices": [
440+
{
441+
"content": "<string>",
442+
"finish_reason": "tool_calls",
443+
"index": 0,
444+
"role": "assistant",
445+
"tool_calls": [
446+
{
447+
"arguments": "<string>",
448+
"id": "<span:18>",
449+
"index": null,
450+
"name": "get_current_weather",
451+
"type": "function"
452+
}
453+
]
454+
}
455+
]
406456
},
407457
"project_id": "<project_id>",
408458
"root_span_id": "<span:2>",
@@ -433,10 +483,10 @@
433483
"caller_lineno": 0
434484
},
435485
"created": "<timestamp>",
436-
"id": "<span:18>",
486+
"id": "<span:20>",
437487
"log_id": "g",
438488
"metadata": {
439-
"operation": "feature-extraction",
489+
"operation": "text-generation-stream",
440490
"testRunId": "<run:1>"
441491
},
442492
"metrics": {
@@ -446,31 +496,149 @@
446496
"root_span_id": "<span:2>",
447497
"span_attributes": {
448498
"exec_counter": 7,
499+
"name": "huggingface-text-generation-stream-operation"
500+
},
501+
"span_id": "<span:21>",
502+
"span_parents": [
503+
"<span:2>"
504+
]
505+
},
506+
{
507+
"_is_merge": true,
508+
"id": "<span:20>",
509+
"log_id": "g",
510+
"metrics": {
511+
"end": "<timestamp>"
512+
},
513+
"project_id": "<project_id>",
514+
"root_span_id": "<span:2>",
515+
"span_id": "<span:21>",
516+
"span_parents": [
517+
"<span:2>"
518+
]
519+
},
520+
{
521+
"context": {},
522+
"created": "<timestamp>",
523+
"id": "<span:22>",
524+
"input": "The capital of France is",
525+
"log_id": "g",
526+
"metadata": {
527+
"endpointUrl": "https://router.huggingface.co/featherless-ai/v1/completions",
528+
"max_tokens": 4,
529+
"model": "arcee-ai/Trinity-Large-Thinking",
530+
"provider": "huggingface"
531+
},
532+
"metrics": {
533+
"start": "<timestamp>"
534+
},
535+
"project_id": "<project_id>",
536+
"root_span_id": "<span:2>",
537+
"span_attributes": {
538+
"exec_counter": 8,
539+
"name": "huggingface.text_generation_stream",
540+
"type": "llm"
541+
},
542+
"span_id": "<span:23>",
543+
"span_parents": [
544+
"<span:21>"
545+
]
546+
},
547+
{
548+
"_is_merge": true,
549+
"id": "<span:22>",
550+
"log_id": "g",
551+
"metrics": {
552+
"completion_tokens": 4,
553+
"prompt_tokens": 6,
554+
"time_to_first_token": "<number>",
555+
"tokens": 10
556+
},
557+
"project_id": "<project_id>",
558+
"root_span_id": "<span:2>",
559+
"span_id": "<span:23>",
560+
"span_parents": [
561+
"<span:21>"
562+
]
563+
},
564+
{
565+
"_is_merge": true,
566+
"id": "<span:22>",
567+
"log_id": "g",
568+
"metadata": {
569+
"finish_reason": "length"
570+
},
571+
"output": {
572+
"finish_reason": "length",
573+
"generated_text": "<string>"
574+
},
575+
"project_id": "<project_id>",
576+
"root_span_id": "<span:2>",
577+
"span_id": "<span:23>",
578+
"span_parents": [
579+
"<span:21>"
580+
]
581+
},
582+
{
583+
"_is_merge": true,
584+
"id": "<span:22>",
585+
"log_id": "g",
586+
"metrics": {
587+
"end": "<timestamp>"
588+
},
589+
"project_id": "<project_id>",
590+
"root_span_id": "<span:2>",
591+
"span_id": "<span:23>",
592+
"span_parents": [
593+
"<span:21>"
594+
]
595+
},
596+
{
597+
"_is_merge": false,
598+
"context": {
599+
"caller_filename": "<repo>/e2e/helpers/provider-runtime.mjs",
600+
"caller_functionname": "runOperation",
601+
"caller_lineno": 0
602+
},
603+
"created": "<timestamp>",
604+
"id": "<span:24>",
605+
"log_id": "g",
606+
"metadata": {
607+
"operation": "feature-extraction",
608+
"testRunId": "<run:1>"
609+
},
610+
"metrics": {
611+
"start": "<timestamp>"
612+
},
613+
"project_id": "<project_id>",
614+
"root_span_id": "<span:2>",
615+
"span_attributes": {
616+
"exec_counter": 9,
449617
"name": "huggingface-feature-extraction-operation"
450618
},
451-
"span_id": "<span:19>",
619+
"span_id": "<span:25>",
452620
"span_parents": [
453621
"<span:2>"
454622
]
455623
},
456624
{
457625
"_is_merge": true,
458-
"id": "<span:18>",
626+
"id": "<span:24>",
459627
"log_id": "g",
460628
"metrics": {
461629
"end": "<timestamp>"
462630
},
463631
"project_id": "<project_id>",
464632
"root_span_id": "<span:2>",
465-
"span_id": "<span:19>",
633+
"span_id": "<span:25>",
466634
"span_parents": [
467635
"<span:2>"
468636
]
469637
},
470638
{
471639
"context": {},
472640
"created": "<timestamp>",
473-
"id": "<span:20>",
641+
"id": "<span:26>",
474642
"input": "Paris France",
475643
"log_id": "g",
476644
"metadata": {
@@ -484,42 +652,42 @@
484652
"project_id": "<project_id>",
485653
"root_span_id": "<span:2>",
486654
"span_attributes": {
487-
"exec_counter": 8,
655+
"exec_counter": 10,
488656
"name": "huggingface.feature_extraction",
489657
"type": "llm"
490658
},
491-
"span_id": "<span:21>",
659+
"span_id": "<span:27>",
492660
"span_parents": [
493-
"<span:19>"
661+
"<span:25>"
494662
]
495663
},
496664
{
497665
"_is_merge": true,
498-
"id": "<span:20>",
666+
"id": "<span:26>",
499667
"log_id": "g",
500668
"metrics": {},
501669
"output": {
502670
"embedding_length": 1024
503671
},
504672
"project_id": "<project_id>",
505673
"root_span_id": "<span:2>",
506-
"span_id": "<span:21>",
674+
"span_id": "<span:27>",
507675
"span_parents": [
508-
"<span:19>"
676+
"<span:25>"
509677
]
510678
},
511679
{
512680
"_is_merge": true,
513-
"id": "<span:20>",
681+
"id": "<span:26>",
514682
"log_id": "g",
515683
"metrics": {
516684
"end": "<timestamp>"
517685
},
518686
"project_id": "<project_id>",
519687
"root_span_id": "<span:2>",
520-
"span_id": "<span:21>",
688+
"span_id": "<span:27>",
521689
"span_parents": [
522-
"<span:19>"
690+
"<span:25>"
523691
]
524692
}
525693
]

0 commit comments

Comments
 (0)