1414from parea .cache .cache import Cache
1515from parea .constants import PAREA_OS_ENV_EXPERIMENT_UUID
1616from parea .experiment .datasets import create_test_cases , create_test_collection
17- from parea .helpers import gen_trace_id , serialize_metadata_values , structure_trace_log_from_api
17+ from parea .helpers import gen_trace_id , serialize_metadata_values , structure_trace_log_from_api , structure_trace_logs_from_api
1818from parea .parea_logger import parea_logger
1919from parea .schemas .models import (
2020 Completion ,
2525 CreateTestCases ,
2626 ExperimentSchema ,
2727 ExperimentStatsSchema ,
28+ ExperimentWithPinnedStatsSchema ,
2829 FeedbackRequest ,
2930 FinishExperimentRequestSchema ,
31+ ListExperimentUUIDsFilters ,
3032 ProjectSchema ,
3133 TestCaseCollection ,
3234 TraceLog ,
35+ TraceLogFilters ,
3336 UseDeployedPrompt ,
3437 UseDeployedPromptResponse ,
3538)
5053CREATE_COLLECTION_ENDPOINT = "/collection"
5154ADD_TEST_CASES_ENDPOINT = "/testcases"
5255GET_TRACE_LOG_ENDPOINT = "/trace_log/{trace_id}"
56+ LIST_EXPERIMENTS_ENDPOINT = "/experiments"
57+ GET_EXPERIMENT_LOGS_ENDPOINT = "/experiment/{experiment_uuid}/trace_logs"
5358
5459
5560@define
@@ -71,19 +76,25 @@ def __attrs_post_init__(self):
7176 parea_logger .set_client (self ._client )
7277 parea_logger .set_project_uuid (self .project_uuid )
7378
74- def wrap_openai_client (self , client : "OpenAI" ) -> None :
79+ def wrap_openai_client (self , client : "OpenAI" , integration : Optional [ str ] = None ) -> None :
7580 """Only necessary for instance client with OpenAI version >= 1.0.0"""
7681 from parea .wrapper import OpenAIWrapper
7782 from parea .wrapper .openai_beta_wrapper import BetaWrappers
7883
7984 OpenAIWrapper ().init (log = logger_all_possible , cache = self .cache , module_client = client )
8085 BetaWrappers (client ).init ()
8186
82- def wrap_anthropic_client (self , client : "Anthropic" ) -> None :
87+ if integration :
88+ self ._client .add_integration (integration )
89+
90+ def wrap_anthropic_client (self , client : "Anthropic" , integration : Optional [str ] = None ) -> None :
8391 from parea .wrapper .anthropic .anthropic import AnthropicWrapper
8492
8593 AnthropicWrapper ().init (log = logger_all_possible , cache = self .cache , client = client )
8694
95+ if integration :
96+ self ._client .add_integration (integration )
97+
8798 def auto_trace_openai_clients (self ) -> None :
8899 import openai
89100
@@ -92,6 +103,10 @@ def auto_trace_openai_clients(self) -> None:
92103 openai .AzureOpenAI = patch_openai_client_classes (openai .AzureOpenAI , self )
93104 openai .AsyncAzureOpenAI = patch_openai_client_classes (openai .AsyncAzureOpenAI , self )
94105
106+ def integrate_with_sglang (self ):
107+ self .auto_trace_openai_clients ()
108+ self ._client .add_integration ("sglang" )
109+
95110 def _add_project_uuid_to_data (self , data ) -> dict :
96111 data_dict = asdict (data )
97112 data_dict ["project_uuid" ] = self ._project .uuid
@@ -346,6 +361,22 @@ async def aget_trace_log(self, trace_id: str) -> TraceLog:
346361 response = await self ._client .request_async ("GET" , GET_TRACE_LOG_ENDPOINT .format (trace_id = trace_id ))
347362 return structure_trace_log_from_api (response .json ())
348363
364+ def list_experiments (self , filter_conditions : Optional [ListExperimentUUIDsFilters ] = ListExperimentUUIDsFilters ()) -> List [ExperimentWithPinnedStatsSchema ]:
365+ response = self ._client .request ("POST" , LIST_EXPERIMENTS_ENDPOINT , data = asdict (filter_conditions ))
366+ return structure (response .json (), List [ExperimentWithPinnedStatsSchema ])
367+
368+ async def alist_experiments (self , filter_conditions : Optional [ListExperimentUUIDsFilters ] = ListExperimentUUIDsFilters ()) -> List [ExperimentWithPinnedStatsSchema ]:
369+ response = await self ._client .request_async ("POST" , LIST_EXPERIMENTS_ENDPOINT , data = asdict (filter_conditions ))
370+ return structure (response .json (), List [ExperimentWithPinnedStatsSchema ])
371+
372+ def get_experiment_trace_logs (self , experiment_uuid : str , filters : TraceLogFilters = TraceLogFilters ()) -> List [TraceLog ]:
373+ response = self ._client .request ("POST" , GET_EXPERIMENT_LOGS_ENDPOINT .format (experiment_uuid = experiment_uuid ), data = asdict (filters ))
374+ return structure_trace_logs_from_api (response .json ())
375+
376+ async def aget_experiment_trace_logs (self , experiment_uuid : str , filters : TraceLogFilters = TraceLogFilters ()) -> List [TraceLog ]:
377+ response = await self ._client .request_async ("POST" , GET_EXPERIMENT_LOGS_ENDPOINT .format (experiment_uuid = experiment_uuid ), data = asdict (filters ))
378+ return structure_trace_logs_from_api (response .json ())
379+
349380
350381_initialized_parea_wrapper = False
351382
0 commit comments