o
    ùT·jÁš  ã                   @  s„  d dl mZ d dlmZmZmZmZ d dlmZ d dl	Z	ddl
mZ ddlmZmZmZmZmZmZmZ ddlmZmZmZ dd	lmZ d
dlmZmZmZmZmZ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+m,Z, ddl-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddgZ7G dd„ de"ƒZ8G dd„ de#ƒZ9G dd„ dƒZ:G dd„ dƒZ;G dd„ dƒZ<G dd„ dƒZ=dS ) é    )Úannotations)ÚDictÚUnionÚIterableÚOptional)ÚLiteralNé   )Ú_legacy_response)ÚBodyÚOmitÚQueryÚHeadersÚNotGivenÚomitÚ	not_given)Úpath_templateÚmaybe_transformÚasync_maybe_transform)Úcached_propertyé   )ÚCheckpointsÚAsyncCheckpointsÚCheckpointsWithRawResponseÚAsyncCheckpointsWithRawResponseÚ CheckpointsWithStreamingResponseÚ%AsyncCheckpointsWithStreamingResponse)ÚSyncAPIResourceÚAsyncAPIResource)Úto_streamed_response_wrapperÚ"async_to_streamed_response_wrapper)ÚSyncCursorPageÚAsyncCursorPage)ÚAsyncPaginatorÚmake_request_options)Újob_list_paramsÚjob_create_paramsÚjob_list_events_params)ÚMetadata)ÚFineTuningJob)ÚFineTuningJobEventÚJobsÚ	AsyncJobsc                   @  óì   e Zd ZdZedAdd„ƒZedBdd„ƒZedCd
d„ƒZeeeeeeeddde	dœdDd(d)„Z
ddde	d*œdEd,d-„Zeeeddde	d.œdFd5d6„Zddde	d*œdEd7d8„Zeeddde	d9œdGd;d<„Zddde	d*œdEd=d>„Zddde	d*œdEd?d@„ZdS )Hr*   úIManage fine-tuning jobs to tailor a model to your specific training data.Úreturnr   c                 C  ó
   t | jƒS ©r-   )r   Ú_client©Úself© r4   úi/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/openai/resources/fine_tuning/jobs/jobs.pyÚcheckpoints%   ó   
zJobs.checkpointsÚJobsWithRawResponsec                 C  ó   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
        )r8   r2   r4   r4   r5   Úwith_raw_response*   ó   zJobs.with_raw_responseÚJobsWithStreamingResponsec                 C  r9   ©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=   r2   r4   r4   r5   Úwith_streaming_response4   ó   zJobs.with_streaming_responseN©ÚhyperparametersÚintegrationsÚmetadataÚmethodÚseedÚsuffixÚvalidation_fileÚextra_headersÚextra_queryÚ
extra_bodyÚtimeoutÚmodelúQUnion[str, Literal['babbage-002', 'davinci-002', 'gpt-3.5-turbo', 'gpt-4o-mini']]Útraining_fileÚstrrB   ú(job_create_params.Hyperparameters | OmitrC   ú8Optional[Iterable[job_create_params.Integration]] | OmitrD   úOptional[Metadata] | OmitrE   újob_create_params.Method | OmitrF   úOptional[int] | OmitrG   úOptional[str] | OmitrH   rI   úHeaders | NonerJ   úQuery | NonerK   úBody | NonerL   ú(float | httpx2.Timeout | None | NotGivenr(   c                C  s@   | j dt|||||||||	dœ	tjƒt|
|||ddid�td�S )á  
        Creates a fine-tuning job which begins the process of creating a new model from
        a given dataset.

        Response includes details of the enqueued job including job status and the name
        of the fine-tuned models once complete.

        [Learn more about fine-tuning](https://developers.openai.com/api/docs/guides/model-optimization)

        Args:
          model: The name of the model to fine-tune. You can select one of the
              [supported models](https://developers.openai.com/api/docs/guides/model-optimization#fine-tuning-methods).

          training_file: The ID of an uploaded file that contains training data.

              See
              [upload file](https://developers.openai.com/api/reference/resources/files/methods/create)
              for how to upload a file.

              Your dataset must be formatted as a JSONL file. Additionally, you must upload
              your file with the purpose `fine-tune`.

              The contents of the file should differ depending on if the model uses the
              [chat](https://developers.openai.com/api/docs/guides/supervised-fine-tuning#formatting-your-data),
              [completions](https://developers.openai.com/api/docs/guides/supervised-fine-tuning#formatting-your-data)
              format, or if the fine-tuning method uses the
              [preference](https://developers.openai.com/api/docs/guides/direct-preference-optimization)
              format.

              See the
              [fine-tuning guide](https://developers.openai.com/api/docs/guides/model-optimization)
              for more details.

          hyperparameters: The hyperparameters used for the fine-tuning job. This value is now deprecated
              in favor of `method`, and should be passed in under the `method` parameter.

          integrations: A list of integrations to enable for your fine-tuning job.

          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.

          method: The method used for fine-tuning.

          seed: The seed controls the reproducibility of the job. Passing in the same seed and
              job parameters should produce the same results, but may differ in rare cases. If
              a seed is not specified, one will be generated for you.

          suffix: A string of up to 64 characters that will be added to your fine-tuned model
              name.

              For example, a `suffix` of "custom-model-name" would produce a model name like
              `ft:gpt-4o-mini:openai:custom-model-name:7p4lURel`.

          validation_file: The ID of an uploaded file that contains validation data.

              If you provide this file, the data is used to generate validation metrics
              periodically during fine-tuning. These metrics can be viewed in the fine-tuning
              results file. The same data should not be present in both train and validation
              files.

              Your dataset must be formatted as a JSONL file. You must upload your file with
              the purpose `fine-tune`.

              See the
              [fine-tuning guide](https://developers.openai.com/api/docs/guides/model-optimization)
              for more details.

          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
        ú/fine_tuning/jobs©	rM   rO   rB   rC   rD   rE   rF   rG   rH   Úbearer_authT©rI   rJ   rK   rL   Úsecurity©ÚbodyÚoptionsÚcast_to)Ú_postr   r%   ÚJobCreateParamsr#   r(   ©r3   rM   rO   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   r4   r4   r5   Úcreate=   s0   b÷ôûézJobs.create©rI   rJ   rK   rL   Úfine_tuning_job_idc             	   C  ó<   |s	t d|›�ƒ‚| jtd|d�t||||ddid�td�S )á¿  
        Get info about a fine-tuning job.

        [Learn more about fine-tuning](https://developers.openai.com/api/docs/guides/model-optimization)

        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
        úAExpected a non-empty value for `fine_tuning_job_id` but received ú&/fine_tuning/jobs/{fine_tuning_job_id}©rj   r^   Tr_   ©rc   rd   ©Ú
ValueErrorÚ_getr   r#   r(   ©r3   rj   rI   rJ   rK   rL   r4   r4   r5   Úretrieve¹   s   
û÷zJobs.retrieve©ÚafterÚlimitrD   rI   rJ   rK   rL   rw   ú
str | Omitrx   ú
int | OmitúOptional[Dict[str, str]] | OmitúSyncCursorPage[FineTuningJob]c                C  ó:   | j dtt t||||t|||dœtjƒddid�td�S ©a�  
        List your organization's fine-tuning jobs

        Args:
          after: Identifier for the last job from the previous pagination request.

          limit: Number of fine-tuning jobs to retrieve.

          metadata: Optional metadata filter. To filter, use the syntax `metadata[k]=v`.
              Alternatively, set `metadata=null` to indicate no metadata.

          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\   )rw   rx   rD   r^   T©rI   rJ   rK   rL   Úqueryr`   ©Úpagerc   rM   )Ú_get_api_listr    r(   r#   r   r$   ÚJobListParams©r3   rw   rx   rD   rI   rJ   rK   rL   r4   r4   r5   Úlistà   ó&    ýúóîz	Jobs.listc             	   C  rk   )áW  
        Immediately cancel a fine-tune job.

        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
        rm   ú-/fine_tuning/jobs/{fine_tuning_job_id}/cancelro   r^   Tr_   rp   ©rr   re   r   r#   r(   rt   r4   r4   r5   Úcancel  ó   
û÷zJobs.cancel©rw   rx   rI   rJ   rK   rL   ú"SyncCursorPage[FineTuningJobEvent]c                C  óR   |s	t d|›�ƒ‚| jtd|d�tt t||||t||dœtjƒddid�td�S ©	aã  
        Get status updates for a fine-tuning job.

        Args:
          after: Identifier for the last event from the previous pagination request.

          limit: Number of events to retrieve.

          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
        rm   z-/fine_tuning/jobs/{fine_tuning_job_id}/eventsro   )rw   rx   r^   Tr   r�   )	rr   rƒ   r   r    r)   r#   r   r&   ÚJobListEventsParams©r3   rj   rw   rx   rI   rJ   rK   rL   r4   r4   r5   Úlist_events:  ó(   
þûôïzJobs.list_eventsc             	   C  rk   )áJ  
        Pause a fine-tune job.

        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
        rm   ú,/fine_tuning/jobs/{fine_tuning_job_id}/pausero   r^   Tr_   rp   rŠ   rt   r4   r4   r5   Úpausem  rŒ   z
Jobs.pausec             	   C  rk   )áK  
        Resume a fine-tune job.

        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
        rm   ú-/fine_tuning/jobs/{fine_tuning_job_id}/resumero   r^   Tr_   rp   rŠ   rt   r4   r4   r5   Úresume’  rŒ   zJobs.resume)r.   r   )r.   r8   )r.   r=   ©rM   rN   rO   rP   rB   rQ   rC   rR   rD   rS   rE   rT   rF   rU   rG   rV   rH   rV   rI   rW   rJ   rX   rK   rY   rL   rZ   r.   r(   ©rj   rP   rI   rW   rJ   rX   rK   rY   rL   rZ   r.   r(   )rw   ry   rx   rz   rD   r{   rI   rW   rJ   rX   rK   rY   rL   rZ   r.   r|   )rj   rP   rw   ry   rx   rz   rI   rW   rJ   rX   rK   rY   rL   rZ   r.   rŽ   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r6   r;   r?   r   r   rh   ru   r†   r‹   r“   r—   rš   r4   r4   r4   r5   r*   "   óp    	ï ÷*õ;÷)õ9÷+÷c                   @  r,   )Hr+   r-   r.   r   c                 C  r/   r0   )r   r1   r2   r4   r4   r5   r6   »  r7   zAsyncJobs.checkpointsÚAsyncJobsWithRawResponsec                 C  r9   r:   )r£   r2   r4   r4   r5   r;   À  r<   zAsyncJobs.with_raw_responseÚAsyncJobsWithStreamingResponsec                 C  r9   r>   )r¤   r2   r4   r4   r5   r?   Ê  r@   z!AsyncJobs.with_streaming_responseNrA   rM   rN   rO   rP   rB   rQ   rC   rR   rD   rS   rE   rT   rF   rU   rG   rV   rH   rI   rW   rJ   rX   rK   rY   rL   rZ   r(   c                Ã  sN   �| j dt|||||||||	dœ	tjƒI dH t|
|||ddid�td�I dH S )r[   r\   r]   Nr^   Tr_   ra   )re   r   r%   rf   r#   r(   rg   r4   r4   r5   rh   Ó  s2   €b÷ôûézAsyncJobs.createri   rj   c             	   Ã  óD   �|s
t d|›�ƒ‚| jtd|d�t||||ddid�td�I dH S )	rl   rm   rn   ro   r^   Tr_   rp   Nrq   rt   r4   r4   r5   ru   O  s   €
û÷zAsyncJobs.retrieverv   rw   ry   rx   rz   r{   ú=AsyncPaginator[FineTuningJob, AsyncCursorPage[FineTuningJob]]c                C  r}   r~   )rƒ   r!   r(   r#   r   r$   r„   r…   r4   r4   r5   r†   v  r‡   zAsyncJobs.listc             	   Ã  r¥   )	rˆ   rm   r‰   ro   r^   Tr_   rp   NrŠ   rt   r4   r4   r5   r‹   «  ó   €
û÷zAsyncJobs.cancelr�   úGAsyncPaginator[FineTuningJobEvent, AsyncCursorPage[FineTuningJobEvent]]c                C  r�   r�   )	rr   rƒ   r   r!   r)   r#   r   r&   r‘   r’   r4   r4   r5   r“   Ð  r”   zAsyncJobs.list_eventsc             	   Ã  r¥   )	r•   rm   r–   ro   r^   Tr_   rp   NrŠ   rt   r4   r4   r5   r—     r§   zAsyncJobs.pausec             	   Ã  r¥   )	r˜   rm   r™   ro   r^   Tr_   rp   NrŠ   rt   r4   r4   r5   rš   (  r§   zAsyncJobs.resume)r.   r   )r.   r£   )r.   r¤   r›   rœ   )rw   ry   rx   rz   rD   r{   rI   rW   rJ   rX   rK   rY   rL   rZ   r.   r¦   )rj   rP   rw   ry   rx   rz   rI   rW   rJ   rX   rK   rY   rL   rZ   r.   r¨   r�   r4   r4   r4   r5   r+   ¸  r¢   c                   @  ó$   e Zd Zddd„Zeddd	„ƒZd
S )r8   Újobsr*   r.   ÚNonec                 C  ól   || _ t |j¡| _t |j¡| _t |j¡| _t |j¡| _t |j¡| _t |j¡| _t |j	¡| _	d S ©N)
Ú_jobsr	   Úto_raw_response_wrapperrh   ru   r†   r‹   r“   r—   rš   ©r3   rª   r4   r4   r5   Ú__init__O  ó,   ÿÿÿÿÿÿ
ÿzJobsWithRawResponse.__init__r   c                 C  ó   t | jjƒS r0   )r   r®   r6   r2   r4   r4   r5   r6   h  ó   zJobsWithRawResponse.checkpointsN©rª   r*   r.   r«   )r.   r   ©rž   rŸ   r    r±   r   r6   r4   r4   r4   r5   r8   N  ó    
r8   c                   @  r©   )r£   rª   r+   r.   r«   c                 C  r¬   r­   )
r®   r	   Úasync_to_raw_response_wrapperrh   ru   r†   r‹   r“   r—   rš   r°   r4   r4   r5   r±   o  r²   z!AsyncJobsWithRawResponse.__init__r   c                 C  r³   r0   )r   r®   r6   r2   r4   r4   r5   r6   ˆ  r´   z$AsyncJobsWithRawResponse.checkpointsN©rª   r+   r.   r«   )r.   r   r¶   r4   r4   r4   r5   r£   n  r·   r£   c                   @  r©   )r=   rª   r*   r.   r«   c                 C  ó^   || _ t|jƒ| _t|jƒ| _t|jƒ| _t|jƒ| _t|jƒ| _t|jƒ| _t|jƒ| _d S r­   )	r®   r   rh   ru   r†   r‹   r“   r—   rš   r°   r4   r4   r5   r±   �  ó,   ÿÿÿÿÿÿ
ÿz"JobsWithStreamingResponse.__init__r   c                 C  r³   r0   )r   r®   r6   r2   r4   r4   r5   r6   ¨  r´   z%JobsWithStreamingResponse.checkpointsNrµ   )r.   r   r¶   r4   r4   r4   r5   r=   Ž  r·   r=   c                   @  r©   )r¤   rª   r+   r.   r«   c                 C  rº   r­   )	r®   r   rh   ru   r†   r‹   r“   r—   rš   r°   r4   r4   r5   r±   ¯  r»   z'AsyncJobsWithStreamingResponse.__init__r   c                 C  r³   r0   )r   r®   r6   r2   r4   r4   r5   r6   È  r´   z*AsyncJobsWithStreamingResponse.checkpointsNr¹   )r.   r   r¶   r4   r4   r4   r5   r¤   ®  r·   r¤   )>Ú
__future__r   Útypingr   r   r   r   Útyping_extensionsr   Úhttpx2Ú r	   Ú_typesr
   r   r   r   r   r   r   Ú_utilsr   r   r   Ú_compatr   r6   r   r   r   r   r   r   Ú	_resourcer   r   Ú	_responser   r   Ú
paginationr    r!   Ú_base_clientr"   r#   Útypes.fine_tuningr$   r%   r&   Útypes.shared_params.metadatar'   Ú!types.fine_tuning.fine_tuning_jobr(   Ú'types.fine_tuning.fine_tuning_job_eventr)   Ú__all__r*   r+   r8   r£   r=   r¤   r4   r4   r4   r5   Ú<module>   s<   $          