From df95b7b0a4705b544c24064ce8a38f9f8fa8b013 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Tue, 11 Feb 2025 16:41:27 -0500 Subject: [PATCH] tweak changelog entry and further simplify templates Signed-off-by: Jared Van Bortel --- gpt4all-chat/CHANGELOG.md | 7 +- gpt4all-chat/src/jinja_replacements.cpp | 103 ++++++++---------------- 2 files changed, 37 insertions(+), 73 deletions(-) diff --git a/gpt4all-chat/CHANGELOG.md b/gpt4all-chat/CHANGELOG.md index 8e4c081c..821e663a 100644 --- a/gpt4all-chat/CHANGELOG.md +++ b/gpt4all-chat/CHANGELOG.md @@ -6,14 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] +### Changed +- Substitute prettier default templates for OLMoE 7B and Granite 3.1 3B/8B ([#3471](https://github.com/nomic-ai/gpt4all/pull/3471)) + ### Fixed - Fix several potential crashes ([#3465](https://github.com/nomic-ai/gpt4all/pull/3465)) - Fix visual spacing issues with deepseek models ([#3470](https://github.com/nomic-ai/gpt4all/pull/3470)) -### Added -- Added Jinja replacement template for allenai\/OLMoE-1B-7B-0924-Instruct ([#3471](https://github.com/nomic-ai/gpt4all/pull/3471)) -- Added Jinja replacement template for ibm-granite\/granite-3.1-3b-a800m-instruct ([#3471](https://github.com/nomic-ai/gpt4all/pull/3471)) - ## [3.9.0] - 2025-02-04 ### Added diff --git a/gpt4all-chat/src/jinja_replacements.cpp b/gpt4all-chat/src/jinja_replacements.cpp index 81cc3db7..d499e3aa 100644 --- a/gpt4all-chat/src/jinja_replacements.cpp +++ b/gpt4all-chat/src/jinja_replacements.cpp @@ -118,6 +118,26 @@ const std::unordered_map CHAT_TEMPLATE_SUBST {%- if loop.last and add_generation_prompt %} {{- '<|assistant|>' }} {%- endif %} +{%- endfor %})TEMPLATE", + }, + // granite-3.1-3b-a800m-instruct-Q4_0.gguf, granite-3.1-8b-instruct-Q4_0.gguf (nomic-ai/gpt4all#3471) + { + // original + R"TEMPLATE({%- if messages[0]['role'] == 'system' %}{%- set system_message = messages[0]['content'] %}{%- set loop_messages = messages[1:] %}{%- else %}{%- set system_message = "Knowledge Cutoff Date: April 2024. You are Granite, developed by IBM." %}{%- if tools and documents %}{%- set system_message = system_message + " You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request. Write the response to the user's input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data." %}{%- elif tools %}{%- set system_message = system_message + " You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request." %}{%- elif documents %}{%- set system_message = system_message + " Write the response to the user's input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data." %}{%- else %}{%- set system_message = system_message + " You are a helpful AI assistant." %}{%- endif %}{%- if controls and 'citations' in controls and documents %}{%- set system_message = system_message + ' In your response, use the symbols and to indicate when a fact comes from a document in the search result, e.g 0 for a fact from document 0. Afterwards, list all the citations with their corresponding documents in an ordered list.' %}{%- endif %}{%- if controls and 'hallucinations' in controls and documents %}{%- set system_message = system_message + ' Finally, after the response is written, include a numbered list of sentences from the response that are potentially hallucinated and not based in the documents.' %}{%- endif %}{%- set loop_messages = messages %}{%- endif %}{{- '<|start_of_role|>system<|end_of_role|>' + system_message + '<|end_of_text|> ' }}{%- if tools %}{{- '<|start_of_role|>tools<|end_of_role|>' }}{{- tools | tojson(indent=4) }}{{- '<|end_of_text|> ' }}{%- endif %}{%- if documents %}{{- '<|start_of_role|>documents<|end_of_role|>' }}{%- for document in documents %}{{- 'Document ' + loop.index0 | string + ' ' }}{{- document['text'] }}{%- if not loop.last %}{{- ' '}}{%- endif%}{%- endfor %}{{- '<|end_of_text|> ' }}{%- endif %}{%- for message in loop_messages %}{{- '<|start_of_role|>' + message['role'] + '<|end_of_role|>' + message['content'] + '<|end_of_text|> ' }}{%- if loop.last and add_generation_prompt %}{{- '<|start_of_role|>assistant' }}{%- if controls %}{{- ' ' + controls | tojson()}}{%- endif %}{{- '<|end_of_role|>' }}{%- endif %}{%- endfor %})TEMPLATE", + // replacement + R"TEMPLATE({%- if messages[0]['role'] == 'system' %} + {%- set system_message = messages[0]['content'] %} + {%- set loop_messages = messages[1:] %} +{%- else %} + {%- set system_message = "Knowledge Cutoff Date: April 2024. You are Granite, developed by IBM. You are a helpful AI assistant." %} + {%- set loop_messages = messages %} +{%- endif %} +{{- '<|start_of_role|>system<|end_of_role|>' + system_message + '<|end_of_text|> ' }} +{%- for message in loop_messages %} + {{- '<|start_of_role|>' + message['role'] + '<|end_of_role|>' + message['content'] + '<|end_of_text|> ' }} + {%- if loop.last and add_generation_prompt %} + {{- '<|start_of_role|>assistant<|end_of_role|>' }} + {%- endif %} {%- endfor %})TEMPLATE", }, // Hermes-3-Llama-3.2-3B.Q4_0.gguf, mistral-7b-openorca.gguf2.Q4_0.gguf @@ -134,61 +154,6 @@ const std::unordered_map CHAT_TEMPLATE_SUBST {%- if add_generation_prompt %} {{- '<|im_start|>assistant\n' }} {%- endif %})TEMPLATE", - }, - // ibm-granite/granite-3.1-3b-a800m-instruct.gguf, ibm-granite/granite-3.1-8b-instruct.gguf (nomic-ai/gpt4all#3159) - { - // original - R"TEMPLATE({%- if messages[0]['role'] == 'system' %}{%- set system_message = messages[0]['content'] %}{%- set loop_messages = messages[1:] %}{%- else %}{%- set system_message = "Knowledge Cutoff Date: April 2024. You are Granite, developed by IBM." %}{%- if tools and documents %}{%- set system_message = system_message + " You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request. Write the response to the user's input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data." %}{%- elif tools %}{%- set system_message = system_message + " You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request." %}{%- elif documents %}{%- set system_message = system_message + " Write the response to the user's input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data." %}{%- else %}{%- set system_message = system_message + " You are a helpful AI assistant." %}{%- endif %}{%- if controls and 'citations' in controls and documents %}{%- set system_message = system_message + ' In your response, use the symbols and to indicate when a fact comes from a document in the search result, e.g 0 for a fact from document 0. Afterwards, list all the citations with their corresponding documents in an ordered list.' %}{%- endif %}{%- if controls and 'hallucinations' in controls and documents %}{%- set system_message = system_message + ' Finally, after the response is written, include a numbered list of sentences from the response that are potentially hallucinated and not based in the documents.' %}{%- endif %}{%- set loop_messages = messages %}{%- endif %}{{- '<|start_of_role|>system<|end_of_role|>' + system_message + '<|end_of_text|> ' }}{%- if tools %}{{- '<|start_of_role|>tools<|end_of_role|>' }}{{- tools | tojson(indent=4) }}{{- '<|end_of_text|> ' }}{%- endif %}{%- if documents %}{{- '<|start_of_role|>documents<|end_of_role|>' }}{%- for document in documents %}{{- 'Document ' + loop.index0 | string + ' ' }}{{- document['text'] }}{%- if not loop.last %}{{- ' '}}{%- endif%}{%- endfor %}{{- '<|end_of_text|> ' }}{%- endif %}{%- for message in loop_messages %}{{- '<|start_of_role|>' + message['role'] + '<|end_of_role|>' + message['content'] + '<|end_of_text|> ' }}{%- if loop.last and add_generation_prompt %}{{- '<|start_of_role|>assistant' }}{%- if controls %}{{- ' ' + controls | tojson()}}{%- endif %}{{- '<|end_of_role|>' }}{%- endif %}{%- endfor %})TEMPLATE", - // replacement - R"TEMPLATE({%- if messages[0]['role'] == 'system' %} - {%- set system_message = messages[0]['content'] %} - {%- set loop_messages = messages[1:] %} -{%- else %} - {%- set system_message = "Knowledge Cutoff Date: April 2024.\nYou are Granite, developed by IBM." %} -{%- if tools and documents %} - {%- set system_message = system_message + " You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.\n\nWrite the response to the user's input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data." %} -{%- elif tools %} - {%- set system_message = system_message + " You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request." %} -{%- elif documents %} - {%- set system_message = system_message + " Write the response to the user's input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data." %} -{%- else %} - {%- set system_message = system_message + " You are a helpful AI assistant." %} -{%- endif %} -{%- if controls and 'citations' in controls and documents %} - {%- set system_message = system_message + '\n\nIn your response, use the symbols and to indicate when a fact comes from a document in the search result, e.g 0 for a fact from document 0. Afterwards, list all the citations with their corresponding documents in an ordered list.' %} -{%- endif %} -{%- if controls and 'hallucinations' in controls and documents %} - {%- set system_message = system_message + '\n\nFinally, after the response is written, include a numbered list of sentences from the response that are potentially hallucinated and not based in the documents.' %} -{%- endif %} - {%- set loop_messages = messages %} -{%- endif %} -{{- '<|start_of_role|>system<|end_of_role|>' + system_message + '<|end_of_text|>\n' }} -{%- if tools %} -{{- '<|start_of_role|>tools<|end_of_role|>' }} -{{- tools | tojson(indent=4) }} -{{- '<|end_of_text|>\n' }} -{%- endif %} -{%- if documents %} - {{- '<|start_of_role|>documents<|end_of_role|>' }} -{%- for document in documents %} - {{- 'Document ' + loop.index0 | string + '\n' }} - {{- document['text'] }} - {%- if not loop.last %} - {{- '\n\n'}} -{%- endif%} -{%- endfor %} -{{- '<|end_of_text|>\n' }} -{%- endif %} -{%- for message in loop_messages %} - {{- '<|start_of_role|>' + message['role'] + '<|end_of_role|>' + message['content'] + '<|end_of_text|>\n' }} -{%- if loop.last and add_generation_prompt %} - {{- '<|start_of_role|>assistant' }} -{%- if controls %} - {{- ' ' + controls | tojson()}} -{%- endif %} - {{- '<|end_of_role|>' }} -{%- endif %} -{%- endfor %})TEMPLATE", }, // Llama-3.2-1B-Instruct-Q4_0.gguf, Llama-3.2-3B-Instruct-Q4_0.gguf, SummLlama3.2-3B-Q4_0.gguf (nomic-ai/gpt4all#3309) { @@ -674,7 +639,7 @@ const std::unordered_map CHAT_TEMPLATE_SUBST {{- '<|im_start|>assistant\n' }} {%- endif %})TEMPLATE", }, - // allenai/OLMoE-1B-7B-0924-Instruct-GGUF (nomic-ai/gpt4all#3053) + // OLMoE-1B-7B-0924-Instruct-Q4_0.gguf (nomic-ai/gpt4all#3471) { // original R"TEMPLATE({{ bos_token }}{% for message in messages %} @@ -693,19 +658,19 @@ const std::unordered_map CHAT_TEMPLATE_SUBST {% endif %} {% endfor %})TEMPLATE", // replacement - R"TEMPLATE({{ bos_token }} -{% for message in messages %} -{% if message['role'] == 'system' %} - {{ '<|system|>\n' + message['content'] }} -{% elif message['role'] == 'user' %} - {{ '<|user|>\n' + message['content'] }} -{% elif message['role'] == 'assistant' %} - {{ '<|assistant|>\n' + message['content'] + eos_token }} -{% endif %} -{% if loop.last and add_generation_prompt %} - {{ '<|assistant|>' }} -{% endif %} -{% endfor %})TEMPLATE", + R"TEMPLATE({{- bos_token }} +{%- for message in messages %} + {%- if message['role'] == 'system' %} + {{- '<|system|>\n' + message['content'] }} + {%- elif message['role'] == 'user' %} + {{- '<|user|>\n' + message['content'] }} + {%- elif message['role'] == 'assistant' %} + {{- '<|assistant|>\n' + message['content'] + eos_token }} + {%- endif %} + {%- if loop.last and add_generation_prompt %} + {{- '<|assistant|>' }} + {%- endif %} +{%- endfor %})TEMPLATE", }, // Phi-3.1-mini-128k-instruct-Q4_0.gguf (nomic-ai/gpt4all#3346) {