o
    ưi                     @  s   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
 d
eZdS )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                      s:   e Zd ZdZ	dd fddZdddZdddZ  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)
    Ningest_options'RAGIngestOptions'routerOptional['Router']c                   s   t  j||d d S )N)r   r   )super__init__)selfr   r   	__class__ ]/home/app/Keep/.python/lib/python3.10/site-packages/litellm/rag/ingestion/openai_ingestion.pyr       s   zOpenAIRAGIngestion.__init__chunks	List[str]returnOptional[List[List[float]]]c                   s   dS )z
        OpenAI handles embedding internally - skip this step.

        Returns:
            None (OpenAI embeds when files are attached to vector store)
        Nr   )r   r   r   r   r   embed'   s   zOpenAIRAGIngestion.embedfile_contentOptional[bytes]filenameOptional[str]content_type
embeddings#Tuple[Optional[str], Optional[str]]c              	     s   | j d}| j d}| j d}| j d}	|s8|r"d|dnd}
t| jp)dd	|
||	d
I dH }|d}d}|rl|rl|rltj|||pGdfdd	||	dI dH }|j}t||d	tt	t
ttf  | j||	dI dH  ||fS )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_baseZlast_active_at)anchordaysNzlitellm-rag-ingestZopenai)namecustom_llm_providerexpires_afterr(   r)   idzapplication/octet-streamZ
assistants)filepurposer-   r(   r)   )r&   Zfile_idr-   chunking_strategyr(   r)   )Zvector_store_configgetvector_store_acreateZingest_namelitellmZacreate_filer/   vector_store_file_acreater	   r   r   strr   r2   )r   r   r!   r#   r   r$   r&   r'   r(   r)   r.   Zcreate_responseZresult_file_idZfile_responser   r   r   store4   sD   
	zOpenAIRAGIngestion.store)N)r   r   r   r   )r   r   r   r   )r   r    r!   r"   r#   r"   r   r   r$   r   r   r%   )__name__
__module____qualname____doc__r   r   r8   __classcell__r   r   r   r   r      s    
r   )r<   
__future__r   typingr   r   r   r   r   r   r	   r5   Z$litellm.rag.ingestion.base_ingestionr
   Zlitellm.vector_store_files.mainr   r6   Zlitellm.vector_stores.mainr4   r   Zlitellm.types.ragr   r   r   r   r   r   <module>   s    $