o %g= @sVddlZddlmZmZddlmZmZddlZddlm Z ddl m Z GdddeZ ej Gdd d Zed d d d e jddZeddddde jdddZeddddde jdddZeddddde jdddZeddddde jddZed d!dde jd"dZed d dde jddZed#d dde jdd$d%Zed dddde jdddZed#ddde jddd&d'Zed dddde jd ddZed(dddde jddZed)d*d+dde jd,dZ ed-d.d/dde jd0dZ!e Z"id1ed2eded3ed4ed5ed6ed7ed8ed9ed:ed$ed;ed&edN)autoEnum)ListTuple)BytesIO)Imagec@s.eZdZdZeZeZeZeZeZ dS)SeparatorStylezDifferent separator style.N) __name__ __module__ __qualname____doc__rSINGLETWOMPTPLAINLLAMA_2rr$/home/user/app/llava/conversation.pyr s rc@seZdZUdZeed<eeed<eeeed<eed<ej Z eed<dZ eed<d Z eed <d Z eed <d Zeed<ddZddZd ddZd!ddZddZddZddZd S)" Conversationz,A class that keeps all conversation history.systemrolesmessagesoffset sep_style###sepNsep2UnknownversionF skip_nextc Csx|j}t|dkrTt|ddturT|j}|d\}}|ddd}d|jvrL||f|d<|d|j ddf|d|j ddfn|d|f|d<|j t j kr|j |j}|D]#\}}|rt|turs|\}}}||d ||j7}qb||d 7}qb|S|j t jkr|j|jg}|j |d}t|D](\} \}}|rt|tur|\}}}||d ||| d 7}q||d 7}q|S|j t jkr|j |j}|D]\}}|rt|tur|\}}}||||j7}q||7}q|S|j t jkrwd d } dd } d}t|D]_\} \}}| dkr-|s!Jd||j dks-Jd|rit|tur<|\}}}| dkrH| |j |}| d dkr\| |}||j|7}q|d|d|j7}q|d7}q||j}|S|j t jkr|j|jg}|j }t|D]&\} \}}|rt|tur|\}}}|||| d 7}q|d7}q|Std|j )NrZmmtagzz Received.z z: :cSst|dkr d|dS|S)Nrz<> z <> )lenmsgrrrKsz)Conversation.get_prompt..cSs d|dS)Nz[INST] z [/INST]rr&rrrr(Ls z first message should not be nonez#first message should come from user zInvalid style: )rr%typetuplecopyreplacestriprinsertrrrr rrrr enumeraterrlstripr ValueError) selfrZ init_roleZinit_msgretrolemessage_sepsiZwrap_sysZ wrap_instrrr get_prompt!s         6   ,     #       zConversation.get_promptcCs|j||gdS)N)rappend)r3r5r6rrrappend_messagenszConversation.append_messagePNG@cCs|dkrd dd}||}n|dvrn|dkr|d}ntd|t|j|kret|jt|j}} || } tt|| || } t| | } |j\} }|| krY| | }} n| | }} || |f}|ri|St}|j||d t |  }|S) NPadzthcSs~|j\}}||kr |S||kr't|j||f|}||d||df|St|j||f|}||||ddf|S)Nrr$)sizernewmodepaste)pil_imgbackground_colorwidthheightresultrrr expand2squaress z1Conversation.process_image..expand2square)DefaultCropResize)PrRzInvalid image_process_mode: )format)rA) resizer2maxrEminintrsavebase64 b64encodegetvaluedecode)r3imageimage_process_mode return_pil image_formatmax_lenmin_lenrNZmax_hwZmin_hw aspect_ratio shortest_edge longest_edgeWHbuffered img_b64_strrrr process_imageqs0       zConversation.process_imagecCsfg}t|j|jdD]$\}\}}|ddkr0t|tur0|\}}}|j|||d}||q |S)Nr$r)r_)r0rrr*r+rjr;)r3r_imagesr9r5r'r]r^rrr get_imagess     zConversation.get_imagesc Csg}t|j|jdD]F\}\}}|ddkrLt|turD|\}}}|j|dddd}d|d}||d d }||dgq ||dgq ||d d <q |S) Nr$rrOFJPEG)r_r`z!user upload imager!r") r0rrr*r+rjr-r.r;) r3r4r9r5r'r]r^riZimg_strrrrto_gradio_chatbots     zConversation.to_gradio_chatbotc Cs2t|j|jdd|jD|j|j|j|j|jdS)NcSsg|]\}}||gqSrr.0xyrrr sz%Conversation.copy..rrrrrrrr) rrrrrrrrrr3rrrr,szConversation.copycCsVt|dkr|j|jdd|jD|j|j|jdS|j|j|j|j|j|jdS)NrcSs,g|]\}}|t|tur|dn|gqS)r)r*r+rprrrrts,z%Conversation.dict..)rrrrrr)r%rlrrrrrrrvrrrdicts zConversation.dict)Fr=r>r?)F)r r r r str__annotations__rrWrr rrrrrboolr:r<rjrlror,rwrrrrrs$      M  )  rzA 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))r{zPWhat are the key differences between renewable and non-renewable energy sources?)r|agRenewable 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.)USERZ ASSISTANTv1rr)z)rrrrrrrraYou 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.Zllama_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|>)rrrrrrrr")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.Zv0_mmtag)rrrrrrrZv1_mmtagruz(<|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|>defaultv0Z vicuna_v1Zllama_2Zmistral_instructZ chatml_directZmistral_directplainZv0_plainZllava_v0Zllava_v1Z llava_llama_2__main__)' dataclassesenumrrtypingrrrYiorPILrr dataclassrr Zconv_vicuna_v0rZconv_vicuna_v1rZ conv_llama_2Zconv_llava_llama_2rZconv_mptrZconv_llava_plainZ conv_llava_v0Zconv_llava_v0_mmtagZ conv_llava_v1Zconv_llava_v1_mmtagZconv_mistral_instructZconv_chatml_directZ conv_llama3Zconv_phi3_instructZdefault_conversationconv_templatesr printr:rrrrsh   B