
    5P@ix4                       d dl mZ d dlZd dlmZmZ d dlmc 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 d d	lmZ dd
	 	 	 ddZdd
ddZdd
	 	 	 ddZ	 d 	 	 	 d!dZddd	 	 	 	 	 d"dZddd	 	 	 	 	 d#dZddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d$dZej6                  	 d dd
	 	 	 	 	 	 	 d%d       Zej6                  dd
	 	 	 	 	 	 	 d&d       Z	 d dd
	 	 	 	 	 	 	 d'dZd Zd Z	 d 	 	 	 	 	 d(dZy))    )annotationsN)AnyLiteral)
operations)get_default_model_client)model_types)	operation)protobuf_helpers)field_mask_pb2clientc                   t        j                  |       } | j                  d      rt        | |      S | j                  d      rt	        | |      S t        d      )aY  Given a model name, fetch the `types.Model` or `types.TunedModel` object.

    ```
    import pprint
    model = genai.get_tuned_model(model_name):
    pprint.pprint(model)
    ```

    Args:
        name: The name of the model to fetch.
        client: The client to use.

    Returns:
        A `types.Model` or `types.TunedModel` object.
    models/r   tunedModels/z7Model names must start with `models/` or `tunedModels/`)r   make_model_name
startswithget_base_modelget_tuned_model
ValueError)namer   s     d/home/www/lebenam.kofcorporation.com/venv/lib/python3.12/site-packages/google/generativeai/models.py	get_modelr      sR    $ &&t,Dy!d622		(tF33RSS    c                  |
t               }t        j                  |       } | j                  d      st	        d|        |j                  |       }t        |      j                  |      }t        j                  di |S )a.  Get the `types.Model` for the given base model name.

    ```
    import pprint
    model = genai.get_model('models/chat-bison-001'):
    pprint.pprint(model)
    ```

    Args:
        name: The name of the model to fetch.
        client: The client to use.

    Returns:
        A `types.Model`.
    r   z1Base model names must start with `models/`, got: r    )	r   r   r   r   r   r   typeto_dictModelr   r   results      r   r   r   8   s{      ~)+&&t,D??9%LTFSTT4(F&\!!&)F&v&&r   c                   |
t               }t        j                  |       } | j                  d      st	        d      |j                  |       }t        j                  |      S )aC  Get the `types.TunedModel` for the given tuned model name.

    ```
    import pprint
    model = genai.get_tuned_model('tunedModels/my-model-1234'):
    pprint.pprint(model)
    ```

    Args:
        name: The name of the model to fetch.
        client: The client to use.

    Returns:
        A `types.TunedModel`.
    r   z0Tuned model names must start with `tunedModels/`r   )r   r   r   r   r   r   decode_tuned_modelr    s      r   r   r   T   s]    $ ~)+&&t,D??>*KLL###.F))&11r   c                   t        | t              r0| j                  d      rt        | |      } | j                  }|S | }|S t        | t
        j                        r| j                  }|S t        | t
        j                        r| j                  }|S t        | t        j                        r| j                  }|S t        | t        j                        r't        | dd       }|s| j                  j                  }|S t        d|        )Nr   r   
base_modelzCannot understand model: )
isinstancestrr   r   r%   r   
TunedModelr   r   glmgetattrtuned_model_source	TypeError)modelr   r%   s      r   get_base_model_namer.   s   s    %N+eF3E))J   J  
E;11	2%%
  
E;,,	-ZZ
  
E399	%ZZ
  
E3>>	*UL$7
11<<J  3E7;<<r   2   )	page_sizer   c              #     K   |
t               }|j                  |       D ]3  }t        |      j                  |      }t	        j
                  di | 5 yw)a`  Lists available models.

    ```
    import pprint
    for model in genai.list_models():
        pprint.pprint(model)
    ```

    Args:
        page_size: How many `types.Models` to fetch per page (api call).
        client: You may pass a `glm.ModelServiceClient` instead of using the default client.

    Yields:
        `types.Model` objects.

    Nr0   r   )r   list_modelsr   r   r   r   r0   r   r-   s      r   r3   r3      sZ     * ~)+##i#8 )U##E*(%(()   AAc              #     K   |
t               }|j                  |       D ]3  }t        |      j                  |      }t	        j
                  |       5 yw)aj  Lists available models.

    ```
    import pprint
    for model in genai.list_tuned_models():
        pprint.pprint(model)
    ```

    Args:
        page_size: How many `types.Models` to fetch per page (api call).
        client: You may pass a `glm.ModelServiceClient` instead of using the default client.

    Yields:
        `types.TunedModel` objects.
    Nr2   )r   list_tuned_modelsr   r   r   r#   r4   s      r   r7   r7      sW     ( ~)+))I)> 4U##E*,,U334r5   
text_inputoutput)iddisplay_namedescriptiontemperaturetop_ptop_kepoch_count
batch_sizelearning_rate	input_key
output_keyr   c                  |
t               }t        j                  |       }t        |       }|j	                  d      rd|i} n(|j	                  d      rd||di} nt        d| d       t        j                  |||      }t        j                  ||	|
	      }t        j                  ||
      }t        j                  di | ||||||d}|j                  t        ||            }t        j                  j                  |      S )a
  Launches a tuning job to create a TunedModel.

    Since tuning a model can take significant time, this API doesn't wait for the tuning to complete.
    Instead, it returns a `google.api_core.operation.Operation` object that lets you check on the
    status of the tuning job, or wait for it to complete, and check the result.

    After the job completes you can either find the resulting `TunedModel` object in
    `Operation.result()` or `palm.list_tuned_models` or `palm.get_tuned_model(model_id)`.

    ```
    my_id = "my-tuned-model-id"
    operation = palm.create_tuned_model(
      id = my_id,
      source_model="models/text-bison-001",
      training_data=[{'text_input': 'example input', 'output': 'example output'},...]
    )
    tuned_model=operation.result()      # Wait for tuning to finish

    palm.generate_text(f"tunedModels/{my_id}", prompt="...")
    ```

    Args:
        source_model: The name of the model to tune.
        training_data: The dataset to tune the model on. This must be either:
          * A `glm.Dataset`, or
          * An `Iterable` of:
            *`glm.TuningExample`,
            * {'text_input': text_input, 'output': output} dicts, or
            * `(text_input, output)` tuples.
          * A `Mapping` of `Iterable[str]` - use `input_key` and `output_key` to choose which
            columns to use as the input/output
          * A csv file (will be read with `pd.read_csv` and handles as a `Mapping`
            above). This can be:
            * A local path as a `str` or `pathlib.Path`.
            * A url for a csv file.
            * The url of a Google Sheets file.
          * A JSON file - Its contents will be handled either as an `Iterable` or `Mapping`
            above. This can be:
            * A local path as a `str` or `pathlib.Path`.
        id: The model identifier, used to refer to the model in the API
          `tunedModels/{id}`. Must be unique.
        display_name: A human-readable name for display.
        description: A description of the tuned model.
        temperature: The default temperature for the tuned model, see `types.Model` for details.
        top_p: The default `top_p` for the model, see `types.Model` for details.
        top_k: The default `top_k` for the model, see `types.Model` for details.
        epoch_count: The number of tuning epochs to run. An epoch is a pass over the whole dataset.
        batch_size: The number of examples to use in each training batch.
        learning_rate: The step size multiplier for the gradient updates.
        client: Which client to use.

    Returns:
        A [`google.api_core.operation.Operation`](https://googleapis.dev/python/google-api-core/latest/operation.html)
    r   r%   r   r+   )tuned_modelr%   zNot understood: `source_model=`)rC   rD   )r@   rA   rB   )training_datahyperparameters)r;   r<   r=   r>   r?   tuning_task)tuned_model_idrF   r   )r   r   r   r.   r   r   encode_tuning_datar)   Hyperparameters
TuningTaskr(   create_tuned_modeldictr   CreateTunedModelOperationfrom_core_operation)source_modelrH   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   r   source_model_namebase_model_namerI   rJ   rF   r	   s                       r   rO   rO      s$   P ~)+#33LA),7O##I.$&78		%	%n	5 0-#
 	4|oQ7822zM ))#O
 ..#'K
 .. 
!K ))$bk*Z[I//CCINNr   c                    y Nr   rF   updatesr   s      r   update_tuned_modelrZ   :       	r   c                    y rW   r   rX   s      r   rZ   rZ   D  r[   r   c                   |
t               }t        | t              r| }t        |t              st	        dt        |             |j                  |      } t        |      }t        j                         }|j                         D ]  }|j                  j                  |        |j                         D ]  \  }}t        | ||        nt        | t        j                         rV|t#        d      | j$                  }|j                  |      }t'        j(                  |j*                  | j*                        }nt	        dt        |        d      |j-                  t        j.                  | |            }t1        j2                  |      S )zGPush updates to the tuned model. Only certain attributes are updatable.z]When calling `update_tuned_model(name:str, updates: dict)`,
`updates` must be a `dict`.
got: r   zfWhen calling `update_tuned_model(tuned_model:glm.TunedModel, updates=None)`,`updates` must not be set.zxFor `update_tuned_model(tuned_model:dict|glm.TunedModel)`,`tuned_model` must be a `dict` or a `glm.TunedModel`. Got a: `rG   )rF   update_mask)r   r&   r'   rP   r,   r   r   _flatten_update_pathsr   	FieldMaskkeyspathsappenditems_apply_updater)   r(   r   r   r
   
field_mask_pbrZ   UpdateTunedModelRequestr   r#   )	rF   rY   r   r   rf   pathvaluewasr!   s	            r   rZ   rZ   N  s    ~)++s#'4(W( 
 ,,$,7'0#--/
LLN 	*D##D)	*"==? 	4KD%+tU3	4	K	0- 
 $$$$/%00+//J
MMQR]M^L__`b
 	

 &&##TF ))&11r   c                    i }| j                         D ]F  \  }}t        |t              r,t        |      j                         D ]  \  }}||| d| <    B|||<   H |S )N.)rd   r&   rP   r_   )rY   new_updateskeyrj   sub_key	sub_values         r   r_   r_   ~  su    Kmmo %
UeT"&;E&B&H&H&J <"2;se1WI./<  %K% r   c                r    |j                  d      }|d d D ]  }t        | |      }  t        | |d   |       y )Nrm   )splitr*   setattr)thingri   rj   partsparts        r   re   re     s@    JJsOEcr
 %t$%E59e$r   c                j    |
t               }t        j                  |       }|j                  |       y )Nr   )r   r   r   delete_tuned_model)rF   r   r   s      r   rz   rz     s2     ~)+&&{3D
4(r   )r   model_types.AnyModelNameOptionsreturnz*model_types.Model | model_types.TunedModel)r   z model_types.BaseModelNameOptionsr|   zmodel_types.Model)r   !model_types.TunedModelNameOptionsr|   model_types.TunedModelrW   )r-   r{   r   glm.ModelServiceClient | None)r0   
int | Noner   r   r|   zmodel_types.ModelsIterable)r0   r   r   r   r|   zmodel_types.TunedModelsIterable)rS   r{   rH   zmodel_types.TuningDataOptionsr:   
str | Noner;   r   r<   r   r=   float | Noner>   r   r?   r   r@   r   rA   r   rB   r   rC   r'   rD   r'   r   r   r|   z$operations.CreateTunedModelOperation)rF   zglm.TunedModelrY   Noner   r   r|   r~   )rF   r'   rY   zdict[str, Any]r   r   r|   r~   )rF   zstr | glm.TunedModelrY   zdict[str, Any] | Noner   r   r|   r~   )rF   r}   r   r   r|   r   ) 
__future__r   typingr   r   google.ai.generativelanguageaigenerativelanguager)   google.generativeair   google.generativeai.clientr   google.generativeai.typesr   google.api_corer	   r
   google.protobufr   r   r   r   r.   r3   r7   rO   overloadrZ   r_   re   rz   r   r   r   <module>r      s   #   * * * ? 1 % , * 6:T
)T/T6 FJ ': 8<2
+22@ UY*4Q6 ,0)) *)  	)> ,044 *4 %	4@ #" $"!"&!,0rO1rO0rO 		rO
 rO rO rO rO rO rO rO  rO rO rO *rO  *!rOj  	 -1				 *		
 	 	 
 -1				 *		
 	 	 &*-2 -1	-2%-2"-2 *	-2
 -2`	% -1)2))) 
)r   