
     j Z                         d dl Zd dlZddlmZ ddlmZmZ ddlm	Z	 ddl
mZmZ ddlmZ  G d	 d
          Z G d d          ZdS )    N   )ObservationLevel)AsyncClientWrapperSyncClientWrapper)RequestOptions   )AsyncRawObservationsClientRawObservationsClient)ObservationsV2Responsec            %       f   e Zd ZdefdZedefd            Zdddddddddddddddddddej	        e
         dej	        e
         d	ej	        e         d
ej	        e
         dej	        e         dej	        e
         dej	        e
         dej	        e
         dej	        e
         dej	        e         dej	        e
         dej	        ej        e
ej        e
         f                  dej	        ej                 dej	        ej                 dej	        e
         dej	        e
         dej	        e         def$dZdS )ObservationsClientclient_wrapperc                0    t          |          | _        d S N)r   )r
   _raw_clientselfr   s     j/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/langfuse/api/observations/client.py__init__zObservationsClient.__init__   s    0OOO    returnc                     | j         S )z
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawObservationsClient
        r   r   s    r   with_raw_responsez$ObservationsClient.with_raw_response        r   Nfieldsexpand_metadatalimitcursorparse_io_as_jsonnameuser_idtypetrace_idlevelparent_observation_idenvironmentfrom_start_timeto_start_timeversionfilterrequest_optionsr   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   c                f    | j                             |||||||||	|
|||||||          }|j        S )a#  
        Get a list of observations with cursor-based pagination and flexible field selection.

        ## Cursor-based Pagination
        This endpoint uses cursor-based pagination for efficient traversal of large datasets.
        The cursor is returned in the response metadata and should be passed in subsequent requests
        to retrieve the next page of results.

        ## Field Selection
        Use the `fields` parameter to control which observation fields are returned:
        - `core` - Always included: id, traceId, startTime, endTime, projectId, parentObservationId, type
        - `basic` - name, level, statusMessage, version, environment, bookmarked, public, userId, sessionId
        - `time` - completionStartTime, createdAt, updatedAt
        - `io` - input, output
        - `metadata` - metadata (truncated to 200 chars by default, use `expandMetadata` to get full values)
        - `model` - providedModelName, internalModelId, modelParameters
        - `usage` - usageDetails, costDetails, totalCost
        - `prompt` - promptId, promptName, promptVersion
        - `metrics` - latency, timeToFirstToken

        If not specified, `core` and `basic` field groups are returned.

        ## Filters
        Multiple filtering options are available via query parameters or the structured `filter` parameter.
        When using the `filter` parameter, it takes precedence over individual query parameter filters.

        Parameters
        ----------
        fields : typing.Optional[str]
            Comma-separated list of field groups to include in the response.
            Available groups: core, basic, time, io, metadata, model, usage, prompt, metrics.
            If not specified, `core` and `basic` field groups are returned.
            Example: "basic,usage,model"

        expand_metadata : typing.Optional[str]
            Comma-separated list of metadata keys to return non-truncated.
            By default, metadata values over 200 characters are truncated.
            Use this parameter to retrieve full values for specific keys.
            Example: "key1,key2"

        limit : typing.Optional[int]
            Number of items to return per page. Maximum 1000, default 50.

        cursor : typing.Optional[str]
            Base64-encoded cursor for pagination. Use the cursor from the previous response to get the next page.

        parse_io_as_json : typing.Optional[bool]
            **Deprecated.** Setting this to `true` will return a 400 error.
            Input/output fields are always returned as raw strings.
            Remove this parameter or set it to `false`.

        name : typing.Optional[str]

        user_id : typing.Optional[str]

        type : typing.Optional[str]
            Filter by observation type (e.g., "GENERATION", "SPAN", "EVENT", "AGENT", "TOOL", "CHAIN", "RETRIEVER", "EVALUATOR", "EMBEDDING", "GUARDRAIL")

        trace_id : typing.Optional[str]

        level : typing.Optional[ObservationLevel]
            Optional filter for observations with a specific level (e.g. "DEBUG", "DEFAULT", "WARNING", "ERROR").

        parent_observation_id : typing.Optional[str]

        environment : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional filter for observations where the environment is one of the provided values.

        from_start_time : typing.Optional[dt.datetime]
            Retrieve only observations with a start_time on or after this datetime (ISO 8601).

        to_start_time : typing.Optional[dt.datetime]
            Retrieve only observations with a start_time before this datetime (ISO 8601).

        version : typing.Optional[str]
            Optional filter to only include observations with a certain version.

        filter : typing.Optional[str]
            JSON string containing an array of filter conditions. When provided, this takes precedence over query parameter filters (userId, name, type, level, environment, fromStartTime, ...).

            ## Filter Structure
            Each filter condition has the following structure:
            ```json
            [
              {
                "type": string,           // Required. One of: "datetime", "string", "number", "stringOptions", "categoryOptions", "arrayOptions", "stringObject", "numberObject", "boolean", "null"
                "column": string,         // Required. Column to filter on (see available columns below)
                "operator": string,       // Required. Operator based on type:
                                          // - datetime: ">", "<", ">=", "<="
                                          // - string: "=", "contains", "does not contain", "starts with", "ends with"
                                          // - stringOptions: "any of", "none of"
                                          // - categoryOptions: "any of", "none of"
                                          // - arrayOptions: "any of", "none of", "all of"
                                          // - number: "=", ">", "<", ">=", "<="
                                          // - stringObject: "=", "contains", "does not contain", "starts with", "ends with"
                                          // - numberObject: "=", ">", "<", ">=", "<="
                                          // - boolean: "=", "<>"
                                          // - null: "is null", "is not null"
                "value": any,             // Required (except for null type). Value to compare against. Type depends on filter type
                "key": string             // Required only for stringObject, numberObject, and categoryOptions types when filtering on nested fields like metadata
              }
            ]
            ```

            ## Available Columns

            ### Core Observation Fields
            - `id` (string) - Observation ID
            - `type` (string) - Observation type (SPAN, GENERATION, EVENT)
            - `name` (string) - Observation name
            - `traceId` (string) - Associated trace ID
            - `startTime` (datetime) - Observation start time
            - `endTime` (datetime) - Observation end time
            - `environment` (string) - Environment tag
            - `level` (string) - Log level (DEBUG, DEFAULT, WARNING, ERROR)
            - `statusMessage` (string) - Status message
            - `version` (string) - Version tag
            - `userId` (string) - User ID
            - `sessionId` (string) - Session ID

            ### Trace-Related Fields
            - `traceName` (string) - Name of the parent trace
            - `traceTags` (arrayOptions) - Tags from the parent trace
            - `tags` (arrayOptions) - Alias for traceTags

            ### Performance Metrics
            - `latency` (number) - Latency in seconds (calculated: end_time - start_time)
            - `timeToFirstToken` (number) - Time to first token in seconds
            - `tokensPerSecond` (number) - Output tokens per second

            ### Token Usage
            - `inputTokens` (number) - Number of input tokens
            - `outputTokens` (number) - Number of output tokens
            - `totalTokens` (number) - Total tokens (alias: `tokens`)

            ### Cost Metrics
            - `inputCost` (number) - Input cost in USD
            - `outputCost` (number) - Output cost in USD
            - `totalCost` (number) - Total cost in USD

            ### Model Information
            - `model` (string) - Provided model name (alias: `providedModelName`)
            - `promptName` (string) - Associated prompt name
            - `promptVersion` (number) - Associated prompt version

            ### Structured Data
            - `metadata` (stringObject/numberObject/categoryOptions) - Metadata key-value pairs. Use `key` parameter to filter on specific metadata keys.

            ## Filter Examples
            ```json
            [
              {
                "type": "string",
                "column": "type",
                "operator": "=",
                "value": "GENERATION"
              },
              {
                "type": "number",
                "column": "latency",
                "operator": ">=",
                "value": 2.5
              },
              {
                "type": "stringObject",
                "column": "metadata",
                "key": "environment",
                "operator": "=",
                "value": "production"
              }
            ]
            ```

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ObservationsV2Response

        Examples
        --------
        from langfuse import LangfuseAPI

        client = LangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )
        client.observations.get_many()
        r   r   get_manydatar   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   	_responses                      r   r1   zObservationsClient.get_many   s_    n $--+-"7#+'+# . 
 
	& ~r   )__name__
__module____qualname__r   r   propertyr
   r   typingOptionalstrintboolr   UnionSequencedtdatetimer   r   r1    r   r   r   r      s       P*; P P P P  #8       X  (,04&*'+26%)(,%))-376:PT8<6:(,'+;?'j j j $j  -	j
 s#j $j !/$/j oc"j %j oc"j /#&j /0j  &s3j _V\#vs7K2K%LMj  5j  r{3!j" %#j$ $%j&  8'j( 
 )j j j j j jr   r   c            %       f   e Zd ZdefdZedefd            Zdddddddddddddddddddej	        e
         dej	        e
         d	ej	        e         d
ej	        e
         dej	        e         dej	        e
         dej	        e
         dej	        e
         dej	        e
         dej	        e         dej	        e
         dej	        ej        e
ej        e
         f                  dej	        ej                 dej	        ej                 dej	        e
         dej	        e
         dej	        e         def$dZdS )AsyncObservationsClientr   c                0    t          |          | _        d S r   )r	   r   r   s     r   r   z AsyncObservationsClient.__init__
  s    5^TTTr   r   c                     | j         S )z
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawObservationsClient
        r   r   s    r   r   z)AsyncObservationsClient.with_raw_response  r   r   Nr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   c                v   K   | j                             |||||||||	|
|||||||           d{V }|j        S )a#$  
        Get a list of observations with cursor-based pagination and flexible field selection.

        ## Cursor-based Pagination
        This endpoint uses cursor-based pagination for efficient traversal of large datasets.
        The cursor is returned in the response metadata and should be passed in subsequent requests
        to retrieve the next page of results.

        ## Field Selection
        Use the `fields` parameter to control which observation fields are returned:
        - `core` - Always included: id, traceId, startTime, endTime, projectId, parentObservationId, type
        - `basic` - name, level, statusMessage, version, environment, bookmarked, public, userId, sessionId
        - `time` - completionStartTime, createdAt, updatedAt
        - `io` - input, output
        - `metadata` - metadata (truncated to 200 chars by default, use `expandMetadata` to get full values)
        - `model` - providedModelName, internalModelId, modelParameters
        - `usage` - usageDetails, costDetails, totalCost
        - `prompt` - promptId, promptName, promptVersion
        - `metrics` - latency, timeToFirstToken

        If not specified, `core` and `basic` field groups are returned.

        ## Filters
        Multiple filtering options are available via query parameters or the structured `filter` parameter.
        When using the `filter` parameter, it takes precedence over individual query parameter filters.

        Parameters
        ----------
        fields : typing.Optional[str]
            Comma-separated list of field groups to include in the response.
            Available groups: core, basic, time, io, metadata, model, usage, prompt, metrics.
            If not specified, `core` and `basic` field groups are returned.
            Example: "basic,usage,model"

        expand_metadata : typing.Optional[str]
            Comma-separated list of metadata keys to return non-truncated.
            By default, metadata values over 200 characters are truncated.
            Use this parameter to retrieve full values for specific keys.
            Example: "key1,key2"

        limit : typing.Optional[int]
            Number of items to return per page. Maximum 1000, default 50.

        cursor : typing.Optional[str]
            Base64-encoded cursor for pagination. Use the cursor from the previous response to get the next page.

        parse_io_as_json : typing.Optional[bool]
            **Deprecated.** Setting this to `true` will return a 400 error.
            Input/output fields are always returned as raw strings.
            Remove this parameter or set it to `false`.

        name : typing.Optional[str]

        user_id : typing.Optional[str]

        type : typing.Optional[str]
            Filter by observation type (e.g., "GENERATION", "SPAN", "EVENT", "AGENT", "TOOL", "CHAIN", "RETRIEVER", "EVALUATOR", "EMBEDDING", "GUARDRAIL")

        trace_id : typing.Optional[str]

        level : typing.Optional[ObservationLevel]
            Optional filter for observations with a specific level (e.g. "DEBUG", "DEFAULT", "WARNING", "ERROR").

        parent_observation_id : typing.Optional[str]

        environment : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            Optional filter for observations where the environment is one of the provided values.

        from_start_time : typing.Optional[dt.datetime]
            Retrieve only observations with a start_time on or after this datetime (ISO 8601).

        to_start_time : typing.Optional[dt.datetime]
            Retrieve only observations with a start_time before this datetime (ISO 8601).

        version : typing.Optional[str]
            Optional filter to only include observations with a certain version.

        filter : typing.Optional[str]
            JSON string containing an array of filter conditions. When provided, this takes precedence over query parameter filters (userId, name, type, level, environment, fromStartTime, ...).

            ## Filter Structure
            Each filter condition has the following structure:
            ```json
            [
              {
                "type": string,           // Required. One of: "datetime", "string", "number", "stringOptions", "categoryOptions", "arrayOptions", "stringObject", "numberObject", "boolean", "null"
                "column": string,         // Required. Column to filter on (see available columns below)
                "operator": string,       // Required. Operator based on type:
                                          // - datetime: ">", "<", ">=", "<="
                                          // - string: "=", "contains", "does not contain", "starts with", "ends with"
                                          // - stringOptions: "any of", "none of"
                                          // - categoryOptions: "any of", "none of"
                                          // - arrayOptions: "any of", "none of", "all of"
                                          // - number: "=", ">", "<", ">=", "<="
                                          // - stringObject: "=", "contains", "does not contain", "starts with", "ends with"
                                          // - numberObject: "=", ">", "<", ">=", "<="
                                          // - boolean: "=", "<>"
                                          // - null: "is null", "is not null"
                "value": any,             // Required (except for null type). Value to compare against. Type depends on filter type
                "key": string             // Required only for stringObject, numberObject, and categoryOptions types when filtering on nested fields like metadata
              }
            ]
            ```

            ## Available Columns

            ### Core Observation Fields
            - `id` (string) - Observation ID
            - `type` (string) - Observation type (SPAN, GENERATION, EVENT)
            - `name` (string) - Observation name
            - `traceId` (string) - Associated trace ID
            - `startTime` (datetime) - Observation start time
            - `endTime` (datetime) - Observation end time
            - `environment` (string) - Environment tag
            - `level` (string) - Log level (DEBUG, DEFAULT, WARNING, ERROR)
            - `statusMessage` (string) - Status message
            - `version` (string) - Version tag
            - `userId` (string) - User ID
            - `sessionId` (string) - Session ID

            ### Trace-Related Fields
            - `traceName` (string) - Name of the parent trace
            - `traceTags` (arrayOptions) - Tags from the parent trace
            - `tags` (arrayOptions) - Alias for traceTags

            ### Performance Metrics
            - `latency` (number) - Latency in seconds (calculated: end_time - start_time)
            - `timeToFirstToken` (number) - Time to first token in seconds
            - `tokensPerSecond` (number) - Output tokens per second

            ### Token Usage
            - `inputTokens` (number) - Number of input tokens
            - `outputTokens` (number) - Number of output tokens
            - `totalTokens` (number) - Total tokens (alias: `tokens`)

            ### Cost Metrics
            - `inputCost` (number) - Input cost in USD
            - `outputCost` (number) - Output cost in USD
            - `totalCost` (number) - Total cost in USD

            ### Model Information
            - `model` (string) - Provided model name (alias: `providedModelName`)
            - `promptName` (string) - Associated prompt name
            - `promptVersion` (number) - Associated prompt version

            ### Structured Data
            - `metadata` (stringObject/numberObject/categoryOptions) - Metadata key-value pairs. Use `key` parameter to filter on specific metadata keys.

            ## Filter Examples
            ```json
            [
              {
                "type": "string",
                "column": "type",
                "operator": "=",
                "value": "GENERATION"
              },
              {
                "type": "number",
                "column": "latency",
                "operator": ">=",
                "value": 2.5
              },
              {
                "type": "stringObject",
                "column": "metadata",
                "key": "environment",
                "operator": "=",
                "value": "production"
              }
            ]
            ```

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ObservationsV2Response

        Examples
        --------
        import asyncio

        from langfuse import AsyncLangfuseAPI

        client = AsyncLangfuseAPI(
            x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
            x_langfuse_sdk_version="YOUR_X_LANGFUSE_SDK_VERSION",
            x_langfuse_public_key="YOUR_X_LANGFUSE_PUBLIC_KEY",
            username="YOUR_USERNAME",
            password="YOUR_PASSWORD",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.observations.get_many()


        asyncio.run(main())
        r   Nr0   r3   s                      r   r1   z AsyncObservationsClient.get_many  s      ~ *33+-"7#+'+# 4 
 
 
 
 
 
 
 
	& ~r   )r5   r6   r7   r   r   r8   r	   r   r9   r:   r;   r<   r=   r   r>   r?   r@   rA   r   r   r1   rB   r   r   rD   rD   	  s       U*< U U U U  #=       X  (,04&*'+26%)(,%))-376:PT8<6:(,'+;?'r r r $r  -	r
 s#r $r !/$/r oc"r %r oc"r /#&r /0r  &s3r _V\#vs7K2K%LMr  5r  r{3!r" %#r$ $%r&  8'r( 
 )r r r r r rr   rD   )rA   r@   r9   commons.types.observation_levelr   core.client_wrapperr   r   core.request_optionsr   
raw_clientr	   r
   types.observations_v2responser   r   rD   rB   r   r   <module>rM      s         > > > > > > G G G G G G G G 1 1 1 1 1 1 I I I I I I I I A A A A A Ay y y y y y y yxA A A A A A A A A Ar   