share a usable chat template in lm studio
#6
by uptonking - opened
i download https://huggingface.co/mlx-community/granite-4.0-3b-vision-mxfp4 in lm studio, but chat does not work.
- AI gives a usable chat template and i tested. it works
{%- set default_system_message = "You are a helpful assistant. Please ensure responses are professional, accurate." -%}
{%- set chart2code_prompt = "Generate code that recreates the chart as accurately as possible." -%}
{%- set chart2csv_prompt = "Examine the chart image and return only a CSV table with headers and all visible values." -%}
{%- set chart2summary_prompt = "Describe the chart in natural language." -%}
{%- set tables_json_prompt = "Extract the table as structured JSON." -%}
{%- set tables_html_prompt = "Extract the table as valid HTML." -%}
{%- set tables_otsl_prompt = "Extract the table as valid OTSL markup." -%}
{%- if messages and messages[0]['role'] == 'system' -%}
<|start_of_role|>system<|end_of_role|>{%- if messages[0]['content'] is string -%}{{ messages[0]['content'] }}{%- endif -%}<|end_of_text|>
{%- else -%}
<|start_of_role|>system<|end_of_role|>{{ default_system_message }}<|end_of_text|>
{%- endif -%}
{%- for message in messages -%}
{%- if loop.first and message['role'] == 'system' -%}
{%- elif message['role'] == 'user' -%}
<|start_of_role|>user<|end_of_role|>
{%- if message['content'] is string -%}
{%- if "<chart2code>" in message['content'] -%}{{ chart2code_prompt }}
{%- elif "<chart2csv>" in message['content'] -%}{{ chart2csv_prompt }}
{%- elif "<chart2summary>" in message['content'] -%}{{ chart2summary_prompt }}
{%- elif "<tables_json>" in message['content'] -%}{{ tables_json_prompt }}
{%- elif "<tables_html>" in message['content'] -%}{{ tables_html_prompt }}
{%- elif "<tables_otsl>" in message['content'] -%}{{ tables_otsl_prompt }}
{%- else -%}{{ message['content'] }}
{%- endif -%}
{%- else -%}
{%- for chunk in message['content'] -%}
{%- if chunk['type'] == 'image' -%}<image>
{%- elif chunk['type'] == 'text' -%}
{%- if "<chart2code>" in chunk['text'] -%}{{ chart2code_prompt }}
{%- elif "<chart2csv>" in chunk['text'] -%}{{ chart2csv_prompt }}
{%- elif "<chart2summary>" in chunk['text'] -%}{{ chart2summary_prompt }}
{%- elif "<tables_json>" in chunk['text'] -%}{{ tables_json_prompt }}
{%- elif "<tables_html>" in chunk['text'] -%}{{ tables_html_prompt }}
{%- elif "<tables_otsl>" in chunk['text'] -%}{{ tables_otsl_prompt }}
{%- else -%}{{ chunk['text'] }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}<|end_of_text|>
{%- elif message['role'] == 'assistant' -%}
<|start_of_role|>assistant<|end_of_role|>
{%- if message['content'] is string -%}{{ message['content'] }}{%- else -%}
{%- for chunk in message['content'] -%}
{%- if chunk['type'] == 'text' -%}{{ chunk['text'] }}{%- endif -%}
{%- endfor -%}
{%- endif -%}<|end_of_text|>
{%- endif -%}
{%- endfor -%}
{%- if add_generation_prompt -%}<|start_of_role|>assistant<|end_of_role|>{%- endif -%}