>3f= ddlZddlmZmZddlmZmZddlZddlm Z ddl m Z GddeZ ej Gdd Zed d d d e jdZeddddde jddZeddddde jddZeddddde jddZeddddde jdZed d!dde jd"Zed d dde jdZed#d dde jdd$%Zed dddde jddZed#ddde jddd&'Zed dddde jd dZed(dddde jdZed)d*d+dde jd,Z ed-d.d/dde jd0Z!e Z"id1ed2eded3ed4ed5ed6ed7ed8ed9ed:ed$ed;ed&edN)autoEnum)ListTuple)BytesIO)ImagecveZdZdZeZeZeZeZeZ dS)SeparatorStylezDifferent separator style.N) __name__ __module__ __qualname____doc__rSINGLETWOMPTPLAINLLAMA_2W/opt/hpcaas/.mounts/fs-036153e63d56f4dc2/home/jiuhai/llama3-mlp3x/llava/conversation.pyr r sK$$ TVVF $&&C $&&C DFFEdffGGGrr ceZdZUdZeed<eeed<eeeed<eed<ej Z eed<dZ eed<d Z eed <d Z eed <d Zeed<dZdZddZddZdZdZdZd S) Conversationz,A class that keeps all conversation history.systemrolesmessagesoffset sep_style###sepNsep2UnknownversionF skip_nextc|j}t|dkrt|ddtur|j}|d\}}|ddd}d|jvrN||f|d<|d|j ddf|d|j ddfn |d|zf|d<|j tj krS|j |jz}|D]?\}}|r0t|tur|\}}}||d z|z|jzz }7||d zz }@nk|j tjkrv|j|jg}|j |dz}t#|D]F\} \}}|r4t|tur|\}}}||d z|z|| d zzz }>||d zz }Gn|j tjkrM|j |jz}|D]9\}}|r-t|tur|\}}}|||z|jzz }4||z }:n~|j tjkrd } d } d}t#|D]\} \}}| dkr'|s Jd||j dks Jd|rkt|tur|\}}}| dkr| |j |z}| d zdkr| |}||j|zz }|d|zdz|jzz }|dz }||j}n|j tjkrc|j|jg}|j }t#|D]=\} \}}|r.t|tur|\}}}|||| d zzz }8|dz }>nt-d|j |S)Nrmmtagzz Received.z z: :c8t|dkrd|dn|S)Nrz<> z <> )lenmsgs rz)Conversation.get_prompt..Ks'c#hhQRll#Bs#B#B#B#BX[rcd|dS)Nz[INST] z [/INST]rr-s rr/z)Conversation.get_prompt..Ls$;c$;$;$;rz first message should not be nonez#first message should come from user zInvalid style: )rr,typetuplecopyreplacestripr"insertrrr rrrrr enumeraterrlstripr ValueError) selfr init_roleinit_msgretrolemessage_sepsiwrap_sys wrap_insts r get_promptzConversation.get_prompt!s= x==1  hqk!n!5!5!>!>}))++H"*1+"2"2"4"4 Ix{**9b99??AAH$,&&((3 DJqM3K#LMMMDJqM;#?@@@@(+*@A >^2 2 2+(C!) & & g&G}}--(/ A4$;048;;CC4#:%CC  &^~1 1 1Hdi(D+Q'C&/&9&9 & &"?D'&G}}--(/ A4$;04A;>>CC4#:%CC  &^~1 1 1+(C!)  g G}}--(/ A4'>DH44CC4KCC  ^~5 5 5[[H;;IC&/&9&9  "?D'66"FF$FFF74:a=0002W000 G}}--(/ AAvv$+)>)>)Hw1uzz"+)G"4"4tx'11sW}s2TY>>2ICC**TX&&CC ^~3 3 3Hdi(D+C&/&9&9  "?D'G}}--(/ A7T!a%[00CC2ICC  ?t~??@@ @ rc>|j||gdS)N)rappend)r;r?r@s rappend_messagezConversation.append_messagens" dG_-----rPNG@c|dkrd d}||}n3|dvrn.|dkr|d}ntd|t|j|krt|jt |j} }|| z } t t || z || } t | | z} |j\} }|| kr| | } }n| | } }|| |f}|r|St }|||tj |  }|S) NPadzthc&|j\}}||kr|S||kr=tj|j||f|}||d||z dzf|Stj|j||f|}||||z dzdf|S)Nrr*)sizernewmodepaste)pil_imgbackground_colorwidthheightresults r expand2squarez1Conversation.process_image..expand2squaress ' vF??"NV^^"Yw|eU^EUVVFLL1uv~!.C*DEEE!M"Yw|ff5EGWXXFLLFUNq+@!*DEEE!Mr)DefaultCropResize)PrazInvalid image_process_mode: )format)rO) resizer:maxrTminintrsavebase64 b64encodegetvaluedecode)r;imageimage_process_mode return_pil image_formatmax_lenmin_lenr]max_hwmin_hw aspect_ratio shortest_edge longest_edgeWHbuffered img_b64_strs r process_imagezConversation.process_imageqsu  & & " " " ""M%((EE #6 6 6  8 + +LL,,EEP+>??FFHHK rcg}t|j|jdD]Z\}\}}|dzdkrIt|tur3|\}}}||||}||[|S)Nr*r)rn)r8rrr2r3r{rH)r;rnimagesrCr?r.rlrms r get_imageszConversation.get_imagess' dkll(CDD ) )NA{c1uzz99%%582C 2 ..u6HU_.``EMM%((( rcg}t|j|jdD]\}\}}|dzdkrt|turh|\}}}||ddd}d|d}||d d z}||dg||dg||d d <|S) Nr*rr^FJPEG)rnroz!user upload imager&r') r8rrr2r3r{r5r6rH) r;r>rCr?r.rlrmrzimg_strs rto_gradio_chatbotzConversation.to_gradio_chatbots' dkll(CDD " "NA{c1uzz99%%582C 2"&"4"4yU%+#5#-#-Kl+kkkG!CKK 2$>$>$D$D$F$FFCJJT{++++JJT{++++!B  rc t|j|jd|jD|j|j|j|j|jS)Ncg|] \}}||g Srr.0xys r z%Conversation.copy..s 777Aq!f777rrrrrrrr r") rrrrrrrr r"r;s rr4zConversation.copysO;*77777;nL""" "rct|dkr1|j|jd|jD|j|j|jdS|j|j|j|j|j|jdS)NrcXg|]'\}}|t|tur|dn|g(S)r)r2r3rs rrz%Conversation.dict..s9\\\daaaE)9)91qA\\\r)rrrrrr )r,r~rrrrrr rs rdictzConversation.dicts t  ! !A % %+\\dm\\\+x  kZ k8I    r)FrJrKrL)F)r r r rstr__annotations__rrfr rrrr r"r#boolrFrIr{r~rr4rrrrrrs66 KKK 949o KKK . 5I~555CD#GSItKKKZ...''''R$ " " "     rrzA chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.)Human Assistant))rzPWhat are the key differences between renewable and non-renewable energy sources?)ragRenewable energy sources are those that can be replenished naturally in a relatively short amount of time, such as solar, wind, hydro, geothermal, and biomass. Non-renewable energy sources, on the other hand, are finite and will eventually be depleted, such as coal, oil, and natural gas. Here are some key differences between renewable and non-renewable energy sources: 1. Availability: Renewable energy sources are virtually inexhaustible, while non-renewable energy sources are finite and will eventually run out. 2. Environmental impact: Renewable energy sources have a much lower environmental impact than non-renewable sources, which can lead to air and water pollution, greenhouse gas emissions, and other negative effects. 3. Cost: Renewable energy sources can be more expensive to initially set up, but they typically have lower operational costs than non-renewable sources. 4. Reliability: Renewable energy sources are often more reliable and can be used in more remote locations than non-renewable sources. 5. Flexibility: Renewable energy sources are often more flexible and can be adapted to different situations and needs, while non-renewable sources are more rigid and inflexible. 6. Sustainability: Renewable energy sources are more sustainable over the long term, while non-renewable sources are not, and their depletion can lead to economic and social instability. r*r)rrrrrrzA chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.)USER ASSISTANTv1rr1z)rrr"rrrrr aYou are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.llama_v2zzYou are a helpful language and vision assistant. You are able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language.z<|im_start|>system A conversation between a user and an LLM-based AI assistant. The assistant gives helpful and honest answers.)z<|im_start|>user z<|im_start|>assistant mptz <|im_end|>)rrr"rrrrr')r'r' a7A chat between a curious user and an artificial intelligence assistant. The assistant is able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language.The visual content will be provided with the following format: visual content.v0_mmtag)rrrrrrr"v1_mmtagrz(<|im_start|>system Answer the questions.z<|begin_of_text|><|start_header_id|>system<|end_header_id|> A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.)z*<|start_header_id|>user<|end_header_id|> z/<|start_header_id|>assistant<|end_header_id|> llama3z <|eot_id|>z*<|system|> You are a helpful AI assistant.)z <|user|> z <|assistant|> phi3z<|end|>defaultv0 vicuna_v1llama_2mistral_instruct chatml_directmistral_directplainv0_plainllava_v0llava_v1 llava_llama_2__main__)' dataclassesenumrrtypingrrrhiorPILrr dataclassrrconv_vicuna_v0rconv_vicuna_v1r conv_llama_2conv_llava_llama_2rconv_mptrconv_llava_plain conv_llava_v0conv_llava_v0_mmtag conv_llava_v1conv_llava_v1_mmtagconv_mistral_instructconv_chatml_direct conv_llama3conv_phi3_instructdefault_conversationconv_templatesr printrFrrrrs T ~ ~ ~ ~ ~ ~ ~ ~ B a , # 9> `         | R   $     "\ Q   $     < p ;        <  "   a  #     #l k ! #      a          #l k        %    $    "\  ;       l k o     "\ < /    # ~. .  |  - '(   # # '!" k#$ %& 8', z E  ) ) + +,,,,,r