lucidicai 2.1.3__py3-none-any.whl → 3.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lucidicai/__init__.py +32 -390
- lucidicai/api/client.py +31 -2
- lucidicai/api/resources/__init__.py +16 -1
- lucidicai/api/resources/dataset.py +422 -82
- lucidicai/api/resources/evals.py +209 -0
- lucidicai/api/resources/event.py +399 -27
- lucidicai/api/resources/experiment.py +108 -0
- lucidicai/api/resources/feature_flag.py +78 -0
- lucidicai/api/resources/prompt.py +84 -0
- lucidicai/api/resources/session.py +545 -38
- lucidicai/client.py +408 -480
- lucidicai/core/config.py +73 -48
- lucidicai/core/errors.py +3 -3
- lucidicai/sdk/bound_decorators.py +321 -0
- lucidicai/sdk/context.py +20 -2
- lucidicai/sdk/decorators.py +283 -74
- lucidicai/sdk/event.py +538 -36
- lucidicai/sdk/event_builder.py +2 -4
- lucidicai/sdk/features/dataset.py +391 -1
- lucidicai/sdk/features/feature_flag.py +344 -3
- lucidicai/sdk/init.py +49 -347
- lucidicai/sdk/session.py +502 -0
- lucidicai/sdk/shutdown_manager.py +103 -46
- lucidicai/session_obj.py +321 -0
- lucidicai/telemetry/context_capture_processor.py +13 -6
- lucidicai/telemetry/extract.py +60 -63
- lucidicai/telemetry/litellm_bridge.py +3 -44
- lucidicai/telemetry/lucidic_exporter.py +143 -131
- lucidicai/telemetry/openai_agents_instrumentor.py +2 -2
- lucidicai/telemetry/openai_patch.py +7 -6
- lucidicai/telemetry/telemetry_manager.py +183 -0
- lucidicai/telemetry/utils/model_pricing.py +21 -30
- lucidicai/telemetry/utils/provider.py +77 -0
- lucidicai/utils/images.py +27 -11
- lucidicai/utils/serialization.py +27 -0
- {lucidicai-2.1.3.dist-info → lucidicai-3.1.0.dist-info}/METADATA +1 -1
- {lucidicai-2.1.3.dist-info → lucidicai-3.1.0.dist-info}/RECORD +39 -29
- {lucidicai-2.1.3.dist-info → lucidicai-3.1.0.dist-info}/WHEEL +0 -0
- {lucidicai-2.1.3.dist-info → lucidicai-3.1.0.dist-info}/top_level.txt +0 -0
|
@@ -388,4 +388,394 @@ def list_dataset_item_sessions(
|
|
|
388
388
|
from ..init import ensure_http_and_resources
|
|
389
389
|
|
|
390
390
|
resources = ensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
391
|
-
return resources['datasets'].list_item_sessions(dataset_id, item_id)
|
|
391
|
+
return resources['datasets'].list_item_sessions(dataset_id, item_id)
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
# ==================== Asynchronous Functions ====================
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
async def aget_dataset(
|
|
398
|
+
dataset_id: str,
|
|
399
|
+
api_key: Optional[str] = None,
|
|
400
|
+
agent_id: Optional[str] = None,
|
|
401
|
+
) -> Dict[str, Any]:
|
|
402
|
+
"""
|
|
403
|
+
Get a dataset by ID with all its items (asynchronous).
|
|
404
|
+
|
|
405
|
+
Args:
|
|
406
|
+
dataset_id: The ID of the dataset to retrieve (required).
|
|
407
|
+
api_key: API key for authentication. If not provided, will use the LUCIDIC_API_KEY environment variable.
|
|
408
|
+
agent_id: Agent ID. If not provided, will use the LUCIDIC_AGENT_ID environment variable.
|
|
409
|
+
|
|
410
|
+
Returns:
|
|
411
|
+
A dictionary containing the dataset information including:
|
|
412
|
+
- dataset_id: The dataset ID
|
|
413
|
+
- name: Dataset name
|
|
414
|
+
- description: Dataset description
|
|
415
|
+
- tags: List of tags
|
|
416
|
+
- created_at: Creation timestamp
|
|
417
|
+
- updated_at: Last update timestamp
|
|
418
|
+
- num_items: Number of items in the dataset
|
|
419
|
+
- items: List of dataset items
|
|
420
|
+
|
|
421
|
+
Raises:
|
|
422
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
423
|
+
ValueError: If dataset_id is not provided.
|
|
424
|
+
"""
|
|
425
|
+
# Validation
|
|
426
|
+
if not dataset_id:
|
|
427
|
+
raise ValueError("Dataset ID is required")
|
|
428
|
+
|
|
429
|
+
from ..init import aensure_http_and_resources, get_http
|
|
430
|
+
|
|
431
|
+
# Ensure HTTP client is initialized and stored in SDK state
|
|
432
|
+
await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
433
|
+
http = get_http()
|
|
434
|
+
|
|
435
|
+
# Make request to get dataset
|
|
436
|
+
response = await http.aget('getdataset', {'dataset_id': dataset_id})
|
|
437
|
+
|
|
438
|
+
logger.info(f"Retrieved dataset {dataset_id} with {response.get('num_items', 0)} items")
|
|
439
|
+
return response
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
async def aget_dataset_items(
|
|
443
|
+
dataset_id: str,
|
|
444
|
+
api_key: Optional[str] = None,
|
|
445
|
+
agent_id: Optional[str] = None,
|
|
446
|
+
) -> List[Dict[str, Any]]:
|
|
447
|
+
"""
|
|
448
|
+
Convenience function to get just the items from a dataset (asynchronous).
|
|
449
|
+
|
|
450
|
+
Args:
|
|
451
|
+
dataset_id: The ID of the dataset to retrieve items from (required).
|
|
452
|
+
api_key: API key for authentication. If not provided, will use the LUCIDIC_API_KEY environment variable.
|
|
453
|
+
agent_id: Agent ID. If not provided, will use the LUCIDIC_AGENT_ID environment variable.
|
|
454
|
+
|
|
455
|
+
Returns:
|
|
456
|
+
A list of dataset items, where each item contains:
|
|
457
|
+
- datasetitem_id: The item ID
|
|
458
|
+
- name: Item name
|
|
459
|
+
- description: Item description
|
|
460
|
+
- tags: List of tags
|
|
461
|
+
- input: Input data for the item
|
|
462
|
+
- expected_output: Expected output data
|
|
463
|
+
- metadata: Additional metadata
|
|
464
|
+
- created_at: Creation timestamp
|
|
465
|
+
|
|
466
|
+
Raises:
|
|
467
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
468
|
+
ValueError: If dataset_id is not provided.
|
|
469
|
+
"""
|
|
470
|
+
dataset = await aget_dataset(dataset_id, api_key, agent_id)
|
|
471
|
+
return dataset.get('items', [])
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
async def alist_datasets(
|
|
475
|
+
api_key: Optional[str] = None,
|
|
476
|
+
agent_id: Optional[str] = None,
|
|
477
|
+
) -> Dict[str, Any]:
|
|
478
|
+
"""
|
|
479
|
+
List all datasets for the agent (asynchronous).
|
|
480
|
+
|
|
481
|
+
Args:
|
|
482
|
+
api_key: API key for authentication. If not provided, will use the LUCIDIC_API_KEY environment variable.
|
|
483
|
+
agent_id: Agent ID. If not provided, will use the LUCIDIC_AGENT_ID environment variable.
|
|
484
|
+
|
|
485
|
+
Returns:
|
|
486
|
+
A dictionary containing:
|
|
487
|
+
- num_datasets: Number of datasets
|
|
488
|
+
- datasets: List of dataset summaries with dataset_id and name
|
|
489
|
+
|
|
490
|
+
Raises:
|
|
491
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
492
|
+
"""
|
|
493
|
+
from ..init import aensure_http_and_resources
|
|
494
|
+
|
|
495
|
+
resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
496
|
+
return await resources['datasets'].alist_datasets(agent_id)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
async def acreate_dataset(
|
|
500
|
+
name: str,
|
|
501
|
+
description: Optional[str] = None,
|
|
502
|
+
tags: Optional[List[str]] = None,
|
|
503
|
+
suggested_flag_config: Optional[Dict[str, Any]] = None,
|
|
504
|
+
api_key: Optional[str] = None,
|
|
505
|
+
agent_id: Optional[str] = None,
|
|
506
|
+
) -> Dict[str, Any]:
|
|
507
|
+
"""
|
|
508
|
+
Create a new dataset (asynchronous).
|
|
509
|
+
|
|
510
|
+
Args:
|
|
511
|
+
name: Dataset name (must be unique per agent)
|
|
512
|
+
description: Optional dataset description
|
|
513
|
+
tags: Optional list of tags
|
|
514
|
+
suggested_flag_config: Optional flag configuration
|
|
515
|
+
api_key: API key for authentication
|
|
516
|
+
agent_id: Agent ID
|
|
517
|
+
|
|
518
|
+
Returns:
|
|
519
|
+
A dictionary containing dataset_id
|
|
520
|
+
|
|
521
|
+
Raises:
|
|
522
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
523
|
+
"""
|
|
524
|
+
from ..init import aensure_http_and_resources
|
|
525
|
+
|
|
526
|
+
resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
527
|
+
return await resources['datasets'].acreate_dataset(name, description, tags, suggested_flag_config, agent_id)
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
async def aupdate_dataset(
|
|
531
|
+
dataset_id: str,
|
|
532
|
+
name: Optional[str] = None,
|
|
533
|
+
description: Optional[str] = None,
|
|
534
|
+
tags: Optional[List[str]] = None,
|
|
535
|
+
suggested_flag_config: Optional[Dict[str, Any]] = None,
|
|
536
|
+
api_key: Optional[str] = None,
|
|
537
|
+
agent_id: Optional[str] = None,
|
|
538
|
+
) -> Dict[str, Any]:
|
|
539
|
+
"""
|
|
540
|
+
Update dataset metadata (asynchronous).
|
|
541
|
+
|
|
542
|
+
Args:
|
|
543
|
+
dataset_id: Dataset UUID to update
|
|
544
|
+
name: New name (optional)
|
|
545
|
+
description: New description (optional)
|
|
546
|
+
tags: New tags (optional)
|
|
547
|
+
suggested_flag_config: New flag config (optional)
|
|
548
|
+
api_key: API key for authentication
|
|
549
|
+
agent_id: Agent ID
|
|
550
|
+
|
|
551
|
+
Returns:
|
|
552
|
+
Updated dataset data
|
|
553
|
+
|
|
554
|
+
Raises:
|
|
555
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
556
|
+
"""
|
|
557
|
+
from ..init import aensure_http_and_resources
|
|
558
|
+
|
|
559
|
+
resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
560
|
+
|
|
561
|
+
kwargs = {}
|
|
562
|
+
if name is not None:
|
|
563
|
+
kwargs['name'] = name
|
|
564
|
+
if description is not None:
|
|
565
|
+
kwargs['description'] = description
|
|
566
|
+
if tags is not None:
|
|
567
|
+
kwargs['tags'] = tags
|
|
568
|
+
if suggested_flag_config is not None:
|
|
569
|
+
kwargs['suggested_flag_config'] = suggested_flag_config
|
|
570
|
+
|
|
571
|
+
return await resources['datasets'].aupdate_dataset(dataset_id, **kwargs)
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
async def adelete_dataset(
|
|
575
|
+
dataset_id: str,
|
|
576
|
+
api_key: Optional[str] = None,
|
|
577
|
+
agent_id: Optional[str] = None,
|
|
578
|
+
) -> Dict[str, Any]:
|
|
579
|
+
"""
|
|
580
|
+
Delete a dataset and all its items (asynchronous).
|
|
581
|
+
|
|
582
|
+
Args:
|
|
583
|
+
dataset_id: Dataset UUID to delete
|
|
584
|
+
api_key: API key for authentication
|
|
585
|
+
agent_id: Agent ID
|
|
586
|
+
|
|
587
|
+
Returns:
|
|
588
|
+
Success message
|
|
589
|
+
|
|
590
|
+
Raises:
|
|
591
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
592
|
+
"""
|
|
593
|
+
from ..init import aensure_http_and_resources
|
|
594
|
+
|
|
595
|
+
resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
596
|
+
return await resources['datasets'].adelete_dataset(dataset_id)
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
async def acreate_dataset_item(
|
|
600
|
+
dataset_id: str,
|
|
601
|
+
name: str,
|
|
602
|
+
input_data: Dict[str, Any],
|
|
603
|
+
expected_output: Optional[Dict[str, Any]] = None,
|
|
604
|
+
description: Optional[str] = None,
|
|
605
|
+
tags: Optional[List[str]] = None,
|
|
606
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
607
|
+
flag_overrides: Optional[Dict[str, Any]] = None,
|
|
608
|
+
api_key: Optional[str] = None,
|
|
609
|
+
agent_id: Optional[str] = None,
|
|
610
|
+
) -> Dict[str, Any]:
|
|
611
|
+
"""
|
|
612
|
+
Create a new dataset item (asynchronous).
|
|
613
|
+
|
|
614
|
+
Args:
|
|
615
|
+
dataset_id: Dataset UUID to add item to
|
|
616
|
+
name: Item name
|
|
617
|
+
input_data: Input data dictionary
|
|
618
|
+
expected_output: Expected output (optional)
|
|
619
|
+
description: Item description (optional)
|
|
620
|
+
tags: Item tags (optional)
|
|
621
|
+
metadata: Additional metadata (optional)
|
|
622
|
+
flag_overrides: Flag overrides (optional)
|
|
623
|
+
api_key: API key for authentication
|
|
624
|
+
agent_id: Agent ID
|
|
625
|
+
|
|
626
|
+
Returns:
|
|
627
|
+
Dictionary with datasetitem_id
|
|
628
|
+
|
|
629
|
+
Raises:
|
|
630
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
631
|
+
"""
|
|
632
|
+
from ..init import aensure_http_and_resources
|
|
633
|
+
|
|
634
|
+
resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
635
|
+
return await resources['datasets'].acreate_item(
|
|
636
|
+
dataset_id, name, input_data,
|
|
637
|
+
expected_output=expected_output,
|
|
638
|
+
description=description,
|
|
639
|
+
tags=tags,
|
|
640
|
+
metadata=metadata,
|
|
641
|
+
flag_overrides=flag_overrides
|
|
642
|
+
)
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
async def aget_dataset_item(
|
|
646
|
+
dataset_id: str,
|
|
647
|
+
item_id: str,
|
|
648
|
+
api_key: Optional[str] = None,
|
|
649
|
+
agent_id: Optional[str] = None,
|
|
650
|
+
) -> Dict[str, Any]:
|
|
651
|
+
"""
|
|
652
|
+
Get a specific dataset item (asynchronous).
|
|
653
|
+
|
|
654
|
+
Args:
|
|
655
|
+
dataset_id: Dataset UUID
|
|
656
|
+
item_id: Item UUID
|
|
657
|
+
api_key: API key for authentication
|
|
658
|
+
agent_id: Agent ID
|
|
659
|
+
|
|
660
|
+
Returns:
|
|
661
|
+
Dataset item data
|
|
662
|
+
|
|
663
|
+
Raises:
|
|
664
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
665
|
+
"""
|
|
666
|
+
from ..init import aensure_http_and_resources
|
|
667
|
+
|
|
668
|
+
resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
669
|
+
return await resources['datasets'].aget_item(dataset_id, item_id)
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
async def aupdate_dataset_item(
|
|
673
|
+
dataset_id: str,
|
|
674
|
+
item_id: str,
|
|
675
|
+
name: Optional[str] = None,
|
|
676
|
+
input_data: Optional[Dict[str, Any]] = None,
|
|
677
|
+
expected_output: Optional[Dict[str, Any]] = None,
|
|
678
|
+
description: Optional[str] = None,
|
|
679
|
+
tags: Optional[List[str]] = None,
|
|
680
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
681
|
+
flag_overrides: Optional[Dict[str, Any]] = None,
|
|
682
|
+
api_key: Optional[str] = None,
|
|
683
|
+
agent_id: Optional[str] = None,
|
|
684
|
+
) -> Dict[str, Any]:
|
|
685
|
+
"""
|
|
686
|
+
Update a dataset item (asynchronous).
|
|
687
|
+
|
|
688
|
+
Args:
|
|
689
|
+
dataset_id: Dataset UUID
|
|
690
|
+
item_id: Item UUID
|
|
691
|
+
name: New name (optional)
|
|
692
|
+
input_data: New input data (optional)
|
|
693
|
+
expected_output: New expected output (optional)
|
|
694
|
+
description: New description (optional)
|
|
695
|
+
tags: New tags (optional)
|
|
696
|
+
metadata: New metadata (optional)
|
|
697
|
+
flag_overrides: New flag overrides (optional)
|
|
698
|
+
api_key: API key for authentication
|
|
699
|
+
agent_id: Agent ID
|
|
700
|
+
|
|
701
|
+
Returns:
|
|
702
|
+
Updated item data
|
|
703
|
+
|
|
704
|
+
Raises:
|
|
705
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
706
|
+
"""
|
|
707
|
+
from ..init import aensure_http_and_resources
|
|
708
|
+
|
|
709
|
+
resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
710
|
+
|
|
711
|
+
kwargs = {}
|
|
712
|
+
if name is not None:
|
|
713
|
+
kwargs['name'] = name
|
|
714
|
+
if input_data is not None:
|
|
715
|
+
kwargs['input'] = input_data
|
|
716
|
+
if expected_output is not None:
|
|
717
|
+
kwargs['expected_output'] = expected_output
|
|
718
|
+
if description is not None:
|
|
719
|
+
kwargs['description'] = description
|
|
720
|
+
if tags is not None:
|
|
721
|
+
kwargs['tags'] = tags
|
|
722
|
+
if metadata is not None:
|
|
723
|
+
kwargs['metadata'] = metadata
|
|
724
|
+
if flag_overrides is not None:
|
|
725
|
+
kwargs['flag_overrides'] = flag_overrides
|
|
726
|
+
|
|
727
|
+
return await resources['datasets'].aupdate_item(dataset_id, item_id, **kwargs)
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
async def adelete_dataset_item(
|
|
731
|
+
dataset_id: str,
|
|
732
|
+
item_id: str,
|
|
733
|
+
api_key: Optional[str] = None,
|
|
734
|
+
agent_id: Optional[str] = None,
|
|
735
|
+
) -> Dict[str, Any]:
|
|
736
|
+
"""
|
|
737
|
+
Delete a dataset item (asynchronous).
|
|
738
|
+
|
|
739
|
+
Args:
|
|
740
|
+
dataset_id: Dataset UUID
|
|
741
|
+
item_id: Item UUID
|
|
742
|
+
api_key: API key for authentication
|
|
743
|
+
agent_id: Agent ID
|
|
744
|
+
|
|
745
|
+
Returns:
|
|
746
|
+
Success message
|
|
747
|
+
|
|
748
|
+
Raises:
|
|
749
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
750
|
+
"""
|
|
751
|
+
from ..init import aensure_http_and_resources
|
|
752
|
+
|
|
753
|
+
resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
754
|
+
return await resources['datasets'].adelete_item(dataset_id, item_id)
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
async def alist_dataset_item_sessions(
|
|
758
|
+
dataset_id: str,
|
|
759
|
+
item_id: str,
|
|
760
|
+
api_key: Optional[str] = None,
|
|
761
|
+
agent_id: Optional[str] = None,
|
|
762
|
+
) -> Dict[str, Any]:
|
|
763
|
+
"""
|
|
764
|
+
List all sessions for a dataset item (asynchronous).
|
|
765
|
+
|
|
766
|
+
Args:
|
|
767
|
+
dataset_id: Dataset UUID
|
|
768
|
+
item_id: Item UUID
|
|
769
|
+
api_key: API key for authentication
|
|
770
|
+
agent_id: Agent ID
|
|
771
|
+
|
|
772
|
+
Returns:
|
|
773
|
+
Dictionary with num_sessions and sessions list
|
|
774
|
+
|
|
775
|
+
Raises:
|
|
776
|
+
APIKeyVerificationError: If API key or agent ID is missing or invalid.
|
|
777
|
+
"""
|
|
778
|
+
from ..init import aensure_http_and_resources
|
|
779
|
+
|
|
780
|
+
resources = await aensure_http_and_resources(api_key=api_key, agent_id=agent_id)
|
|
781
|
+
return await resources['datasets'].alist_item_sessions(dataset_id, item_id)
|