
    +#h                     :    d dl Z d dlmZ d dlmZ  G d de      Zy)    N)Union)LMc                        e Zd ZdZd	deee   eeef   f   def fdZ	d
deeeeeef      f   fdZ
ddZdefdZ xZS )DummyLMz/Dummy language model for unit testing purposes.answersfollow_examplesc                 N    t         |   d       d| _        || _        || _        y)aD  Initializes the dummy language model.

        Parameters:
        - answers: A list of strings or a dictionary with string keys and values.
        - follow_examples: If True, and the prompt contains an example exactly equal to the prompt,
                           the dummy model will return the next string in the list for each request.
        If a list is provided, the dummy model will return the next string in the list for each request.
        If a dictionary is provided, the dummy model will return the value corresponding to the key that matches the prompt.
        zdummy-modeldummyN)super__init__providerr   r   )selfr   r   	__class__s      Q/var/www/html/sandstorm/venv/lib/python3.12/site-packages/dsp/modules/dummy_lm.pyr   zDummyLM.__init__   s(     	'.    returnc                 >   dg i}t        |      D ]f  }d}| j                  r{j                  d      d   }j                  d      ^}}	}
}dj                  |
      }t	        j
                  |dz   |      }|r|d   }t        d| d|       nt        d	|       |t        | j                  t              r.t        fd
| j                  j                         D        d      }n;t        | j                        dkD  r#| j                  d   }| j                  dd | _        |d}|d   j                  |dd       d\  }}}t        d       t        d       t        | | |        t        d       i |||d}| j                  j                  |       |S )z/Generates a dummy response based on the prompt.choicesN
z
---
z\s*(.*)z'DummyLM got found previous example for z with value answer=z2DummyLM couldn't find previous example for prefix=c              3   2   K   | ]  \  }}|v s|  y w)N ).0kvprompts      r   	<genexpr>z(DummyLM.basic_request.<locals>.<genexpr>/   s     "UAf1"Us   r      zNo more responseszsimulated completion)textfinish_reason)z[91mz[92mz[0mz=== DummyLM === )endz===)r   responsekwargs
raw_kwargs)ranger   splitjoinrefindallprint
isinstancer   dictnextitemslenappendhistory)r   r   nr$   dummy_response_answerprefix_instructions_formatexamples_outputexamples_strpossible_answersREDGREENRESEThistory_entrys    `                r   basic_requestzDummyLM.basic_request   s   #Rq '	AF##d+B/=C\\)=T:w7#yy2#%::fz.A<#P # .b1FCF8K_X^W`abOyQR~dllD1!"U1C1C1E"UW[\F4<<(1,!%a'+||AB'7~, 9%,,"%; !BC#$&b!SE&%)*%LO'	V & 	
 	M*r   c                 b     | j                   |fi |}|d   }|D cg c]  }|d   	 c}S c c}w )zRetrieves dummy completions.r   r   )rB   )r   r   _only_completed_return_sortedr$   r#   r   choices           r   __call__zDummyLM.__call__Q   s=    %4%%f779% .556v555s   ,c                 d    | j                   |   d   dz   | j                   |   d   d   d   d   z   S )z,Get the prompt + anwer from the ith message.r    r#   r   r   r   )r2   )r   indexs     r   	get_convozDummyLM.get_convoY   s@    ||E"8,s2T\\%5H5TU^5_`a5bci5jjjr   )F)r   )TF)__name__
__module____qualname____doc__r   liststrr-   boolr   rB   rG   rK   __classcell__)r   s   @r   r   r      sg    9/d3ic3h&? @ /SW /5d3T#s(^@T;T6U 5n6k# kr   r   )r)   typingr   dsp.modulesr   r   r   r   r   <module>rV      s    	  Skb Skr   