
    j.                         d dl Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZ  e j                  e j                  d	      Z G d
 d      Z G d d      Zy)    N   )AsyncClientWrapperSyncClientWrapper)RequestOptions)OllamaConnectionTestResponse)OllamaModel   )AsyncRawOllamaClientRawOllamaClient.c            
           e Zd ZdefdZedefd       Zeddde	de
j                  e	   d	e
j                  e   de
j                  e   fd
Zeddde	de
j                  e	   d	e
j                  e   defdZy)OllamaClientclient_wrapperc                &    t        |      | _        y N)r   )r   _raw_clientselfr   s     t/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/rest_api/ollama/client.py__init__zOllamaClient.__init__   s    *.I    returnc                     | j                   S )z
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawOllamaClient
        r   r   s    r   with_raw_responsezOllamaClient.with_raw_response        r   Napi_keyrequest_optionsbase_urlr   r   c                V    | j                   j                  |||      }|j                  S )a  
        Fetches the list of models available from the Ollama instance. URL may be provided with or without /v1 suffix (e.g., http://localhost:11434 or http://localhost:11434/v1). The /v1 suffix will be automatically removed for model discovery. For actual LLM inference, use the URL with /v1 suffix for OpenAI-compatible endpoints.

        Parameters
        ----------
        base_url : str
            Base URL of the Ollama instance. May include /v1 suffix which will be automatically removed for connection testing. For inference, use the URL with /v1 suffix for OpenAI-compatible endpoints.

        api_key : typing.Optional[str]
            Optional API key for authenticated Ollama instances. If provided, will be sent as Bearer token in Authorization header.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[OllamaModel]
            Models retrieved successfully

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.ollama.list_models(base_url='http://localhost:11434/v1', )
        r    r   r   r   list_modelsdatar   r    r   r   	_responses        r   r$   zOllamaClient.list_models   s-    @ $$00(Get0u	~~r   c                V    | j                   j                  |||      }|j                  S )a  
        Validates that the provided Ollama URL is reachable. URL may be provided with or without /v1 suffix (e.g., http://localhost:11434 or http://localhost:11434/v1). The /v1 suffix will be automatically removed for connection testing. For inference, use the URL with /v1 suffix.

        Parameters
        ----------
        base_url : str
            Base URL of the Ollama instance. May include /v1 suffix which will be automatically removed for connection testing. For inference, use the URL with /v1 suffix for OpenAI-compatible endpoints.

        api_key : typing.Optional[str]
            Optional API key for authenticated Ollama instances. If provided, will be sent as Bearer token in Authorization header.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        OllamaConnectionTestResponse
            Connection test successful

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.ollama.test_connection(base_url='http://localhost:11434/v1', )
        r"   r   test_connectionr%   r&   s        r   r*   zOllamaClient.test_connectionA   s3    @ $$44w 5 
	 ~~r   )__name__
__module____qualname__r   r   propertyr   r   OMITstrtypingOptionalr   Listr   r$   r   r*    r   r   r   r      s    J*; J  ?     )-;?! ! %	!
  8! 
[	!!N )-;?# # %	#
  8# 
&#r   r   c            
           e Zd ZdefdZedefd       Zeddde	de
j                  e	   d	e
j                  e   de
j                  e   fd
Zeddde	de
j                  e	   d	e
j                  e   defdZy)AsyncOllamaClientr   c                &    t        |      | _        y r   )r
   r   r   s     r   r   zAsyncOllamaClient.__init__h   s    /~Nr   r   c                     | j                   S )z
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawOllamaClient
        r   r   s    r   r   z#AsyncOllamaClient.with_raw_responsek   r   r   Nr   r    r   r   c                r   K   | j                   j                  |||       d{   }|j                  S 7 w)a.  
        Fetches the list of models available from the Ollama instance. URL may be provided with or without /v1 suffix (e.g., http://localhost:11434 or http://localhost:11434/v1). The /v1 suffix will be automatically removed for model discovery. For actual LLM inference, use the URL with /v1 suffix for OpenAI-compatible endpoints.

        Parameters
        ----------
        base_url : str
            Base URL of the Ollama instance. May include /v1 suffix which will be automatically removed for connection testing. For inference, use the URL with /v1 suffix for OpenAI-compatible endpoints.

        api_key : typing.Optional[str]
            Optional API key for authenticated Ollama instances. If provided, will be sent as Bearer token in Authorization header.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[OllamaModel]
            Models retrieved successfully

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.ollama.list_models(base_url='http://localhost:11434/v1', )
        asyncio.run(main())
        r"   Nr#   r&   s        r   r$   zAsyncOllamaClient.list_modelsv   sA     F **66w 7 
 
	 ~~
   "757c                r   K   | j                   j                  |||       d{   }|j                  S 7 w)a  
        Validates that the provided Ollama URL is reachable. URL may be provided with or without /v1 suffix (e.g., http://localhost:11434 or http://localhost:11434/v1). The /v1 suffix will be automatically removed for connection testing. For inference, use the URL with /v1 suffix.

        Parameters
        ----------
        base_url : str
            Base URL of the Ollama instance. May include /v1 suffix which will be automatically removed for connection testing. For inference, use the URL with /v1 suffix for OpenAI-compatible endpoints.

        api_key : typing.Optional[str]
            Optional API key for authenticated Ollama instances. If provided, will be sent as Bearer token in Authorization header.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        OllamaConnectionTestResponse
            Connection test successful

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.ollama.test_connection(base_url='http://localhost:11434/v1', )
        asyncio.run(main())
        r"   Nr)   r&   s        r   r*   z!AsyncOllamaClient.test_connection   sA     F **::w ; 
 
	 ~~
r:   )r+   r,   r-   r   r   r.   r
   r   r/   r0   r1   r2   r   r3   r   r$   r   r*   r4   r   r   r6   r6   g   s    O*< O  #7     )-;?& & %	&
  8& 
[	!&X )-;?& & %	&
  8& 
&&r   r6   )r1   core.client_wrapperr   r   core.request_optionsr   %types.ollama_connection_test_responser   types.ollama_modelr   
raw_clientr
   r   castAnyr/   r   r6   r4   r   r   <module>rC      sJ     G 1 P , = v{{6::s#U Up] ]r   