U
    ·ÜŸjuO  ã                   @  s<  d dl mZ d dlmZ d dlmZ d dlZddlmZ ddl	m
Z
mZ ddlmZmZmZmZ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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& ddgZ'G dd„ deƒZ(G dd„ deƒZ)G dd„ dƒZ*G dd„ dƒZ+G dd„ dƒZ,G dd„ dƒZ-dS )é    )Úannotations)ÚOptional)ÚLiteralNé   )Ú_legacy_response)Úbatch_list_paramsÚbatch_create_params)Ú	NOT_GIVENÚBodyÚQueryÚHeadersÚNotGiven)Úmaybe_transformÚasync_maybe_transform)Úcached_property)ÚSyncAPIResourceÚAsyncAPIResource)Úto_streamed_response_wrapperÚ"async_to_streamed_response_wrapper)ÚSyncCursorPageÚAsyncCursorPage)ÚBatch)ÚAsyncPaginatorÚmake_request_options)ÚMetadataÚBatchesÚAsyncBatchesc                   @  sÎ   e Zd Zeddœdd„ƒZeddœdd„ƒZeddded	œd
dddddddddœ	dd„Zdddedœdddddddœdd„Zeedddedœddddddddœdd „Z	dddedœdddddddœd!d"„Z
dS )#r   ÚBatchesWithRawResponse©Úreturnc                 C  s   t | ƒS ©a  
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
        )r   ©Úself© r#   ú</tmp/pip-unpacked-wheel-2qj3ofc_/openai/resources/batches.pyÚwith_raw_response   s    zBatches.with_raw_responseÚBatchesWithStreamingResponsec                 C  s   t | ƒS ©zÌ
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/openai/openai-python#with_streaming_response
        )r&   r!   r#   r#   r$   Úwith_streaming_response'   s    zBatches.with_streaming_responseN©ÚmetadataÚextra_headersÚextra_queryÚ
extra_bodyÚtimeoutúLiteral['24h']úWLiteral[('/v1/responses', '/v1/chat/completions', '/v1/embeddings', '/v1/completions')]ÚstrúOptional[Metadata] | NotGivenúHeaders | NoneúQuery | NoneúBody | Noneú'float | httpx.Timeout | None | NotGivenr   ©	Úcompletion_windowÚendpointÚinput_file_idr*   r+   r,   r-   r.   r   c          	   	   C  s0   | j dt||||dœtjƒt||||d�td�S )á  
        Creates and executes a batch from an uploaded file of requests

        Args:
          completion_window: The time frame within which the batch should be processed. Currently only `24h`
              is supported.

          endpoint: The endpoint to be used for all requests in the batch. Currently
              `/v1/responses`, `/v1/chat/completions`, `/v1/embeddings`, and `/v1/completions`
              are supported. Note that `/v1/embeddings` batches are also restricted to a
              maximum of 50,000 embedding inputs across all requests in the batch.

          input_file_id: The ID of an uploaded file that contains requests for the new batch.

              See [upload file](https://platform.openai.com/docs/api-reference/files/create)
              for how to upload a file.

              Your input file must be formatted as a
              [JSONL file](https://platform.openai.com/docs/api-reference/batch/request-input),
              and must be uploaded with the purpose `batch`. The file can contain up to 50,000
              requests, and can be up to 200 MB in size.

          metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
              for storing additional information about the object in a structured format, and
              querying for objects via API or the dashboard.

              Keys are strings with a maximum length of 64 characters. Values are strings with
              a maximum length of 512 characters.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        ú/batches©r8   r9   r:   r*   ©r+   r,   r-   r.   ©ÚbodyÚoptionsÚcast_to)Ú_postr   r   ÚBatchCreateParamsr   r   ©	r"   r8   r9   r:   r*   r+   r,   r-   r.   r#   r#   r$   Úcreate0   s$    3üù	   ÿòzBatches.creater>   ©Úbatch_idr+   r,   r-   r.   r   c                C  s4   |st d|›�ƒ‚| jd|› �t||||d�td�S )áF  
        Retrieves a batch.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        ú7Expected a non-empty value for `batch_id` but received ú	/batches/r>   ©rA   rB   ©Ú
ValueErrorÚ_getr   r   ©r"   rH   r+   r,   r-   r.   r#   r#   r$   Úretrievet   s       ÿûzBatches.retrieve©ÚafterÚlimitr+   r,   r-   r.   ústr | NotGivenúint | NotGivenzSyncCursorPage[Batch]©rS   rT   r+   r,   r-   r.   r   c                C  s2   | j dtt t||||t||dœtjƒd�td�S ©a,  List your organization's batches.

        Args:
          after: A cursor for use in pagination.

        `after` is an object ID that defines your place
              in the list. For instance, if you make a list request and receive 100 objects,
              ending with obj_foo, your subsequent call can include after=obj_foo in order to
              fetch the next page of the list.

          limit: A limit on the number of objects to be returned. Limit can range between 1 and
              100, and the default is 20.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        r<   )rS   rT   )r+   r,   r-   r.   Úquery)ÚpagerA   Úmodel)Ú_get_api_listr   r   r   r   r   ÚBatchListParams©r"   rS   rT   r+   r,   r-   r.   r#   r#   r$   Úlist•   s"    !þûûðzBatches.listc                C  s6   |st d|›�ƒ‚| jd|› d�t||||d�td�S )á
  Cancels an in-progress batch.

        The batch will be in status `cancelling` for up to
        10 minutes, before changing to `cancelled`, where it will have partial results
        (if any) available in the output file.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        rJ   rK   ú/cancelr>   rL   ©rN   rC   r   r   rP   r#   r#   r$   ÚcancelÉ   s    
   ÿûzBatches.cancel©Ú__name__Ú
__module__Ú__qualname__r   r%   r(   r	   rF   rQ   r_   rc   r#   r#   r#   r$   r      s6   	ô"J÷$ö:÷c                   @  sÎ   e Zd Zeddœdd„ƒZeddœdd„ƒZeddded	œd
dddddddddœ	dd„Zdddedœdddddddœdd„Zeedddedœddddddddœdd „Z	dddedœdddddddœd!d"„Z
dS )#r   ÚAsyncBatchesWithRawResponser   c                 C  s   t | ƒS r    )rh   r!   r#   r#   r$   r%   ï   s    zAsyncBatches.with_raw_responseÚ!AsyncBatchesWithStreamingResponsec                 C  s   t | ƒS r'   )ri   r!   r#   r#   r$   r(   ù   s    z$AsyncBatches.with_streaming_responseNr)   r/   r0   r1   r2   r3   r4   r5   r6   r   r7   c          	   	   Ã  s<   | j dt||||dœtjƒI dH t||||d�td�I dH S )r;   r<   r=   Nr>   r?   )rC   r   r   rD   r   r   rE   r#   r#   r$   rF     s$    3üù	   ÿòzAsyncBatches.creater>   rG   c                Ã  s:   |st d|›�ƒ‚| jd|› �t||||d�td�I dH S )rI   rJ   rK   r>   rL   NrM   rP   r#   r#   r$   rQ   F  s       ÿûzAsyncBatches.retrieverR   rU   rV   z-AsyncPaginator[Batch, AsyncCursorPage[Batch]]rW   c                C  s2   | j dtt t||||t||dœtjƒd�td�S rX   )r\   r   r   r   r   r   r]   r^   r#   r#   r$   r_   g  s"    !þûûðzAsyncBatches.listc                Ã  s<   |st d|›�ƒ‚| jd|› d�t||||d�td�I dH S )r`   rJ   rK   ra   r>   rL   Nrb   rP   r#   r#   r$   rc   ›  s    
   ÿûzAsyncBatches.cancelrd   r#   r#   r#   r$   r   î   s6   	ô"J÷$ö:÷c                   @  s   e Zd Zdddœdd„ZdS )r   r   ÚNone©Úbatchesr   c                 C  sB   || _ t |j¡| _t |j¡| _t |j¡| _t |j¡| _d S ©N)Ú_batchesr   Zto_raw_response_wrapperrF   rQ   r_   rc   ©r"   rl   r#   r#   r$   Ú__init__Á  s    ÿÿÿÿzBatchesWithRawResponse.__init__N©re   rf   rg   rp   r#   r#   r#   r$   r   À  s   r   c                   @  s   e Zd Zdddœdd„ZdS )rh   r   rj   rk   c                 C  sB   || _ t |j¡| _t |j¡| _t |j¡| _t |j¡| _d S rm   )rn   r   Zasync_to_raw_response_wrapperrF   rQ   r_   rc   ro   r#   r#   r$   rp   Ó  s    ÿÿÿÿz$AsyncBatchesWithRawResponse.__init__Nrq   r#   r#   r#   r$   rh   Ò  s   rh   c                   @  s   e Zd Zdddœdd„ZdS )r&   r   rj   rk   c                 C  s:   || _ t|jƒ| _t|jƒ| _t|jƒ| _t|jƒ| _d S rm   )rn   r   rF   rQ   r_   rc   ro   r#   r#   r$   rp   å  s    ÿÿÿÿz%BatchesWithStreamingResponse.__init__Nrq   r#   r#   r#   r$   r&   ä  s   r&   c                   @  s   e Zd Zdddœdd„ZdS )ri   r   rj   rk   c                 C  s:   || _ t|jƒ| _t|jƒ| _t|jƒ| _t|jƒ| _d S rm   )rn   r   rF   rQ   r_   rc   ro   r#   r#   r$   rp   ÷  s    ÿÿÿÿz*AsyncBatchesWithStreamingResponse.__init__Nrq   r#   r#   r#   r$   ri   ö  s   ri   ).Ú
__future__r   Útypingr   Útyping_extensionsr   ZhttpxÚ r   Útypesr   r   Ú_typesr	   r
   r   r   r   Ú_utilsr   r   Ú_compatr   Z	_resourcer   r   Ú	_responser   r   Z
paginationr   r   Ztypes.batchr   Z_base_clientr   r   Ztypes.shared_params.metadatar   Ú__all__r   r   r   rh   r&   ri   r#   r#   r#   r$   Ú<module>   s.    S S