
    b"\i                    L    d Z ddlmZ ddlZddlmZmZmZmZ dZ	 G d d      Z
y)zpMinimal OpenAI client using httpx.

We intentionally avoid adding a hard dependency on the official OpenAI SDK.
    )annotationsN)AnyDictListOptionalz*https://api.openai.com/v1/chat/completionsc                       e Zd ZdddZdddZy)OpenAIClientc                H    |st        d      || _        || _        || _        y )NzOpenAI API key is required)
ValueErrorapi_keymodeltimeout)selfr   r   r   s       /app/app/llm/openai_client.py__init__zOpenAIClient.__init__   s&    9::
    c                >   d| j                    dd}| j                  |||d}t        j                  | j                        5 }|j                  t        ||      }|j                          |j                         }d d d        d   d   d	   d
   S # 1 sw Y   xY w)NzBearer zapplication/json)AuthorizationzContent-Type)r   messagestemperature
max_tokens)r   )headersjsonchoicesr   messagecontent)	r   r   httpxClientr   postOPENAI_CHAT_URLraise_for_statusr   )	r   r   r   r   r   payloadclientrdatas	            r   chatzOpenAIClient.chat   s    &t||n5.

 ZZ &$	#
 \\$,,/6OW7KA 668D 0 Iq!),Y77 0/s   9BBN)zgpt-4o-minig      N@)r   strr   r'   r   float)gffffff?i  )r   zList[Dict[str, str]]r   r(   r   intreturnr'   )__name__
__module____qualname__r   r&    r   r   r	   r	      s    8r   r	   )__doc__
__future__r   r   typingr   r   r   r   r    r	   r.   r   r   <module>r2      s'   
 #  , ,>8 8r   