o
    rqi¶  ã                   @   s  d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlZd dlmZmZmZmZ ddlmZ ddlmZmZ eƒ ZeG dd	„ d	ƒƒZd
d„ ZeddddƒZdd„ Zdd„ Zg ededdƒ› ddd‘ededdƒ› ddd‘ededdƒ› dedƒ› ddd‘eejdeddƒ› eƒ › de› dd d!‘eejded"d#ƒ› eƒ › de› dd$d!‘eded%d&ƒ› deƒ › de› ded'ƒ› d	d(d‘eded%d&ƒ› deƒ › ded)ƒ› ded*d+ƒ› d	d,d‘eded%d&ƒ› deƒ › ded-ƒ› dd.d‘eded/ƒ› dd0d‘eded1ƒ› ded%ƒ› dd2d‘eejded%d&ƒ› eƒ › de› dd3d!‘eded4d5ƒ› eƒ › ded6ƒ› de› dd7d‘eded8ƒ› dd9d‘eded:ƒ› dd;d‘eded<d=ƒ› dd>d‘eded?ƒ› ded@ƒ› ddAd‘eejded?ƒ› eƒ › de› ddBd!‘eejdedCƒ› dedDƒ› eƒ › ddEd!‘eejdedCƒ› dedFƒ› dedGƒ› ddHd!‘eejdedCƒ› edGdDƒ› dedFƒ› ddId!‘eej dedCƒ› dedGƒ› edDƒ› eƒ › de› d	dJd!‘eej!dedCƒ› edGdDdFƒ› eƒ › de› ddKd!‘ededCƒ› dedLƒ› ddMd‘ededCƒ› dedNƒ› ddOd‘ededPƒ› dedFƒ› ddQdRdS‘ededPƒ› eƒ › ddTd‘ededUƒ› dedVƒ› ddWd‘eej"dedUƒ› dedFƒ› de› ddXd!‘eej"dedUƒ› eƒ › de› ddYd!‘ededZƒ› dd[d‘eded\d]ƒ› de› dd^d‘eej"ded_d`ƒ› eƒ › ddad!‘eej"dedbƒ› eƒ › de› ddcd!‘eej#eddƒ› dedeƒ› dedfƒ› ddgd!‘ededhƒ› ddid‘eej#eddƒ› dedjdkƒ› ddld!‘eej#eddƒ› dedmdnƒ› doe› ddpd!‘ededqƒ› ddrd‘eej#eddƒ› dedeƒ› ddsd!‘eded1ƒ› dedtƒ› ddud‘eded1ƒ› dedvƒ› ddwd‘ededxdyƒ› ddzd‘eded{ƒ› dd|d‘eded}ƒ› dd~d‘ededd€ƒ› ddd‘eded‚dƒƒ› eƒ › de› dd„d‘eej$ded…d†ƒ› eƒ › de› dd‡d!‘ededˆd‰ƒ› ddŠd‘eded‹dŒƒ› eƒ › ddd‘ededŽƒ› eƒ › ddd‘ededƒ› dedvƒ› dd‘d‘ededvƒ› ded’d“ƒ› dd”d‘ededvƒ› ded•d–ƒ› dd—d‘ededvƒ› ded˜ƒ› dd™d‘ededvƒ› dedšƒ› dd›d‘eej%dedœƒ› eƒ › ddd!‘ededvƒ› dedžƒ› ddŸd‘eded ƒ› dd¡d‘eejdedvd¢ƒ› eƒ › de› dd£d!‘eded¤d¥ƒ› ded¦ƒ› dd§d‘eejded¦ƒ› eƒ › dd¨d!‘eejded©ƒ› eƒ › ddªd!‘eded¤d¥ƒ› dd«d‘eded¬ƒ› dd­d‘eej&ded®ƒ› dedFƒ› de› dd¯d!‘eej'ded®ƒ› eƒ › edFƒ› dd°d!‘eded±ƒ› dd²d‘eded³ƒ› dd´d‘ededµƒ› dd¶d‘eded·ƒ› dd¸d‘eded¹ƒ› ddºd‘eej'ded»ƒ› ed¼ƒ› dd°d!‘eej(ded½ƒ› eƒ › dd¾‘eej)ded¿ƒ› eƒ › dd¾‘eej*dedÀdÁƒ› eƒ › de› ddÂd!‘eej+dedÃƒ› eƒ › de› dd¾‘ededÄƒ› ddÅd‘ededÆƒ› ddÇd‘ededÈƒ› ddÉd‘ededÊƒ› ddËd‘ededÌƒ› ddÍd‘eej,dedÎƒ› eƒ › ddÏd!‘ededÐƒ› dedÑƒ› ddÒd‘ededÓdÔƒ› ddÕd‘ededÖƒ› dd×d‘ededØdÙƒ› ddÚd‘ededÛƒ› ddÜd‘ededÝƒ› ddÞd‘ededßƒ› ddàd‘ededáƒ› ddâd‘ededãƒ› ddäd‘ededåƒ› ddæd‘eej-dedçƒ› eƒ › dd¾‘eej.dedèƒ› edédêƒ› eƒ › de› dd¾‘eej/dedéƒ› eƒ › de› ddëd!‘eej0dedìƒ› eƒ › dd¾‘eej1dedíƒ› eƒ › de› dd¾‘eej2dedîƒ› eƒ › de› dd¾‘eej3dedïƒ› eƒ › de› dd¾‘eej4dedðƒ› eƒ › dd¾‘eej5dedñƒ› eƒ › de› dd¾‘eej6dedòƒ› edGƒ› dd¾‘eej7dedòƒ› dedGƒ› dd¾‘ededódôƒ› ddõd‘ededöƒ› dd÷d‘ededøƒ› ddùd‘ededúƒ› dedûƒ› ddüd‘ededúƒ› dedýƒ› ddþd‘ededúƒ› dedƒ› dedÿƒ› dd d‘ededúƒ› dedÿƒ› ddd‘ededƒ› deddƒ› ddd‘ededƒ› deddƒ› ddd‘eded	ƒ› dd
d‘ededƒ› deddƒ› ddd‘ededƒ› deddƒ› ddd‘ededƒ› ddd‘ededƒ› ddd‘ededƒ› ddd‘ededƒ› ddd‘ededƒ› ddd‘ededƒ› ddd‘ededƒ› dedƒ› ddd‘ededƒ› ddd‘ededƒ› ddd‘eded ƒ› dd!dRdS‘eded"d#ƒ› dd$d‘eded%ƒ› dd&d‘eded'ƒ› dd(d‘eded)ƒ› dd*d‘eded+d,ƒ› dd-d‘ededðƒ› dd.d‘eded/ƒ› dd0d‘eded1ƒ› dd2d‘eded3ƒ› dd4d‘eded5ƒ› dd6d‘eded7ƒ› dd8d‘eded9ƒ› dd:d‘eded;ƒ› dd<d‘eded=ƒ› dd>d‘eded?ƒ› ded@ƒ› ddAd‘ededBƒ› ddCd‘ededDƒ› ddEd‘ededFƒ› ddGd‘ededHƒ› ddId‘ededJdKdLƒ› ddMd‘ededNdOdPƒ› ddQd‘ededRƒ› ddSd‘ededTƒ› ddUd‘ededVƒ› ddWd‘ededXƒ› ddYd‘ededZƒ› dd[d‘eded\ƒ› dd]d‘eded^ƒ› dd_d‘eded`ƒ› dedaƒ› dedbƒ› ddcd‘ededdƒ› dded‘ededfƒ› ddgd‘ededhƒ› ddid‘ededjƒ› ddkd‘ededlƒ› ddmd‘edednƒ› ddod‘ededpƒ› ddqd‘ededrƒ› ddsd‘ededtƒ› deduƒ› ddvd‘ededwƒ› ddxd‘ededyƒ› ddzd‘eded{ƒ› dd|d‘eded}ƒ› dd~d‘Z8G dd€„ d€ƒZ9dS (  é    N)Ú	dataclass)ÚAnyÚDictÚListÚUnionÚOptionalÚTuple)ÚAutoTokenizerÚ
get_loggerÚsnapshot_downloadÚ
AutoConfigé   )ÚTemplateType)ÚTemplateÚget_templatec                   @   s>   e Zd ZU dZeed< dZeed< dZeed< dZe	ed< dS )ÚTemplateInfoNÚtemplateÚtemplate_regexÚmodelfile_prefixTÚallow_general_name)
Ú__name__Ú
__module__Ú__qualname__r   ÚstrÚ__annotations__r   r   r   Úbool© r   r   úp/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/modelscope/preprocessors/templates/loader.pyr      s
   
 r   c                  G   s¨   g }| D ]6}d}|D ]}|  ¡ | ¡ kr#|d|  ¡ › | ¡ › d7 }q
||7 }q
| |¡ d|v r:| | dd¡¡ qt|ƒdkrNd |¡}d| d	 }|S |d
 }|S )NÚ ú[ú]ú-ú r   ú|ú(ú)r   )ÚupperÚlowerÚappendÚreplaceÚlenÚjoin)ÚnamesÚretÚnameÚregexÚletterr   r   r   Úcases   s"   

€
ÿr1   ZinstructZchatz-rlz-itc                  G   s   dt | Ž › dS )Nz(?!.*r%   )r1   )r,   r   r   r   Úno.   s   r2   c                   C   s   t ddddƒS )NZaudioZvideoÚvlÚvision)r2   r   r   r   r   Úno_multi_modal2   s   r5   z.*Zllama4zllama-4zIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama4)r   r   zllama3.3z	llama-3.3zKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama3.3zllama3.2z	llama-3.2r4   zRhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama3.2-visionzKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama3.2)r   r   r   zllama3.1z	llama-3.1zKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama3.1Úllama3zllama-3ZgradientzRhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama3-gradientZgroqztool-useZtool_usezWhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama3-groq-tool-useZchatqazPhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama3-chatqazllava-llama-3zOhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llava-llama3ÚdolphinzQhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/dolphin-llama3zIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama3Zllama2zllama-2ÚchinesezQhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama2-chineseZ	codellamazLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/codellamaZ	tinyllamazLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/tinyllamaz	llama-proZ	llama_prozLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama-proÚllamaÚguardzOhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama-guard3zIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llama2Údeepseekzv2.5zPhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-v2.5ZcoderÚv2zThttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-coder-v2zQhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-coderzNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-v2zOhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-llmZv3zNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-v3Úr1zNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepseek-r1Zqwen3zNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwen3-coderF)r   r   r   zHhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwen3zqwen2.5r3   zLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwen2.5vlzPhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwen2.5-coderzJhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwen2.5z
qwen2-mathzMhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwen2-mathzcodeqwen1.5zcodeqwen-1.5zKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/codeqwenZqwen2zqwen1.5zHhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwen2ÚqwenzGhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwenZpaliÚgemmaZ3nzJhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/gemma3nZ	codegemmazLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/codegemmaZgemma3zgemma-3zIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/gemma3Zgemma2zgemma-2z\b.*zIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/gemma2ZshieldgemmazNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/shieldgemmazHhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/gemmaz-mixtralzRhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/dolphin-mixtralZmistralzRhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/dolphin-mistralZdolphin3z	dolphin-3zKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/dolphin3zphi-4-reasoningzQhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/phi4-reasoningzphi-4-mini-reasoningzVhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/phi4-mini-reasoningz
llava-phi3zllava-phi-3zMhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llava-phi3zphi3.5zphi-3.5zIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/phi3.5Úphi3zphi-3zGhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/phi3z	phi4-miniz
phi-4-minizLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/phi4-miniZphi4zphi-4zGhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/phi4ÚphizFhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/phiÚyarnzOhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/yarn-mistralzsmall3.2z	small-3.2zShttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mistral-small3.2zsmall3.1z	small-3.1zShttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mistral-small3.1ZlargezPhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mistral-largeZsmallzPhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mistral-smallzMistral-NemozOhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mistral-nemoZopenorcazShttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mistral-openorcaZmistrallitezNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mistralliteZ	ministralzJhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mistralznous-hermes2znous-hermes-2ZmixtralzWhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/nous-hermes2-mixtralzJhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mixtralZ	codestralzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/codestralzOhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/nous-hermes2znous-hermeszNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/nous-hermesÚyizKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/yi-coderzEhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/yiZbakllavazKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/bakllavaZllavazHhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/llavaznemotron-minizPhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/nemotron-miniZnemotronzKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/nemotronz	minicpm-vzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/minicpm-vZminicpmz-vÚchatglm2)r   r   Úchatglm3Zglm4zglm-4zGhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/glm4Úbaichuanzcommand-r-pluszQhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/command-r-pluszcommand-r7b-arabiczUhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/command-r7b-arabiczcommand-r7bzNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/command-r7bz	command-rzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/command-rz	command-azLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/command-aÚ	codegeex4zLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/codegeex4zwizard-vicunaZ
uncensoredz[https://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/wizard-vicuna-uncensoredZ	wizardlm2z
wizardlm-2zLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/wizardlm2ZwizardcoderzNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/wizardcoderzwizard-mathZ
wizardmathzNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/wizard-mathZwizardlmzKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/wizardlmZ	magistralzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/magistralZdevstralzKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/devstralZvicunazIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/vicunazstable-codezNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/stable-codeZstablelmzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/stablelm2Úidefics3ÚinternlmÚ	internlm2Z	internlm3zLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/internlm2ZYuanÚxverseÚskyworkÚbluelmÚzephyrÚorionZTeleChatZtulu3ztulu-3zHhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/tulu3z	athene-v2zLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/athene-v2zgranite-guardian-3zThttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/granite3-guardianZgraniteÚcodezOhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/granite-codez3.3zMhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/granite3.3z3.2zThttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/granite3.2-visionzMhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/granite3.2zgranite-3.1Z2bZ8bzShttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/granite3.1-denseZ1bZ3bzQhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/granite3.1-moezgranite-embeddingzThttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/granite-embeddingz	granite-3zQhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/granite3-densezOhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/granite3-moeZ	opencoderzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/opencoderZsmollm2zJhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/smollm2ZsmollmzIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/smollmzaya-expansezNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/aya-expanseZayazFhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/ayaZfalcon3zJhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/falcon3Zfalconz-2zJhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/falcon2zIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/falconZsmallthinkerzOhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/smallthinkerZopenthinkerzNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/openthinkerZolmo2zolmo-2zHhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/olmo2znomic-embed-textzShttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/nomic-embed-textzmxbai-embed-largezThttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mxbai-embed-largeZ
starcoder2zMhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/starcoder2z	orca-miniZ	orca_minizLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/orca-minizIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/zephyrzsnowflake-arctic-embedzYhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/snowflake-arctic-embedZ	starcoderzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/starcoderz
all-minilmzMhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/all-minilmZopenchatzKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/openchatZ
openhermeszMhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/openhermesZ
reflectionzMhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/reflectionzneural-chatzNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/neural-chatZ	moondreamzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/moondreamZxwinZlmzIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/xwinlmZsqlcoderzKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/sqlcoderzstarling-lmzNhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/starling-lmz	solar-prozLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/solar-proZsolarzHhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/solarZorca2zorca-2Zorca_2zHhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/orca2Zhermes3zhermes-3Zhermes_3zJhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/hermes3ZmeditronzKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/meditronZ
nexusravenzMhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/nexusravenZ	magicoderzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/magicoderZ	deepcoderzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepcoderZcogitozIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/cogitozbge-m3zIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/bge-m3ZnotuxzHhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/notuxÚopenZorcaZ	platypus2zVhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/open-orca-platypus2ZnotuszHhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/notusZ	mathstralzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/mathstralZdbrxzGhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/dbrxZ	nuextractzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/nuextractz	reader-lmzLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/reader-lmZalfredzIhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/alfredz	bge-largezLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/bge-largezparaphrase-multilingualzZhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/paraphrase-multilingualZmarcoZo1zKhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/marco-o1ZqwqzFhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/qwqZexaonezLhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/exaone3.5zr1-1776zJhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/r1-1776Z
deepscalerzMhttps://modelscope.oss-cn-beijing.aliyuncs.com/llm_template/ollama/deepscalerc                   @   sð   e Zd Zededefdd„ƒZededefdd„ƒZeded	ed
edefdd„ƒZ	eddede
dedee deee
f f
dd„ƒZe						ddededede
eef dededeee
ee
ef eeef df fdd„ƒZedd„ ƒZdS )ÚTemplateLoaderÚmodel_idÚreturnc              	   K   sÌ   g d¢}|  d¡}|  d¡}| dd¡}tD ]M}t |j| ¡rc|jrc|du rTz$t| | dd¡|d}t 	d	|› d
¡ t
j||d}tj||d}W n	 tyS   Y nw tj|jf||dœ|¤Ž  S qdS )a  Load a template by model-id

        Args:
            model_id: The model-id used to load the proper template
            kwargs:
                revision: the revision of the model, default is `master`
        Returns:
            The template instance
        )z.+\.bin$z.+\.safetensors$z	.+\.gguf$Ú	tokenizerÚconfigÚtrust_remote_codeNÚrevisionZmaster)rX   Úignore_file_patternz3Use trust_remote_code=True. Will invoke codes from z9. Please make sure that you can trust the external codes.)rW   )rU   rV   )ÚgetÚpopÚtemplate_infoÚreÚ	fullmatchr   r   r   ÚloggerÚwarningr	   Zfrom_pretrainedr   Ú	ExceptionrR   Úload_by_template_name)rS   ÚkwargsrY   rU   rV   rW   Ú_infoZ	model_dirr   r   r   Úload_by_model_idê  s>   


ýÿÿÿÿ
ÿ€ïzTemplateLoader.load_by_model_idÚtemplate_namec                 K   s,   t | fd| dd¡i|¤Ž}| d¡|_|S )aè  Load a template by model-id

        Args:
            template_name: The template name used to load the proper template
            kwargs:
                tokenizer: The tokenizer of the model
                default_system: The extra default system info
                max_length: The max_length for the sequence
                truncation_strategy: 'delete' or 'truncation_left' the sequence of the length exceeds the limit
        Returns:
            The template instance
        rU   NrV   )r   r[   rZ   rV   )rf   rc   r   r   r   r   rb     s   z$TemplateLoader.load_by_template_namer   Útemplate_listÚplaceholderÚkeywordc                 C   sž   d}|D ]H}t |tƒr|| ||¡7 }qt |ttfƒrLt |d tƒr+|| j |¡7 }q|D ]}|dkr:|| jj7 }q-|dkrE|| jj	7 }q-t
d|› ƒ‚q|S )Nr   r   Zbos_token_idÚeos_token_idzUnknown token: )Ú
isinstancer   r)   ÚtupleÚlistÚintrU   ÚdecodeZ	bos_tokenÚ	eos_tokenÚ
ValueError)r   rg   rh   ri   Z	final_strÚtÚattrr   r   r   Úreplace_and_concat  s   
€z!TemplateLoader.replace_and_concatNÚtemplate_linesÚparamsÚsplitÚlicensec              	   C   s®   |r|r	t  |¡}|| |dœS d}|d7 }|rK| ¡ D ]+\}}t|tƒr8|D ]}|d|› dt  |¡› d7 }q&q|d|› dt  |¡› d7 }q|d7 }| rU|d|  d 7 }|S )	N)rv   r   rx   r   zFROM {gguf_file}

z
PARAMETER r"   Ú
zTEMPLATE """z"""
)ÚjsonÚdumpsÚitemsrk   rm   )ru   rv   rw   rx   ÚcontentÚkeyÚvaluesÚvaluer   r   r   Ú_format_return3  s"   

ÿzTemplateLoader._format_returnFÚ	gguf_fileÚ	gguf_metaÚdebugc                 K   s*  | s|s|st d| › d|› dƒ‚t d¡ i }i }|r(| dd¡}	|	r(|	|d< | r.| |d< | ¡ D ]!\}
}tD ]}t |j|¡rR|j	rR| d	d
¡sR||f||
<  nq8q2d}d}t
|ƒdkrg| ¡ \}\}}nt
|ƒdkr|d d js{|d \}}n|d \}}|rÏt |j	d ¡}|s•t |› d¡ t |j	d ¡}|r¥t |¡}nt |› d¡ t |j	d ¡}|s¿t |› d¡ t ||||¡}|rÍ||fS |S |rÛtj|fi |¤Ž}n	tj| fi |¤Ž}|sèdS d}t ||jdd¡}|r|dt ||jpÿg dd¡› d|› d7 }n|dt ||jpg dd¡› d7 }|dt ||jdd¡› d7 }|d7 }|t ||jdd¡7 }t ||jdd¡h}t|ddƒr|t |dggdd¡}| |¡ t|ddƒr|t|jdƒr||jj}t ||ggdd¡}| |¡ tƒ }|D ]}| |¡ qd|i}t |||¡S ) a-  Export to ollama ModelFile

        Args:
            model_id: The model-id to use
            template_name: An extra template name to use
            gguf_file: An extra gguf_file path to use in the `FROM` field
            gguf_meta: An gguf extra meta info
            split: bool. Return str modelfile content, or dict of params and template
            debug: bool. Whether or not to return the matched TemplateInfo
        Returns:
            The ModelFile content, or dictionary of params and template, returns `None` if no template found
        zPlease make sure you model_id: z and template_name: z is supported.zExporting to ollama:zgeneral.nameNÚgguf_header_namerS   Zignore_oss_model_fileFr   z	.templatez has no template file.z.paramsz has no params file.z.licensez has no license file.r   z{{ if .System }}z
{{SYSTEM}}z{{ .System }}z
{{ else }}z	{{ end }}z{{ if .Prompt }}z	{{QUERY}}z{{ .Prompt }}z{{ .Response }}rU   rj   rV   Ústop)rq   r_   ÚinforZ   r|   r\   r]   r^   r   r   r*   Úpopitemr   rR   Ú_read_content_from_urlrz   Úloadsr   rb   re   rt   ÚprefixZsystem_prefixÚpromptÚsuffixÚgetattrÚaddrV   rj   rm   r(   )rS   rf   r‚   rƒ   rw   r„   rc   r,   Zmatch_infosr…   Z	name_typer.   rd   Ú_nameÚ_Ztemplate_strrv   rx   Z
format_outr   ru   Ú_prefixZall_eos_tokensrp   rj   Zstop_tokensr   r   r   Ú	to_ollamaI  sÆ   ÿÿ
€ÿÿÿÿÿÿÿþÿÿÿÿÿÿ

zTemplateLoader.to_ollamac              
   C   sR   zt  | ¡}| ¡  W n t jjy  } zW Y d }~d S d }~ww |j}| d¡S )Nzutf-8)ÚrequestsrZ   Úraise_for_statusÚ
exceptionsÚ	HTTPErrorr}   ro   )ÚurlÚresponseÚer}   r   r   r   r‰   ¿  s   
€ÿ
z%TemplateLoader._read_content_from_url)N)NNNNFF)r   r   r   Ústaticmethodr   r   re   rb   r   rt   r   r   r   r   r   r   r   r   r“   r‰   r   r   r   r   rR   è  sJ    "
ÿÿÿûÿþ
ýüû úurR   ):r]   rz   Údataclassesr   Útypingr   r   r   r   r   r   r”   Z
modelscoper	   r
   r   r   r   r   Úbaser   r   r_   r   r1   Zchat_suffixr2   r5   r6   r9   Zdeepseek2_5Zdeepseek_coderZ	deepseek2r;   r>   r?   r@   Zmistral_nemoZyi_coderZchatmlrD   rE   Zchatglm4rF   rG   rH   rI   rJ   ZyuanrK   rL   rM   rN   rO   ZtelechatZtelechat_v2r\   rR   r   r   r   r   Ú<module>   s6    üþ	ü÷üñûëûä#(üÝ).ü×/"üÑ5þË8þÈ;ûÅD&ü¼Jü¶Pü°Vüª\ü¤bûžkû•r"ûŽy"û‡ ,û ÿ &û ø ü ñ ü ë ü ã #ý Ý (ý Ø -ü Ó 3ü Í 9ý Ç >ü Â Dü ¼ Jü ¶ R û ® Yü § _û ¡ fû š mü “ sû  |ü „  ü  ý  	ý  ÷  ü  ñ  ü  ë  ü  å  !ü  ß  'û  Ù  .ü  Ò  4ü  Ì  :ü  Æ  Bü  ¾  Hü  ¸  Nü  ²  Tü  ¬  Zü  ¦  `ü     fü  š  lü  ”  sû    |ü  „   û   ý   û   ô   ü   ë   ý   å   !ü   ß   'û   Ù   0ü   Ð   6ü   Ê   >ü   Â   Dü   ¼   Lý   ´   Qü   ¯   Yþ   §   \þ   ¤   _ü   ¡   gý   ™   mü   “   sü      yü   ‡   ü       ü    ù    ü    ñ    ü    é    ü    ã    #ü    Ý    )ü    ×    /ü    Ñ    7ü    É    ?ü    Á    Gü    ¹    Oü    ±    Uü    «    ]þ    £    b$ý    ž    iû    —    rþ    Ž    wþ    ‰    }ý    ƒ     þ     ü     
þ     ö     þ     ñ     þ     ë     þ     æ     ý     á     %ý     Û     +ý     Õ     /ý     Ñ     3ý     Í     7"ý     É     ;ý     Å     ? ý     Á     C ý     ½     Gý     ¹     K ý     µ     O ý     ±     Tý     ¬     Zý     ¦     ^ý     ¢     dý     œ     hý     ˜     ný     ’     rý     Ž     vý     Š     |ý     „      ü      þ      ü      ø      ý      ñ      ý      í      ý      é      ý      å      ý      á      #ý      Ý      'ý      Ù      +ý      Õ      /ý      Ñ      3ý      Í      7ý      É      ;ý      Å      ?ý      Á      Cý      ½      Gý      ¹      Ký      µ      Oý      ±      Sý      ­      Wý      ©      [ý      ¥      _ý      ¡      cý            gý      ™      kü      •      pý            tý      Œ      xý      ˆ      |(ý      „       ý       ÿ       ý       û       	ý       ÷       ý       ó       ý       ï       ý       ë       ý       ç       ý       ã       !ý       ß       %ý       Û       )ý       ×       -ý       Ó       1ý       Ï       8