a Hkfd @sddlmZddlZddlmZddlmZmZddlZddl m Z ddl Tddl TddlmZdd d d d d Zd ddddZddddddZeddddNZedddd ZeZeZWdn1s0YWdn1s0YddZejjjZdS)) annotationsN)Prompt)ListTuple)utils)*) render_latexrz List[str])prompt text_chunksreturncCsNtddd|D}ddt|D}d|}|j|ddd}||S)Nu%Compacting text chunks...🚀🚀🚀cSsg|]}|r|qS)strip).0cr r ;/Users/treediagram/dev/ChuanhuChatGPT/modules/overwrites.py z'compact_text_chunks..cSs$g|]\}}d|dd|qS)[z] r )rindexrr r rrrz r)padding)loggingdebug enumeratejoinZget_text_splitter_given_promptZ split_text)selfr r Z combined_strZ text_splitterr r rcompact_text_chunks s   rz=List[List[str | Tuple[str] | Tuple[str, str] | None] | Tuple]zList[List[str | Dict | None]])yr cCsz|dur gSg}|D]`}t|ttfs4Jd|t|dksNJd||||dd||ddgq|S) a Parameters: y: List of lists representing the message and response pairs. Each message and response should be a string, which may be in Markdown format. It can also be a tuple whose first element is a string filepath or URL to an image/video/audio, and second (optional) element is the alt text, in which case the media file is displayed. It can also be None, in which case that message is not displayed. Returns: List of lists representing the message and response. Each message and response will be a string of HTML, or a dictionary with media information. Or None if the message is not to be displayed. Nz6Expected a list of lists or list of tuples. Received: zNExpected a list of lists of length 2 or list of tuples of length 2. Received: ruserrbot) isinstancetuplelistlenappend_postprocess_chat_messages)rrprocessed_messages message_pairr r r postprocesss&  r)zstr | Tuple | List | Nonestrzstr | Dict | None) chat_message message_typer cCs|dur dSt|ttfrZ|d}t|}||}||t|dkrN|dnddddSt|tr|dkr~t|st |}n|dkrt|st |}|St d|dS)NrrT)name mime_typealt_textdatais_filer rz'Invalid message for Chatbot component: ) r!r"r# client_utils get_mimetypemake_temp_copy_if_neededr$r*detect_converted_markconvert_mdtext convert_asis ValueError)rr+r,filepathr.r r rpostprocess_chat_messages4s*    r:z./assets/custom.jsrzutf-8)encodingz./assets/external-scripts.jscs@tddtdtdtr&d7fdd}|tjj_dS)NzReloading javascript...zaG cs6t|i|}|jddd|_||S)Nszutf8)GradioTemplateResponseOriginalbodyreplaceencode init_headers)argskwargsresjsr rtemplate_response]sz,reload_javascript..template_response)printcustomJSexternalScriptsrgrroutes templatesTemplateResponse)rHr rFrreload_javascriptUs  rP) __future__rrZ llama_indexrtypingrr mdtex2html gradio_clientrr2modules.presetsZmodules.llama_funcmodules.configrrr)r:openff1readrJrKrPrLrMrNrOr>r r r rs&      D