
    ^h57                        S SK r S SKrS SKJr  S SKJrJrJrJrJ	r	J
r
  S SKrS SKJr  S SK7  S SKJr  \" 5       rS SKJr  SqS rS	\4S
 jr\R1                  S\" \5      /S/SS9\R1                  S\" \5      /S/SS9\" \5      4S\S\	S\S\4S jj5       5       r\R7                  S\" \5      /S/SS9\R7                  S\" \5      /S/SS9SS\" \5      4S\S\	S	\S   S\\   S\\   S\4S jj5       5       r\R1                  S\" \5      /S/SS9\R1                  S\" \5      /S/SS9\" \5      4S\S\	S\S\4S jj5       5       rg)    N)Optional)	APIRouterDependsHTTPExceptionRequestResponsestatus)verbose_proxy_logger)*)user_api_key_auth)LiteLLMFineTuningJobCreatec                 P   U c  g [        U [        5      (       d  [        S5      eU  Hz  n[        U[        5      (       d  M  UR	                  5        HL  u  p#[        U[
        5      (       d  M  UR                  S5      (       d  M4  [        R                  " U5      X'   MN     M|     U q	g )Nz9invalid fine_tuning config, expected a list is not a listzos.environ/)

isinstancelist
ValueErrordictitemsstr
startswithlitellm
get_secretfine_tuning_config)configelementkeyvalues       g/home/james-whalen/.local/lib/python3.13/site-packages/litellm/proxy/fine_tuning_endpoints/endpoints.pyset_fine_tuning_configr      s    ~ fd##TUUgt$$%mmo
eS))e.>.>}.M.M#*#5#5e#<GL .       custom_llm_providerc                 t    [         c  [        S5      e[          H  nUR                  S5      U :X  d  M  Us  $    g )Nz?fine_tuning_config is not set, set it on your config.yaml file.r    )r   r   get)r    settings     r   get_fine_tuning_provider_configr$   ,   sC     !M
 	
 &;;,-1DDN & r   z/v1/fine_tuning/jobszfine-tuningu'   ✨ (Enterprise) Create Fine-Tuning Job)dependenciestagssummaryz/fine_tuning/jobsrequestfastapi_responsefine_tuning_requestuser_api_key_dictc                   #    SSK JnJnJnJnJnJn	Jn
  UR                  SS9n USLa&  [        S[        R                  R                   35      e[        R                  " SR                  [         R#                  USS95      5        U" UU UUU
US	9I S
h  vN n[%        UR&                  S9nUb  UR)                  U5        [*        R,                  " S0 UD6I S
h  vN n[.        R0                  " U	R3                  UR5                  SS5      SS95        [7        US0 5      =(       d    0 nUR5                  SS
5      =(       d    SnUR5                  SS
5      =(       d    SnUR5                  SS
5      =(       d    SnUR8                  R)                  U" UUUUU
[7        USS5      S95        U$  GN N! [:         Ga(  nU	R=                  UUUS9I S
h  vN    [        R>                  " SR                  [A        U5      5      5        [        R                  " [B        RD                  " 5       5        [G        U[H        5      (       aY  [K        [7        US[A        URL                  5      5      [7        USS5      [7        USS5      [7        US[N        RP                  5      S9e[A        U5       n[K        [7        USU5      [7        USS5      [7        USS5      [7        USS5      S9eS
nAff = f7f) a,  
Creates a fine-tuning job which begins the process of creating a new model from a given dataset.
This is the equivalent of POST https://api.openai.com/v1/fine_tuning/jobs

Supports Identical Params as: https://platform.openai.com/docs/api-reference/fine-tuning/create

Example Curl:
```
curl http://localhost:4000/v1/fine_tuning/jobs       -H "Content-Type: application/json"       -H "Authorization: Bearer sk-1234"       -d '{
    "model": "gpt-3.5-turbo",
    "training_file": "file-abc123",
    "hyperparameters": {
      "n_epochs": 4
    }
  }'
```
r   add_litellm_data_to_requestgeneral_settingsget_custom_headerspremium_userproxy_configproxy_logging_objversionT)exclude_none+Only premium users can use this endpoint + zRequest received by LiteLLM:
{}   )indentdatar(   r/   r+   r4   r2   Nr    litellm_call_id success)r<   r	   _hidden_paramsmodel_id	cache_keyapi_baseallowed_model_regionr+   r@   rA   rB   r4   model_regionr+   original_exceptionrequest_datazLlitellm.proxy.proxy_server.create_fine_tuning_job(): Exception occurred - {}messagetypeNoneparamstatus_coderI   rJ   rL   code   ))litellm.proxy.proxy_serverr.   r/   r0   r1   r2   r3   r4   
model_dumpr   CommonProxyErrorsnot_premium_userr   r
   debugformatjsondumpsr$   r    updater   acreate_fine_tuning_jobasynciocreate_taskupdate_request_statusr"   getattrheaders	Exceptionpost_call_failure_hookerrorr   	traceback
format_excr   r   ProxyExceptiondetailr	   HTTP_400_BAD_REQUEST)r(   r)   r*   r+   r.   r/   r0   r1   r2   r3   r4   r:   llm_provider_configresponsehidden_paramsr@   rA   rB   e	error_msgs                       r   create_fine_tuning_jobrn   :   s    L   ))t)<DQt#=>O>`>`>f>f=gh 
 	"".55djjaj6PQ	

 1-/%
 
 > 3 G G

 *KK+, 88@4@@ 	33 $):B ?	 4 	
  *:B?E2 $$Z6<"!%%k48>B	 $$Z6<"  ''"3!#!$%68NPRS		
 Y
$ A6  66/ATX 7 
 	
 	
 	""ZaaA	

 	""9#7#7#9:a'' 9c!((m<Q/a&1Qv/J/JK	  q6(I 9i8Q/a&1Qs3	 's\   "K&A0F0 F+AF0 F.CF0 *K&+F0 .F0 0K#;KGDKK##K&u&   ✨ (Enterprise) List Fine-Tuning Jobs)openaiazureafterlimitc                   #    SSK JnJnJnJn	Jn
JnJn  0 n U	SLa&  [        S[        R                  R                   35      eU" UU UUUU
S9I Sh  vN n[        US9nUb  UR                  U5        [        R                  " S0 UDUUS.D6I Sh  vN n[!        US	0 5      =(       d    0 nUR#                  S
S5      =(       d    SnUR#                  SS5      =(       d    SnUR#                  SS5      =(       d    SnUR$                  R                  U" UUUUU[!        USS5      S95        U$  N N! [&         Ga(  nUR)                  UUUS9I Sh  vN    [*        R,                  " SR/                  [1        U5      5      5        [*        R2                  " [4        R6                  " 5       5        [9        U[:        5      (       aY  [=        [!        US[1        UR>                  5      5      [!        USS5      [!        USS5      [!        US[@        RB                  5      S9e[1        U5       n[=        [!        USU5      [!        USS5      [!        USS5      [!        USS5      S9eSnAff = f7f)aV  
Lists fine-tuning jobs for the organization.
This is the equivalent of GET https://api.openai.com/v1/fine_tuning/jobs

Supported Query Params:
- `custom_llm_provider`: Name of the LiteLLM provider
- `after`: Identifier for the last job from the previous pagination request.
- `limit`: Number of fine-tuning jobs to retrieve (default is 20).
r   r-   Tr6   r9   Nr;   )rq   rr   r?   r@   r=   rA   rB   rC   rD   rF   Klitellm.proxy.proxy_server.list_fine_tuning_jobs(): Exception occurred - {}rI   rJ   rK   rL   rM   rN   rP   rQ   )"rR   r.   r/   r0   r1   r2   r3   r4   r   rT   rU   r   r$   rZ   r   alist_fine_tuning_jobsr_   r"   r`   ra   rb   r
   rc   rW   r   rV   rd   re   r   r   rf   rg   r	   rh   )r(   r)   r    rq   rr   r+   r.   r/   r0   r1   r2   r3   r4   r:   ri   rj   rk   r@   rA   rB   rl   rm   s                         r   list_fine_tuning_jobsrv      s{    :   DHt#=>O>`>`>f>f=gh  1-/%
 
 > 3
 *KK+, 77 


 
  *:B?E2 $$Z6<"!%%k48>B	 $$Z6<"  ''"3!#!$%68NPRS		
 Q
"
2  66/ATX 7 
 	
 	
 	""Y``A	

 	""9#7#7#9:a'' 9c!((m<Q/a&1Qv/J/JK	  q6(I 9i8Q/a&1Qs3	 'sZ   I(9D2 D.?D2 D0BD2 -I(.D2 0D2 2I%=I EDI  I%%I(z5/v1/fine_tuning/jobs/{fine_tuning_job_id:path}/cancelu(   ✨ (Enterprise) Cancel Fine-Tuning Jobsz2/fine_tuning/jobs/{fine_tuning_job_id:path}/cancelfine_tuning_job_idc                 ,  #    SSK JnJnJnJnJnJn	Jn
  0 n USLa&  [        S[        R                  R                   35      eU" UU UUU
US9I Sh  vN nU R                  5       I Sh  vN nUR                  SS5      n[        US9nUb  UR                  U5        [         R"                  " S0 UDS	U0D6I Sh  vN n[%        US
0 5      =(       d    0 nUR                  SS5      =(       d    SnUR                  SS5      =(       d    SnUR                  SS5      =(       d    SnUR&                  R                  U" UUUUU
[%        USS5      S95        U$  GN N N! [(         Ga(  nU	R+                  UUUS9I Sh  vN    [,        R.                  " SR1                  [3        U5      5      5        [,        R4                  " [6        R8                  " 5       5        [;        U[<        5      (       aY  [?        [%        US[3        UR@                  5      5      [%        USS5      [%        USS5      [%        US[B        RD                  5      S9e[3        U5       n[?        [%        USU5      [%        USS5      [%        USS5      [%        USS5      S9eSnAff = f7f)a  
Cancel a fine-tuning job.

This is the equivalent of POST https://api.openai.com/v1/fine_tuning/jobs/{fine_tuning_job_id}/cancel

Supported Query Params:
- `custom_llm_provider`: Name of the LiteLLM provider
- `fine_tuning_job_id`: The ID of the fine-tuning job to cancel.
r   r-   Tr6   r9   Nr    r;   rw   r?   r@   r=   rA   rB   rC   rD   rF   rt   rI   rJ   rK   rL   rM   rN   rP   rQ   )#rR   r.   r/   r0   r1   r2   r3   r4   r   rT   rU   r   rX   r"   r$   rZ   r   acancel_fine_tuning_jobr_   r`   ra   rb   r
   rc   rW   r   rV   rd   re   r   r   rf   rg   r	   rh   )r(   r)   rw   r+   r.   r/   r0   r1   r2   r3   r4   r:   request_bodyr    ri   rj   rk   r@   rA   rB   rl   rm   s                         r   retrieve_fine_tuning_jobr{   2  s    6   DKt#=>O>`>`>f>f=gh  1-/%
 
 %\\^+*../DdK > 3
 *KK+, 88 

1
 
  *:B?E2 $$Z6<"!%%k48>B	 $$Z6<"  ''"3!#!$%68NPRS		
 W
 ,
0  66/ATX 7 
 	
 	
 	""Y``A	

 	""9#7#7#9:a'' 9c!((m<Q/a&1Qv/J/JK	  q6(I 9i8Q/a&1Qs3	 'sm   J9E EE )E*AE :E;BE JE E E J)J=F >DJJJ) r\   rd   typingr   fastapir   r   r   r   r   r	   r   litellm._loggingr
   litellm.proxy._types$litellm.proxy.auth.user_api_key_authr   routerlitellm.types.llms.openair   r   r   r   r$   postUserAPIKeyAuthrn   r"   Literalintrv   r{   rQ   r   r   <module>r      sG      P P  1 " B	 @  $ +,-
5	   +,-
5	   )00A(B	vvv 4v &	vvr +,-
4	   +,-
4	    (/0A(Bddd !!23d C=	d
 C=d &ddN ;+,-
6	   8+,-
6	   )00A(B	eee e &	eer   