
    iT                        d Z ddlmZ ddlmZmZmZ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DictListOptionalTuplecastN)BaseRAGIngestion)acreate)Router)RAGIngestOptionsc                  ^     e Zd ZdZ	 d	 	 	 d fdZ	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 	 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)
    c                (    t         |   ||       y )N)ingest_optionsrouter)super__init__)selfr   r   	__class__s      w/Users/manta/Documents/Projects/TheRoad-I1/.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      }	|s@|rd|dnd}
t        | j                  xs dd	|
||	
       d{   }|j                  d      }d}|r~|r||rzt	        j
                  |||xs dfdd	||	       d{   }|j                  }t        ||d	t        t        t        t        t        f      | j                        ||	       d{    ||fS 7 7 [7 w)a$  
        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

        Returns:
            Tuple of (vector_store_id, file_id)
        vector_store_idttl_daysapi_keyapi_baselast_active_at)anchordaysNzlitellm-rag-ingestopenai)namecustom_llm_providerexpires_afterr!   r"   idzapplication/octet-stream
assistants)filepurposer(   r!   r"   )r   file_idr(   chunking_strategyr!   r"   )vector_store_configgetvector_store_acreateingest_namelitellmacreate_filer*   vector_store_file_acreater
   r   r   strr   r/   )r   file_contentfilenamecontent_typer   
embeddingsr   r    r!   r"   r)   create_responseresult_file_idfile_responses                 r   storezOpenAIRAGIngestion.store4   so    4 22667HI++//
; **..y9++//
; BJ+X>PT  %9%%=)=$,+!% O .11$7O H")"6"6  >$>
 %$,!
# 
M +--N , /&$,"&T#s(^,d.D.D#  !	 	 	 ..M
	s8   BD=D7AD=D9AD=.D;/	D=9D=;D=)N)r   z'RAGIngestOptions'r   zOptional['Router'])r   	List[str]returnOptional[List[List[float]]])r8   zOptional[bytes]r9   Optional[str]r:   rC   r   r@   r;   rB   rA   z#Tuple[Optional[str], Optional[str]])__name__
__module____qualname____doc__r   r   r?   __classcell__)r   s   @r   r   r      s     &*G*G #G 
%L/%L/  L/ $	L/
 L/ 0L/ 
-L/r   r   )rG   
__future__r   typingr   r   r   r   r   r	   r
   r4   $litellm.rag.ingestion.base_ingestionr   litellm.vector_store_files.mainr   r6   litellm.vector_stores.mainr2   r   litellm.types.ragr   r   r   r   r   <module>rO      s<    # H H H  A P F2j/) j/r   