
    3i=                     d    S SK r S SKrS SKrS SKJr  S	S jrS	S jrS	S jrS	S jr	S	S jr
S	S jrg)
    N)MorphEmbeddingFunctionc                  *   [         R                  R                  S5      c  [        R                  " S5        [        SS9n SS/nU " U5      nUc   e[        U5      S:X  d   e[        S	 U 5       5      (       d   e[        S
 U 5       5      (       d   eg)z8Test Morph embedding function when API key is available.MORPH_API_KEYNMORPH_API_KEY not setmorph-embedding-v2)
model_namez-def hello_world():
    print('Hello, World!')z?class Calculator:
    def add(self, a, b):
        return a + b   c              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7f)N)
isinstancenpndarray.0embs     X/home/james-whalen/.local/lib/python3.13/site-packages/chromadb/test/ef/test_morph_ef.py	<genexpr>=test_morph_embedding_function_with_api_key.<locals>.<genexpr>   s     Ajsz#rzz**js   ')c              3   >   #    U  H  n[        U5      S :  v   M     g7f)r   N)lenr   s     r   r   r      s     2zs3x!|zs   )osenvirongetpytestskipr   r   all)efcode_snippets
embeddingss      r   *test_morph_embedding_function_with_api_keyr   	   s    	zz~~o&.+,	'
B 	9KM
 M"J!!!z?aAjAAAAA2z22222    c                  :   [         R                  R                  S5      c  [        R                  " S5        [        SSSSS9n S/nU " U5      nUc   e[        U5      S	:X  d   e[        US
   [        R                  5      (       d   e[        US
   5      S
:  d   eg)z5Test Morph embedding function with custom parameters.r   Nr   r   https://api.morphllm.com/v1floatr   api_baseencoding_formatapi_key_env_varz$function add(a, b) { return a + b; }   r   )
r   r   r   r   r   r   r   r   r   r   )r   code_snippetr   s      r   4test_morph_embedding_function_with_custom_parametersr*      s    	zz~~o&.+,	'.'	
B ;;LL!J!!!z?ajmRZZ0000z!}!!!r    c                      SSK n [	        SSSSS9nUR                  5       nS	U;   d   eS
U;   d   eSU;   d   eSU;   d   eUS	   S:X  d   eUS
   S:X  d   eUS   S:X  d   eUS   S:X  d   e[        R                  " U5      nUR                  5       nX$:X  d   eg! [         a    [        R                  " S5         Nf = f)zKTest that Morph embedding function configuration can be saved and restored.r   Nopenai package not installedr   r"   r#   r   r$   r   r%   r&   r'   )openaiImportErrorr   r   r   
get_configbuild_from_config)r-   r   confignew_ef
new_configs        r   .test_morph_embedding_function_config_roundtripr4   5   s   4 
 '.'	
B ]]_F 6!!!&&&&&& ,#7777*!>>>>#$///#$777 $55f=F""$J =  4234s   B  B?>B?c                  :    [         R                  " 5       S:X  d   eg)z8Test that Morph embedding function returns correct name.morphN)r   name r    r   "test_morph_embedding_function_namer9   Z   s    !&&(G333r    c                       SSK n [	        SSS9nUR                  5       S:X  d   eUR                  5       nSU;   d   eSU;   d   eS	U;   d   eg! [         a    [        R                  " S5         Nkf = f)
z<Test that Morph embedding function supports expected spaces.r   Nr,   r   r   r   r'   cosinel2ip)r-   r.   r   r   r   default_spacesupported_spaces)r-   r   r@   s      r   $test_morph_embedding_function_spacesrA   _   s    4 
 ''
B ))) **,''''########  4234s   A  A21A2c                      SSS.n [         R                  " U 5        SS0n[        R                  " [        5         [         R                  " U5        SSS5        g! , (       d  f       g= f)zETest that Morph embedding function validates configuration correctly.r   r   r;   r   N)r   validate_configr   raises	Exception)valid_configinvalid_configs     r   -test_morph_embedding_function_validate_configrH   u   sX     +*L **<8 	*N
 
y	!..~> 
"	!	!s   A
A()returnN)r   r   numpyr   ;chromadb.utils.embedding_functions.morph_embedding_functionr   r   r*   r4   r9   rA   rH   r8   r    r   <module>rL      s2    	  
3,"," J4
$,?r    