
    ~zg                     F    d dl Z d dlmZmZ d dlmZ d dlZ G d de      Zy)    N)ABCabstractmethod)loggerc                   ,    e Zd ZddZed        ZddZy)	AgentBasec                 .    || _         || _        || _        y N)namemax_retriesverbose)selfr
   r   r   s       tC:\Users\bruma\Desktop\finale\rulare ollama remote cu colab\AI-Agents-from-Scratch-using-Ollama\agents\agent_base.py__init__zAgentBase.__init__	   s    	&    c                      y r	    )r   argskwargss      r   executezAgentBase.execute   s    r   c                    d}|| j                   k  r	 | j                  rKt        j                  d| j                   d       |D ]#  }t        j
                  d|d    d|d           % t        j                  d|	      }|d
   d   }| j                  r%t        j                  d| j                   d|        |S t        d| j                   d| j                    d      # t        $ rD}|dz  }t        j                  d| j                   d| d| d| j                           Y d}~nd}~ww xY w|| j                   k  r1)aa  
        Calls the Llama model via Ollama and retrieves the response.

        Args:
            messages (list): A list of message dictionaries.
            temperature (float): Sampling temperature.
            max_tokens (int): Maximum number of tokens in the response.

        Returns:
            str: The content of the model's response.
        r   [z] Sending messages to Ollama:z  rolez: contentzllama3.2:3b)modelmessagesmessagez] Received response:    z] Error during Ollama call: z. Retry /Nz+] Failed to get response from Ollama after z	 retries.)
r   r   r   infor
   debugollamachat	Exceptionerror)	r   r   temperature
max_tokensretriesmsgresponsereplyes	            r   
call_llamazAgentBase.call_llama   sR    (((q<<KK!DII;.K LM' Kr#f+bY8H%IJK ";;'% !+I6<<KK!DII;.CE7 KL !DII;&QRVRbRbQcclmnn  q1q+Gs(SZR[[\]a]m]m\noppq) (((s   B(C" "	D/+:D**D/N)   T)gffffff?   )__name__
__module____qualname__r   r   r   r,   r   r   r   r   r      s!    
  $or   r   )r!   abcr   r   logurur   osr   r   r   r   <module>r5      s!     #  	.o .or   