
    jw                     F   d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZ dej"                  dee   d	ed
ee
   dededeej*                     fdZdej"                  d	ee   d
ee
   dededeej.                     fdZdeg ee   f   dedededee   f
dZy)    )OptionalListCallableAny)synchronization)rest_stream_parser)OptionalFilterParsedItemList)client)span_publictrace_publicrest_clienttrace_idproject_namefiltersmax_resultstruncatereturnc                 j     t        j                   fd|t        j                        }|S )Nc                 F    j                   j                  | |      S )N)r   r   r   limitr   last_retrieved_id)spanssearch_spans)current_batch_sizer   r   r   r   r   r   s     x/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/api_objects/search_helpers.py<lambda>z+search_spans_with_filters.<locals>.<lambda>   s.    &,,99%$/ : 
    read_sourcer   parsed_item_class)r   read_and_parse_full_streamr   
SpanPublic)r   r   r   r   r   r   r   s   ```` ` r   search_spans_with_filtersr#   
   s/     99
  %00E Lr   c                 f     t        j                   fd|t        j                        }|S )Nc                 D    j                   j                  | |      S )N)r   r   r   r   r   )tracessearch_traces)r   r   r   r   r   r   s     r   r   z,search_traces_with_filters.<locals>.<lambda>+   s+    &--;;%$/ < 
r   r   )r   r!   r   TracePublic)r   r   r   r   r   r&   s   ``` ` r   search_traces_with_filtersr)   #   s/      ::
  &22F Mr   search_functorwait_for_at_leastwait_for_timeout
sleep_timec                 r     g dt         t           f fdt        j                  fd||       S )a  
    The expected behavior is to keep making repeated calls until either the specified number of
    results is found or the timeout is reached. The function will then return the best possible
    attempt results to meet these conditions.
    Args:
        search_functor: The function to call to retrieve the results.
        wait_for_at_least: The minimum number of results to return.
        wait_for_timeout: The timeout for waiting for results.
        sleep_time: The time to sleep between calls to search_functor.

    Returns:
        The function returns the results of the best possible attempt to meet both waiting conditions.
    r   c                                S N )resultr*   s   r   searchz(search_and_wait_for_done.<locals>.searchN   s    !r   c                  *    t                       k\  S r0   )len)r3   r+   s   r   r   z*search_and_wait_for_done.<locals>.<lambda>T   s    s68}0AAr   )check_functiontimeoutr-   )r   r   r   wait_for_done)r*   r+   r,   r-   r2   r3   s   ``  @@r   search_and_wait_for_doner9   9   s:    & FDI 
 !!A  Mr   N)typingr   r   r   r   opikr   opik.api_objectsr   opik.api_objects.helpersr	   opik.rest_apir
   rest_api_clientopik.rest_api.typesr   r   OpikApistrintboolr"   r#   r(   r)   floatr9   r1   r   r   <module>rF      s   0 0   / A 3 9 ((sm  23	
   
+
 
 !2 ((3- 23 	
  
,
"
"#, Rc]+     	 
 
#Y r   