
    OjK                        d Z ddlmZ ddlZddlZddlZej                  j                  dd      j                  d      Z
dZdZdd	Zed
dddf	 	 	 	 	 	 	 ddZy)u  Thin DeepSeek (OpenAI-compatible) chat client.

Cheap flagship reasoning for the parts of the brain that need real judgment the
tiny local model can't do — auto-supersession, and later the nightly reflection
engine (insights, opportunities, community summaries, goal-nudges).

Key in .env as DEEPSEEK_API_KEY (permanent 75%-off V4 pricing). Models:
  deepseek-v4-flash — cheap, default for high-volume judging
  deepseek-v4-pro   — flagship (~Opus), for the creative reflection passes
    )annotationsNDEEPSEEK_URLzhttps://api.deepseek.com/zdeepseek-v4-flashzdeepseek-v4-proc                 T    t        t        j                  j                  dd            S )NDEEPSEEK_API_KEY )boolosenvironget     </Users/ahmed/devFolder/Ultron/claude-voice/voice/deepseek.py	availabler      s    

12677r   g        i   Z   c                   t         j                  j                  dd      }|st        d      g }|r|j	                  d|d       |j	                  d| d       t        j                  ||||dd      j                         }t        j                  j                  t        d	z   |d
d| d      }	t        j                  j                  |	|      5 }
t        j                  |
j                               }ddd       j                  d      xs i gd   j                  d      xs i j                  dd      j                         S # 1 sw Y   SxY w)zFSingle-turn completion; returns the assistant text. Raises on failure.r   r   zDEEPSEEK_API_KEY not setsystem)rolecontentuserF)modelmessagestemperature
max_tokensstreamz/chat/completionszapplication/jsonzBearer )zContent-TypeAuthorization)dataheaders)timeoutNchoicesr   messager   )r
   r   r   RuntimeErrorappendjsondumpsencodeurllibrequestRequest_URLurlopenloadsreadstrip)promptr   r   r   r   r   keymsgsbodyreqros               r   chatr6      s.    **..+R
0C566DX&9:KKF34::4&1!&( ))/ 	 ..
 
 ""!3$+C5/3 ! 4C 
		W		5JJqvvx  
6UU9%"q)--i8>Bc)R ) 
6	5s   $E		E)returnr	   )r/   strr   r8   r   floatr   intr   z
str | Noner   r:   r7   r8   )__doc__
__future__r   r$   r
   urllib.requestr'   r   r   rstripr*   FLASHPROr   r6   r   r   r   <module>rA      s{   	 #  	 	zz~~n&@AHHM8 $)sd)))3))")r   