Ë
    uPêjý  ã                  óŠ   — d Z ddlmZ ddlmZmZmZmZ ddlZddl	m
Z
 ddlmZ ddlmZ erddlmZ ddlmZ  G d	„ d
e
«      Zy)zÊ
OpenAI-specific RAG Ingestion implementation.

OpenAI handles embedding internally when files are attached to vector stores,
so this implementation skips the embedding step and directly uploads files.
é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚFinalÚcastN)ÚBaseRAGIngestion)Úacreate)ÚRouter)ÚRAGIngestOptionsc                  óh   ‡ — e Zd ZdZdZ	 d	 	 	 dˆ fd„Z	 	 	 	 dd„Z	 d	 	 	 	 	 	 	 	 	 	 	 	 	 d	d„Zˆ xZS )
ÚOpenAIRAGIngestiona  
    OpenAI-specific RAG ingestion.

    Key differences from base:
    - Embedding is handled by OpenAI when attaching files to vector stores
    - Files are uploaded and attached to vector stores directly
    - Chunking is done by OpenAI's vector store (uses 'auto' strategy)
    Tc                ó(   •— t         ‰| �  ||¬«       y )N)Úingest_optionsÚrouter)ÚsuperÚ__init__)Úselfr   r   Ú	__class__s      €úk/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/rag/ingestion/openai_ingestion.pyr   zOpenAIRAGIngestion.__init__"   s   ø€ ô
 	‰Ñ¨¸vÐÕFó    c              ƒ  ó   K  — y­w)z¢
        OpenAI handles embedding internally - skip this step.

        Returns:
            None (OpenAI embeds when files are attached to vector store)
        N© )r   Úchunkss     r   ÚembedzOpenAIRAGIngestion.embed)   s   è ø€ ð ùs   ‚c           
   ƒ  ó*  K  — | j                   j                  d«      }| j                   j                  d«      }| j                   j                  d«      }	| j                   j                  d«      }
|r|st        d«      ‚|s@|rd|dœnd}t        | j                  xs d	d
||	|
¬«      ƒ d{  –—† }|j                  d«      }|rG|rEt        ||d
t        t        t        t        f   dz  | j                  «      |	|
¬«      ƒ d{  –—†  ||fS d}|�z|rx|rvt        j                  |||xs dfdd
|	|
¬«      ƒ d{  –—† }|j                  }t        ||d
t        t        t        t        f   dz  | j                  «      |	|
¬«      ƒ d{  –—†  ||fS 7 Œà7 ŒŒ7 ŒY7 Œ­w)ad  
        Store content in OpenAI vector store.

        OpenAI workflow:
        1. Create vector store (if not provided)
        2. Upload file to OpenAI
        3. Attach file to vector store (OpenAI handles chunking/embedding)

        Args:
            file_content: Raw file bytes
            filename: Name of the file
            content_type: MIME type
            chunks: Ignored - OpenAI handles chunking
            embeddings: Ignored - OpenAI handles embedding
            existing_file_id: Existing OpenAI file ID to attach

        Returns:
            Tuple of (vector_store_id, file_id)
        Úvector_store_idÚttl_daysÚapi_keyÚapi_basez>vector_store_id is required when ingesting an existing file_idÚlast_active_at)ÚanchorÚdaysNzlitellm-rag-ingestÚopenai)ÚnameÚcustom_llm_providerÚexpires_afterr   r   Úid)r   Úfile_idr%   Úchunking_strategyr   r   zapplication/octet-streamÚ
assistants)ÚfileÚpurposer%   r   r   )Úvector_store_configÚgetÚ
ValueErrorÚvector_store_acreateÚingest_nameÚvector_store_file_acreater   ÚdictÚstrr   r)   ÚlitellmÚacreate_filer'   )r   Úfile_contentÚfilenameÚcontent_typer   Ú
embeddingsÚexisting_file_idr   r   r   r   r&   Úcreate_responseÚresult_file_idÚfile_responses                  r   ÚstorezOpenAIRAGIngestion.store6   sÐ  è ø€ ð8 ×2Ñ2×6Ñ6Ð7HÓIˆØ×2Ñ2×6Ñ6°zÓBˆð ×1Ñ1×5Ñ5°iÓ@ˆØ×2Ñ2×6Ñ6°zÓBˆá¡OÜÐ]Ó^Ð^ñ ÙU]Ð.>ÈÒ#QÐcgˆMÜ+?Ø×%Ñ%Ò=Ð)=Ø$,Ø+ØØ!ô,÷ &ˆOð .×1Ñ1°$Ó7ˆOá¡Ü+Ø /Ø(Ø$,Ü"&¤t¬C´¨H¡~¸Ñ'<¸d×>TÑ>TÓ"UØØ!ô÷ ð ð #Ð$4Ð4Ð4ð ˆØÐ#©±_ä)0×)=Ñ)=àØ Ø Ò>Ð$>ðð
 %Ø$,ØØ!ô
*÷ 
$ˆMð +×-Ñ-ˆNô ,Ø /Ø&Ø$,Ü"&¤t¬C´¨H¡~¸Ñ'<¸d×>TÑ>TÓ"UØØ!ô÷ ð ð  Ð.Ð.ð_&øðøð
$øðúsJ   ‚B(FÂ*FÂ+AFÄ FÄ4FÄ5FÄ6AFÆFÆ	FÆFÆFÆF)N)r   r   r   zRouter | None)r   ú	list[str]Úreturnúlist[list[float]] | None)r7   zbytes | Noner8   ú
str | Noner9   rC   r   r@   r:   rB   r;   rC   rA   ztuple[str | None, str | None])	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úsupports_existing_file_idr   r   r?   Ú__classcell__)r   s   @r   r   r      sœ   ø„ ñð !%Ðð
 !%ðGà(ðGð õGðàðð 
"óð( (,ðX/à"ðX/ð ðX/ð !ð	X/ð
 ðX/ð -ðX/ð %ðX/ð 
'÷X/r   r   )rG   Ú
__future__r   Útypingr   r   r   r   r5   Ú$litellm.rag.ingestion.base_ingestionr   Úlitellm.vector_store_files.mainr	   r2   Úlitellm.vector_stores.mainr0   r
   Úlitellm.types.ragr   r   r   r   r   ú<module>rP      s9   ðñõ #ç 2Ó 2ã Ý AÝ PÝ FáÝÝ2ôx/Ð)õ x/r   