ó
    ÀÜji  ã                   óx   • S r SSKrSSKrSSKrSSKrSSKr\R                  R                  SS5      r	S r
SS jrg)a˜  gem.py -- one Gemini call (text, optional PNGs), so the reef's small judgments don't spend the Claude subscription (Ivy, Oct 23
2026: "We could route thru gemini to offgas the usage"). Same shape as favorites/haiku.py: ask(text, images, max_tokens) -> (text,
usage). Tries each Gemini key on the machine (they are different Google projects with separate daily quotas -- see ~/ask_gemini.py).
Written by Iris.é    NÚ	GEM_MODELzgemini-3.5-flash-litec                  óT  • / n S HŸ  n[         R                  R                  U5      n[         R                  R                  U5      (       d  MH  [	        U5      R                  5       R                  5       nUR                  S5      (       d  M‡  X0;  d  MŽ  U R                  U5        M¡     U $ )N)z~/.gemini_api_keyz~/.gemini_keyÚAIza)	ÚosÚpathÚ
expanduserÚexistsÚopenÚreadÚstripÚ
startswithÚappend)ÚoutÚpthÚfÚks       Ú)/home/ivy/projects/brick_reef/reef/gem.pyÚ_keysr   	   st   € Ø
€CÛ5ˆÜ�G‰G×Ñ˜sÓ#ˆÜ�7‰7�>‰>˜!×ÓÜ�Q“—‘“×$Ñ$Ó&ˆAØ�|‰|˜F×#Ó#¨­°c·j±jÀ¶mñ	 6ð
 €Jó    c                 óØ  • U Vs/ s HD  nSS[         R                  " [        US5      R                  5       5      R	                  5       S.0PMF     nnUR                  SU 05        SU0/[        US5      SS	.S
.nS n[        5        HÑ  n	SU=(       d    [         SU	 3n
 [        R                  R                  U
[        R                  " U5      R                  5       SS0S9n[        R                  " [        R                  R!                  X´S95      nSR#                  S US   S   S   R%                  S/ 5       5       5      nXÜR%                  S0 5      4s  $    [-        U=(       d    S5      es  snf ! [        R&                  R(                   aW  nUR*                   SUR                  5       R	                  5       S S  3nUR*                  S;   a   S nAGMS  [-        U5      eS nAff = f)NÚinline_dataz	image/pngÚrb)Ú	mime_typeÚdataÚtextÚpartsé   gš™™™™™É?)ÚmaxOutputTokensÚtemperature)ÚcontentsÚgenerationConfigz8https://generativelanguage.googleapis.com/v1beta/models/z:generateContent?key=zcontent-typezapplication/json)r   Úheaders)ÚtimeoutÚ c              3   óD   #   • U  H  oR                  S S5      v •  M     g7f)r   r$   N)Úget)Ú.0Úps     r   Ú	<genexpr>Úask.<locals>.<genexpr>   s   é € ÐbÒ3a¨aŸ™˜f b×)Ð)Ò3aùs   ‚ Ú
candidatesr   ÚcontentÚusageMetadataÚ éÈ   )i­  i“  zno Gemini key)Úbase64Ú	b64encoder
   r   Údecoder   Úmaxr   ÚMODELÚurllibÚrequestÚRequestÚjsonÚdumpsÚencodeÚloadÚurlopenÚjoinr&   ÚerrorÚ	HTTPErrorÚcodeÚRuntimeError)r   ÚimagesÚ
max_tokensÚmodelr#   r(   r   ÚbodyÚlastÚkeyÚurlÚrÚjÚtÚes                  r   ÚaskrM      sÐ  € ñ |Bó  Cò  |BÐvwˆm¨;Ä×@PÒ@PÔQUÐVWÐY]ÓQ^×QcÑQcÓQeÓ@f×@mÑ@mÓ@oÑpÓqñ  |B€Eð  CØ	‡L�L�&˜$�Ô ð " 5Ð)Ð*ÔTWÐXbÐdfÓTgÐx{Ñ@|Ñ}€DØ€DÜŽwˆØHÈÏÔRWÐHXÐXmÐnqÐmrÐsˆð	%Ü—‘×&Ñ& s´·²¸DÓ1A×1HÑ1HÓ1JÐUcÐewÐTxÐ&ÐyˆAÜ—	’	œ&Ÿ.™.×0Ñ0°Ð0ÐDÓEˆAØ—‘Ñb°1°\±?À1Ñ3EÀiÑ3P×3TÑ3TÐU\Ð^`Ô3aÓbÓbˆAØ—e‘e˜O¨RÓ0Ð0Ò0ñ ô �t×.˜Ó
/Ð/ùò# Cøô �|‰|×%Ñ%ó 	%Ø—f‘f�X˜Q˜qŸv™v›xŸ™Ó0°°#Ð6Ð7Ð8ˆDØ�v‰v˜Ó#¦XÜ˜tÓ$Ð$ûð	%ús&   …AE/ÂB7E4Å4G)ÆA G$ÇG$Ç$G))© i�  Né   )Ú__doc__r   r8   r0   Úurllib.requestr5   Úurllib.errorÚenvironr&   r4   r   rM   rN   r   r   Ú<module>rT      s4   ðñ÷ 6× 5Ó 5à
�
‰
�‰�{Ð$;Ó<€òõ0r   