diff --git a/common/chat-template.cpp b/common/chat-template.cpp
index ed37513be..eee134dba 100644
--- a/common/chat-template.cpp
+++ b/common/chat-template.cpp
@@ -126,11 +126,17 @@ std::string llama_chat_template::apply(
auto context = minja::Context::make(json({
{"messages", actual_messages},
- {"tools", tools},
{"add_generation_prompt", add_generation_prompt},
{"bos_token", _bos_token},
{"eos_token", _eos_token},
}));
+ if (!tools.is_null()) {
+ auto tools_val = minja::Value(tools);
+ context->set("tools", tools_val);
+ auto builtin_tools = minja::Value(json {"wolfram_alpha", "brave_search"});
+ context->set("builtin_tools", builtin_tools);
+ }
+
return _template_root->render(context);
}
diff --git a/tests/chat/contexts/tool_use.json b/tests/chat/contexts/tool_use.json
index cd49885b0..07719fc27 100644
--- a/tests/chat/contexts/tool_use.json
+++ b/tests/chat/contexts/tool_use.json
@@ -21,7 +21,7 @@
{
"role": "tool",
"name": "ipython",
- "content": "{\"stdout\": \"Hello, World!\"}"
+ "content": {"stdout": "Hello, World!"}
},
{
"role": "assistant",
@@ -48,7 +48,7 @@
{
"role": "tool",
"name": "test",
- "content": "true"
+ "content": true
},
{
"role": "assistant",
@@ -75,7 +75,7 @@
{
"role": "tool",
"name": "brave_search",
- "content": "{\"title\":\"Truth: don't ask the web, ask an LLM instead!\",\"url\":\"https://en.wikipedia.org/wiki/Truth\"}"
+ "content": {"title":"Truth: don't ask the web, ask an LLM instead!","url":"https://en.wikipedia.org/wiki/Truth"}
},
{
"role": "assistant",
diff --git a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-default-simple.txt b/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-default-simple.txt
deleted file mode 100644
index 09e69d792..000000000
--- a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-default-simple.txt
+++ /dev/null
@@ -1 +0,0 @@
-<|startoftext|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>What's your favourite LLM framework?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>llama.cpp!<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
\ No newline at end of file
diff --git a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-default-system.txt b/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-default-system.txt
deleted file mode 100644
index b9bea1cf7..000000000
--- a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-default-system.txt
+++ /dev/null
@@ -1 +0,0 @@
-<|startoftext|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>You only tell the truth.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>What's your favourite LLM framework?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>llama.cpp!<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
\ No newline at end of file
diff --git a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-rag-simple.txt b/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-rag-simple.txt
deleted file mode 100644
index 5495007e1..000000000
--- a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-rag-simple.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-<|startoftext|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
-The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
-
-# System Preamble
-## Basic Rules
-You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
-
-# User Preamble
-## Task and Context
-You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.
-
-## Style Guide
-Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>What's your favourite LLM framework?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>llama.cpp!<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.
-Firstly, Decide which of the retrieved documents are relevant to the user's last input by writing 'Relevant Documents:' followed by comma-separated list of document numbers. If none are relevant, you should instead write 'None'.
-Secondly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user's last input by writing 'Cited Documents:' followed a comma-separated list of document numbers. If you dont want to cite any of them, you should instead write 'None'.
-Finally, Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 0.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
\ No newline at end of file
diff --git a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-rag-system.txt b/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-rag-system.txt
deleted file mode 100644
index f18fe7ff8..000000000
--- a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-rag-system.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-<|startoftext|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
-The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
-
-# System Preamble
-## Basic Rules
-You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
-
-# User Preamble
-You only tell the truth.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>What's your favourite LLM framework?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>llama.cpp!<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.
-Firstly, Decide which of the retrieved documents are relevant to the user's last input by writing 'Relevant Documents:' followed by comma-separated list of document numbers. If none are relevant, you should instead write 'None'.
-Secondly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user's last input by writing 'Cited Documents:' followed a comma-separated list of document numbers. If you dont want to cite any of them, you should instead write 'None'.
-Finally, Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 0.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
\ No newline at end of file
diff --git a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-rag-tool_use.txt b/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-rag-tool_use.txt
deleted file mode 100644
index 6d8b116b2..000000000
--- a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-rag-tool_use.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-<|startoftext|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
-The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
-
-# System Preamble
-## Basic Rules
-You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
-
-# User Preamble
-## Task and Context
-You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.
-
-## Style Guide
-Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Print a hello world message with python.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>Anything else?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Test a tautology.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>Truth is definitely true.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Check it on the web.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>I don't need the web to answer you but I did check, as you asked. What now?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Carefully perform the following instructions, in order, starting each with a new line.
-Firstly, Decide which of the retrieved documents are relevant to the user's last input by writing 'Relevant Documents:' followed by comma-separated list of document numbers. If none are relevant, you should instead write 'None'.
-Secondly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user's last input by writing 'Cited Documents:' followed a comma-separated list of document numbers. If you dont want to cite any of them, you should instead write 'None'.
-Finally, Write 'Grounded answer:' followed by a response to the user's last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 0.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
\ No newline at end of file
diff --git a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-tool_use-simple.txt b/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-tool_use-simple.txt
deleted file mode 100644
index 394cdafb3..000000000
--- a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-tool_use-simple.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-<|startoftext|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
-The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
-
-# System Preamble
-## Basic Rules
-You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
-
-# User Preamble
-## Task and Context
-You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.
-
-## Style Guide
-Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.
-
-## Available Tools
-Here is a list of tools that you have available to you:
-
-<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>What's your favourite LLM framework?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>llama.cpp!<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Write 'Action:' followed by a json-formatted list of actions that you want to perform in order to produce a good response to the user's last input. You can use any of the supplied tools any number of times, but you should aim to execute the minimum number of necessary actions for the input. You should use the `directly-answer` tool if calling the other tools is unnecessary. The list of actions you want to call should be formatted as a list of json objects, for example:
-```json
-[
- {
- "tool_name": title of the tool in the specification,
- "parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
- }
-]```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
\ No newline at end of file
diff --git a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-tool_use-system.txt b/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-tool_use-system.txt
deleted file mode 100644
index 61375a0d4..000000000
--- a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-tool_use-system.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-<|startoftext|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
-The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
-
-# System Preamble
-## Basic Rules
-You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
-
-# User Preamble
-You only tell the truth.
-
-## Available Tools
-Here is a list of tools that you have available to you:
-
-<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>What's your favourite LLM framework?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>llama.cpp!<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Write 'Action:' followed by a json-formatted list of actions that you want to perform in order to produce a good response to the user's last input. You can use any of the supplied tools any number of times, but you should aim to execute the minimum number of necessary actions for the input. You should use the `directly-answer` tool if calling the other tools is unnecessary. The list of actions you want to call should be formatted as a list of json objects, for example:
-```json
-[
- {
- "tool_name": title of the tool in the specification,
- "parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
- }
-]```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
\ No newline at end of file
diff --git a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-tool_use-tool_use.txt b/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-tool_use-tool_use.txt
deleted file mode 100644
index 27dfbbc6f..000000000
--- a/tests/chat/goldens/CohereForAI-c4ai-command-r-plus-tool_use-tool_use.txt
+++ /dev/null
@@ -1,93 +0,0 @@
-<|startoftext|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|># Safety Preamble
-The instructions in this section override those in the task description and style guide sections. Don't answer questions that are harmful or immoral.
-
-# System Preamble
-## Basic Rules
-You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user's requests, you cite your sources in your answers, according to those instructions.
-
-# User Preamble
-## Task and Context
-You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging.
-
-## Style Guide
-Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.
-
-## Available Tools
-Here is a list of tools that you have available to you:
-
-```python
-def ipython(code: str) -> List[Dict]:
- """Runs code in an ipython interpreter and returns the result of the execution after 60 seconds.
-
- Args:
- code (str): The code to run in the ipython interpreter.
- """
- pass
-```
-
-```python
-def brave_search(query: str) -> List[Dict]:
- """Executes a web search with Brave.
-
- Args:
- query (str): The query to search for.
- """
- pass
-```
-
-```python
-def wolfram_alpha(query: str) -> List[Dict]:
- """Executes a query with Wolfram Alpha.
-
- Args:
- query (str): The query to execute.
- """
- pass
-```
-
-```python
-def test(condition: bool) -> List[Dict]:
- """Runs a test.
-
- Args:
- condition (bool): The condition to test.
- """
- pass
-```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Print a hello world message with python.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
-Action:
-```json
-[
- {
- "tool_name": "ipython",
- "parameters": "{\"code\": \"print('Hello, World!')\"}"
- }
-]```
-<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>
-{"stdout": "Hello, World!"}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>Anything else?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Test a tautology.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>None
-Action:
-```json
-[
- {
- "tool_name": "test",
- "parameters": "{\"condition\":true}"
- }
-]```
-<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>
-true<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>Truth is definitely true.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Check it on the web.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>None
-Action:
-```json
-[
- {
- "tool_name": "brave_search",
- "parameters": "{\"query\": \"what is truth anyway am I right?\"}"
- }
-]```
-<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>
-{"title":"Truth: don't ask the web, ask an LLM instead!","url":"https://en.wikipedia.org/wiki/Truth"}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>I don't need the web to answer you but I did check, as you asked. What now?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Write 'Action:' followed by a json-formatted list of actions that you want to perform in order to produce a good response to the user's last input. You can use any of the supplied tools any number of times, but you should aim to execute the minimum number of necessary actions for the input. You should use the `directly-answer` tool if calling the other tools is unnecessary. The list of actions you want to call should be formatted as a list of json objects, for example:
-```json
-[
- {
- "tool_name": title of the tool in the specification,
- "parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
- }
-]```<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
\ No newline at end of file
diff --git a/tests/chat/goldens/NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use-tool_use.txt b/tests/chat/goldens/NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use-tool_use.txt
index 1bfd411d7..b3bd121e7 100644
--- a/tests/chat/goldens/NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use-tool_use.txt
+++ b/tests/chat/goldens/NousResearch-Hermes-2-Pro-Llama-3-8B-tool_use-tool_use.txt
@@ -27,7 +27,7 @@ Print a hello world message with python.<|im_end|>
<|im_end|>
<|im_start|>tool
-{"stdout": "Hello, World!"}
+{'stdout': 'Hello, World!'}
<|im_end|><|im_start|>assistant
Anything else?<|im_end|>
@@ -39,7 +39,7 @@ Test a tautology.<|im_end|>
<|im_end|>
<|im_start|>tool
-true
+True
<|im_end|><|im_start|>assistant
Truth is definitely true.<|im_end|>
@@ -51,7 +51,7 @@ Check it on the web.<|im_end|>
<|im_end|>
<|im_start|>tool
-{"title":"Truth: don't ask the web, ask an LLM instead!","url":"https://en.wikipedia.org/wiki/Truth"}
+{'title': "Truth: don't ask the web, ask an LLM instead!", 'url': 'https://en.wikipedia.org/wiki/Truth'}
<|im_end|><|im_start|>assistant
I don't need the web to answer you but I did check, as you asked. What now?<|im_end|>
diff --git a/tests/chat/goldens/NousResearch-Hermes-2-Pro-Mistral-7B-tool_use-tool_use.txt b/tests/chat/goldens/NousResearch-Hermes-2-Pro-Mistral-7B-tool_use-tool_use.txt
index 1bfd411d7..b3bd121e7 100644
--- a/tests/chat/goldens/NousResearch-Hermes-2-Pro-Mistral-7B-tool_use-tool_use.txt
+++ b/tests/chat/goldens/NousResearch-Hermes-2-Pro-Mistral-7B-tool_use-tool_use.txt
@@ -27,7 +27,7 @@ Print a hello world message with python.<|im_end|>
<|im_end|>
<|im_start|>tool
-{"stdout": "Hello, World!"}
+{'stdout': 'Hello, World!'}
<|im_end|><|im_start|>assistant
Anything else?<|im_end|>
@@ -39,7 +39,7 @@ Test a tautology.<|im_end|>
<|im_end|>
<|im_start|>tool
-true
+True
<|im_end|><|im_start|>assistant
Truth is definitely true.<|im_end|>
@@ -51,7 +51,7 @@ Check it on the web.<|im_end|>
<|im_end|>
<|im_start|>tool
-{"title":"Truth: don't ask the web, ask an LLM instead!","url":"https://en.wikipedia.org/wiki/Truth"}
+{'title': "Truth: don't ask the web, ask an LLM instead!", 'url': 'https://en.wikipedia.org/wiki/Truth'}
<|im_end|><|im_start|>assistant
I don't need the web to answer you but I did check, as you asked. What now?<|im_end|>
diff --git a/tests/chat/goldens/NousResearch-Hermes-3-Llama-3.1-70B-tool_use-tool_use.txt b/tests/chat/goldens/NousResearch-Hermes-3-Llama-3.1-70B-tool_use-tool_use.txt
index 1bfd411d7..b3bd121e7 100644
--- a/tests/chat/goldens/NousResearch-Hermes-3-Llama-3.1-70B-tool_use-tool_use.txt
+++ b/tests/chat/goldens/NousResearch-Hermes-3-Llama-3.1-70B-tool_use-tool_use.txt
@@ -27,7 +27,7 @@ Print a hello world message with python.<|im_end|>
<|im_end|>
<|im_start|>tool
-{"stdout": "Hello, World!"}
+{'stdout': 'Hello, World!'}
<|im_end|><|im_start|>assistant
Anything else?<|im_end|>
@@ -39,7 +39,7 @@ Test a tautology.<|im_end|>
<|im_end|>
<|im_start|>tool
-true
+True
<|im_end|><|im_start|>assistant
Truth is definitely true.<|im_end|>
@@ -51,7 +51,7 @@ Check it on the web.<|im_end|>
<|im_end|>
<|im_start|>tool
-{"title":"Truth: don't ask the web, ask an LLM instead!","url":"https://en.wikipedia.org/wiki/Truth"}
+{'title': "Truth: don't ask the web, ask an LLM instead!", 'url': 'https://en.wikipedia.org/wiki/Truth'}
<|im_end|><|im_start|>assistant
I don't need the web to answer you but I did check, as you asked. What now?<|im_end|>
diff --git a/tests/chat/goldens/Qwen-Qwen2.5-7B-Instruct-tool_use.txt b/tests/chat/goldens/Qwen-Qwen2.5-7B-Instruct-tool_use.txt
index f5fb6a25e..795f5c1c8 100644
--- a/tests/chat/goldens/Qwen-Qwen2.5-7B-Instruct-tool_use.txt
+++ b/tests/chat/goldens/Qwen-Qwen2.5-7B-Instruct-tool_use.txt
@@ -25,7 +25,7 @@ Print a hello world message with python.<|im_end|>
<|im_end|>
<|im_start|>user
-{"stdout": "Hello, World!"}
+{'stdout': 'Hello, World!'}
<|im_end|>
<|im_start|>assistant
Anything else?<|im_end|>
@@ -37,7 +37,7 @@ Test a tautology.<|im_end|>
<|im_end|>
<|im_start|>user
-true
+True
<|im_end|>
<|im_start|>assistant
Truth is definitely true.<|im_end|>
@@ -49,7 +49,7 @@ Check it on the web.<|im_end|>
<|im_end|>
<|im_start|>user
-{"title":"Truth: don't ask the web, ask an LLM instead!","url":"https://en.wikipedia.org/wiki/Truth"}
+{'title': "Truth: don't ask the web, ask an LLM instead!", 'url': 'https://en.wikipedia.org/wiki/Truth'}
<|im_end|>
<|im_start|>assistant
I don't need the web to answer you but I did check, as you asked. What now?<|im_end|>
diff --git a/tests/chat/goldens/Qwen-Qwen2.5-Math-7B-Instruct-tool_use.txt b/tests/chat/goldens/Qwen-Qwen2.5-Math-7B-Instruct-tool_use.txt
index e77903e91..3a97af7ff 100644
--- a/tests/chat/goldens/Qwen-Qwen2.5-Math-7B-Instruct-tool_use.txt
+++ b/tests/chat/goldens/Qwen-Qwen2.5-Math-7B-Instruct-tool_use.txt
@@ -25,7 +25,7 @@ Print a hello world message with python.<|im_end|>
<|im_end|>
<|im_start|>user
-{"stdout": "Hello, World!"}
+{'stdout': 'Hello, World!'}
<|im_end|>
<|im_start|>assistant
Anything else?<|im_end|>
@@ -37,7 +37,7 @@ Test a tautology.<|im_end|>
<|im_end|>
<|im_start|>user
-true
+True
<|im_end|>
<|im_start|>assistant
Truth is definitely true.<|im_end|>
@@ -49,7 +49,7 @@ Check it on the web.<|im_end|>
<|im_end|>
<|im_start|>user
-{"title":"Truth: don't ask the web, ask an LLM instead!","url":"https://en.wikipedia.org/wiki/Truth"}
+{'title': "Truth: don't ask the web, ask an LLM instead!", 'url': 'https://en.wikipedia.org/wiki/Truth'}
<|im_end|>
<|im_start|>assistant
I don't need the web to answer you but I did check, as you asked. What now?<|im_end|>
diff --git a/tests/chat/goldens/THUDM-chatglm3-6b-simple.txt b/tests/chat/goldens/THUDM-chatglm3-6b-simple.txt
deleted file mode 100644
index d1bc10858..000000000
--- a/tests/chat/goldens/THUDM-chatglm3-6b-simple.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-[gMASK]sop<|user|>
- What's your favourite LLM framework?<|assistant|>
- llama.cpp!<|assistant|>
\ No newline at end of file
diff --git a/tests/chat/goldens/THUDM-chatglm3-6b-system.txt b/tests/chat/goldens/THUDM-chatglm3-6b-system.txt
deleted file mode 100644
index 768f8a82d..000000000
--- a/tests/chat/goldens/THUDM-chatglm3-6b-system.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-[gMASK]sop<|system|>
- You only tell the truth.<|user|>
- What's your favourite LLM framework?<|assistant|>
- llama.cpp!<|assistant|>
\ No newline at end of file
diff --git a/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Instruct-simple.txt b/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Instruct-simple.txt
deleted file mode 100644
index d825f5a82..000000000
--- a/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Instruct-simple.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-<|startoftext|>User: What's your favourite LLM framework?
-
-Assistant: llama.cpp!<|endoftext|>Assistant:
\ No newline at end of file
diff --git a/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Instruct-system.txt b/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Instruct-system.txt
deleted file mode 100644
index 5ec17d2de..000000000
--- a/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Instruct-system.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-<|startoftext|>You only tell the truth.
-
-User: What's your favourite LLM framework?
-
-Assistant: llama.cpp!<|endoftext|>Assistant:
\ No newline at end of file
diff --git a/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Lite-Instruct-simple.txt b/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Lite-Instruct-simple.txt
deleted file mode 100644
index d825f5a82..000000000
--- a/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Lite-Instruct-simple.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-<|startoftext|>User: What's your favourite LLM framework?
-
-Assistant: llama.cpp!<|endoftext|>Assistant:
\ No newline at end of file
diff --git a/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Lite-Instruct-system.txt b/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Lite-Instruct-system.txt
deleted file mode 100644
index 5ec17d2de..000000000
--- a/tests/chat/goldens/deepseek-ai-DeepSeek-Coder-V2-Lite-Instruct-system.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-<|startoftext|>You only tell the truth.
-
-User: What's your favourite LLM framework?
-
-Assistant: llama.cpp!<|endoftext|>Assistant:
\ No newline at end of file
diff --git a/tests/chat/goldens/deepseek-ai-DeepSeek-V2.5-simple.txt b/tests/chat/goldens/deepseek-ai-DeepSeek-V2.5-simple.txt
deleted file mode 100644
index eb7d9a5c6..000000000
--- a/tests/chat/goldens/deepseek-ai-DeepSeek-V2.5-simple.txt
+++ /dev/null
@@ -1 +0,0 @@
-<|startoftext|><|User|>What's your favourite LLM framework?<|Assistant|>llama.cpp!<|end▁of▁sentence|><|Assistant|>
\ No newline at end of file
diff --git a/tests/chat/goldens/deepseek-ai-DeepSeek-V2.5-system.txt b/tests/chat/goldens/deepseek-ai-DeepSeek-V2.5-system.txt
deleted file mode 100644
index 932331694..000000000
--- a/tests/chat/goldens/deepseek-ai-DeepSeek-V2.5-system.txt
+++ /dev/null
@@ -1 +0,0 @@
- <|startoftext|>You only tell the truth.<|User|>What's your favourite LLM framework?<|Assistant|>llama.cpp!<|end▁of▁sentence|><|Assistant|>
\ No newline at end of file
diff --git a/tests/chat/goldens/deepseek-ai-deepseek-coder-33b-instruct-simple.txt b/tests/chat/goldens/deepseek-ai-deepseek-coder-33b-instruct-simple.txt
deleted file mode 100644
index 830ed34ce..000000000
--- a/tests/chat/goldens/deepseek-ai-deepseek-coder-33b-instruct-simple.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-<|startoftext|>You are an AI programming assistant, utilizing the Deepseek Coder model, developed by Deepseek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer
-### Instruction:
-What's your favourite LLM framework?
-### Response:
-llama.cpp!
-<|EOT|>
-### Response:
diff --git a/tests/chat/goldens/deepseek-ai-deepseek-coder-33b-instruct-system.txt b/tests/chat/goldens/deepseek-ai-deepseek-coder-33b-instruct-system.txt
deleted file mode 100644
index 847d7545e..000000000
--- a/tests/chat/goldens/deepseek-ai-deepseek-coder-33b-instruct-system.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-<|startoftext|>You only tell the truth.### Instruction:
-What's your favourite LLM framework?
-### Response:
-llama.cpp!
-<|EOT|>
-### Response:
diff --git a/tests/chat/goldens/derek33125-project-angel-chatglm4-simple.txt b/tests/chat/goldens/derek33125-project-angel-chatglm4-simple.txt
deleted file mode 100644
index b226e00d2..000000000
--- a/tests/chat/goldens/derek33125-project-angel-chatglm4-simple.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-[gMASK]<|user|>
-What's your favourite LLM framework?<|assistant|>
-llama.cpp!<|assistant|>
\ No newline at end of file
diff --git a/tests/chat/goldens/derek33125-project-angel-chatglm4-system.txt b/tests/chat/goldens/derek33125-project-angel-chatglm4-system.txt
deleted file mode 100644
index b39676f58..000000000
--- a/tests/chat/goldens/derek33125-project-angel-chatglm4-system.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-[gMASK]<|system|>
-You only tell the truth.<|user|>
-What's your favourite LLM framework?<|assistant|>
-llama.cpp!<|assistant|>
\ No newline at end of file
diff --git a/tests/chat/goldens/derek33125-project-angel-chatglm4-tool_use.txt b/tests/chat/goldens/derek33125-project-angel-chatglm4-tool_use.txt
deleted file mode 100644
index 380c8578b..000000000
--- a/tests/chat/goldens/derek33125-project-angel-chatglm4-tool_use.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-[gMASK]<|user|>
-Print a hello world message with python.<|tool|>
-{"stdout": "Hello, World!"}<|assistant|>
-Anything else?<|user|>
-Test a tautology.<|tool|>
-true<|assistant|>
-Truth is definitely true.<|user|>
-Check it on the web.<|tool|>
-{"title":"Truth: don't ask the web, ask an LLM instead!","url":"https://en.wikipedia.org/wiki/Truth"}<|assistant|>
-I don't need the web to answer you but I did check, as you asked. What now?<|assistant|>
\ No newline at end of file
diff --git a/tests/chat/goldens/meetkai-functionary-medium-v3.1-simple.txt b/tests/chat/goldens/meetkai-functionary-medium-v3.1-simple.txt
deleted file mode 100644
index 415215244..000000000
--- a/tests/chat/goldens/meetkai-functionary-medium-v3.1-simple.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-<|startoftext|><|start_header_id|>system<|end_header_id|>
-
-
-Cutting Knowledge Date: December 2023
-
-<|eot_id|><|start_header_id|>user<|end_header_id|>
-
-What's your favourite LLM framework?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
-llama.cpp!<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
diff --git a/tests/chat/goldens/meetkai-functionary-medium-v3.1-system.txt b/tests/chat/goldens/meetkai-functionary-medium-v3.1-system.txt
deleted file mode 100644
index 3239384b6..000000000
--- a/tests/chat/goldens/meetkai-functionary-medium-v3.1-system.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-<|startoftext|><|start_header_id|>system<|end_header_id|>
-
-
-Cutting Knowledge Date: December 2023
-
-<|eot_id|><|start_header_id|>system<|end_header_id|>
-
-You only tell the truth.<|eot_id|><|start_header_id|>user<|end_header_id|>
-
-What's your favourite LLM framework?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
-llama.cpp!<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
diff --git a/tests/chat/goldens/meetkai-functionary-medium-v3.1-tool_use.txt b/tests/chat/goldens/meetkai-functionary-medium-v3.1-tool_use.txt
deleted file mode 100644
index 3802abb0b..000000000
--- a/tests/chat/goldens/meetkai-functionary-medium-v3.1-tool_use.txt
+++ /dev/null
@@ -1,66 +0,0 @@
-<|startoftext|><|start_header_id|>system<|end_header_id|>
-
-
-Cutting Knowledge Date: December 2023
-
-
-You have access to the following functions:
-
-Use the function 'ipython' to 'Runs code in an ipython interpreter and returns the result of the execution after 60 seconds.'
-{"name": "ipython", "description": "Runs code in an ipython interpreter and returns the result of the execution after 60 seconds.", "parameters": {"type": "object", "properties": {"code": {"type": "string", "description": "The code to run in the ipython interpreter."}}, "required": ["code"]}}
-
-Use the function 'brave_search' to 'Executes a web search with Brave.'
-{"name": "brave_search", "description": "Executes a web search with Brave.", "parameters": {"type": "object", "properties": {"query": {"type": "string", "description": "The query to search for."}}, "required": ["query"]}}
-
-Use the function 'wolfram_alpha' to 'Executes a query with Wolfram Alpha.'
-{"name": "wolfram_alpha", "description": "Executes a query with Wolfram Alpha.", "parameters": {"type": "object", "properties": {"query": {"type": "string", "description": "The query to execute."}}, "required": ["query"]}}
-
-Use the function 'test' to 'Runs a test.'
-{"name": "test", "description": "Runs a test.", "parameters": {"type": "object", "properties": {"condition": {"type": "boolean", "description": "The condition to test."}}, "required": ["condition"]}}
-
-
-Think very carefully before calling functions.
-If a you choose to call a function ONLY reply in the following format:
-<{start_tag}={function_name}>{parameters}{end_tag}
-where
-
-start_tag => ` a JSON dict with the function argument name as key and function argument value as value.
-end_tag => ``
-
-Here is an example,
-{"example_name": "example_value"}
-
-Reminder:
-- If looking for real time information use relevant functions before falling back to brave_search
-- Function calls MUST follow the specified format, start with
-- Required parameters MUST be specified
-- Only call one function at a time
-- Put the entire function call reply on one line
-
-<|eot_id|><|start_header_id|>user<|end_header_id|>
-
-Print a hello world message with python.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
-{"code": "print('Hello, World!')"}<|eom_id|><|start_header_id|>ipython<|end_header_id|>
-
-{"stdout": "Hello, World!"}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
-Anything else?<|eot_id|><|start_header_id|>user<|end_header_id|>
-
-Test a tautology.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
-{"condition":true}<|eom_id|><|start_header_id|>ipython<|end_header_id|>
-
-true<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
-Truth is definitely true.<|eot_id|><|start_header_id|>user<|end_header_id|>
-
-Check it on the web.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
-{"query": "what is truth anyway am I right?"}<|eom_id|><|start_header_id|>ipython<|end_header_id|>
-
-{"title":"Truth: don't ask the web, ask an LLM instead!","url":"https://en.wikipedia.org/wiki/Truth"}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
-I don't need the web to answer you but I did check, as you asked. What now?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
diff --git a/tests/chat/goldens/meetkai-functionary-medium-v3.2-simple.txt b/tests/chat/goldens/meetkai-functionary-medium-v3.2-simple.txt
deleted file mode 100644
index 3c20de4f5..000000000
--- a/tests/chat/goldens/meetkai-functionary-medium-v3.2-simple.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-<|startoftext|><|start_header_id|>system<|end_header_id|>
-
-You are capable of executing available function(s) if required.
-Only execute function(s) when absolutely necessary.
-Ask for the required input to:recipient==all
-Use JSON for function arguments.
-Respond in this format:
->>>${recipient}
-${content}
-Available functions:
-// Supported function definitions that should be called when necessary.
-namespace functions {
-
-} // namespace functions<|eot_id|><|start_header_id|>user<|end_header_id|>
-
-What's your favourite LLM framework?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>all
-llama.cpp!<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>
\ No newline at end of file
diff --git a/tests/chat/goldens/meetkai-functionary-medium-v3.2-system.txt b/tests/chat/goldens/meetkai-functionary-medium-v3.2-system.txt
deleted file mode 100644
index a006497cf..000000000
--- a/tests/chat/goldens/meetkai-functionary-medium-v3.2-system.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-<|startoftext|><|start_header_id|>system<|end_header_id|>
-
-You are capable of executing available function(s) if required.
-Only execute function(s) when absolutely necessary.
-Ask for the required input to:recipient==all
-Use JSON for function arguments.
-Respond in this format:
->>>${recipient}
-${content}
-Available functions:
-// Supported function definitions that should be called when necessary.
-namespace functions {
-
-} // namespace functions<|eot_id|><|start_header_id|>system<|end_header_id|>
-
-You only tell the truth.<|eot_id|><|start_header_id|>user<|end_header_id|>
-
-What's your favourite LLM framework?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>all
-llama.cpp!<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>
\ No newline at end of file
diff --git a/tests/chat/goldens/meetkai-functionary-medium-v3.2-tool_use.txt b/tests/chat/goldens/meetkai-functionary-medium-v3.2-tool_use.txt
deleted file mode 100644
index 6c134bc65..000000000
--- a/tests/chat/goldens/meetkai-functionary-medium-v3.2-tool_use.txt
+++ /dev/null
@@ -1,70 +0,0 @@
-<|startoftext|><|start_header_id|>system<|end_header_id|>
-
-You are capable of executing available function(s) if required.
-Only execute function(s) when absolutely necessary.
-Ask for the required input to:recipient==all
-Use JSON for function arguments.
-Respond in this format:
->>>${recipient}
-${content}
-Available functions:
-// Supported function definitions that should be called when necessary.
-namespace functions {
-
-// Runs code in an ipython interpreter and returns the result of the execution after 60 seconds.
-type ipython = (_: {
-// The code to run in the ipython interpreter.
-code: string,
-}) => any;
-
-// Executes a web search with Brave.
-type brave_search = (_: {
-// The query to search for.
-query: string,
-}) => any;
-
-// Executes a query with Wolfram Alpha.
-type wolfram_alpha = (_: {
-// The query to execute.
-query: string,
-}) => any;
-
-// Runs a test.
-type test = (_: {
-// The condition to test.
-condition: boolean,
-}) => any;
-
-} // namespace functions<|eot_id|><|start_header_id|>user<|end_header_id|>
-
-Print a hello world message with python.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>ipython
-{"code": "print('Hello, World!')"}<|eot_id|><|start_header_id|>tool<|end_header_id|>
-
-{"stdout": "Hello, World!"}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>all
-Anything else?<|eot_id|><|start_header_id|>user<|end_header_id|>
-
-Test a tautology.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>test
-{"condition":true}<|eot_id|><|start_header_id|>tool<|end_header_id|>
-
-true<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>all
-Truth is definitely true.<|eot_id|><|start_header_id|>user<|end_header_id|>
-
-Check it on the web.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>brave_search
-{"query": "what is truth anyway am I right?"}<|eot_id|><|start_header_id|>tool<|end_header_id|>
-
-{"title":"Truth: don't ask the web, ask an LLM instead!","url":"https://en.wikipedia.org/wiki/Truth"}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>all
-I don't need the web to answer you but I did check, as you asked. What now?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
-
->>>
\ No newline at end of file
diff --git a/tests/chat/goldens/meta-llama-Meta-Llama-3.1-8B-Instruct-tool_use.txt b/tests/chat/goldens/meta-llama-Meta-Llama-3.1-8B-Instruct-tool_use.txt
index 0c2c6a921..0fc7178c0 100644
--- a/tests/chat/goldens/meta-llama-Meta-Llama-3.1-8B-Instruct-tool_use.txt
+++ b/tests/chat/goldens/meta-llama-Meta-Llama-3.1-8B-Instruct-tool_use.txt
@@ -96,7 +96,7 @@ Print a hello world message with python.<|eot_id|><|start_header_id|>assistant<|
{"name": "ipython", "parameters": {"code": "print('Hello, World!')"}}<|eom_id|><|start_header_id|>ipython<|end_header_id|>
-"{\"stdout\": \"Hello, World!\"}"<|eot_id|><|start_header_id|>assistant<|end_header_id|>
+{"stdout": "Hello, World!"}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
Anything else?<|eot_id|><|start_header_id|>user<|end_header_id|>
@@ -104,7 +104,7 @@ Test a tautology.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
{"name": "test", "parameters": {"condition": true}}<|eom_id|><|start_header_id|>ipython<|end_header_id|>
-"true"<|eot_id|><|start_header_id|>assistant<|end_header_id|>
+True<|eot_id|><|start_header_id|>assistant<|end_header_id|>
Truth is definitely true.<|eot_id|><|start_header_id|>user<|end_header_id|>
@@ -112,7 +112,7 @@ Check it on the web.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
<|python_tag|>brave_search.call(query="what is truth anyway am I right?")<|eom_id|><|start_header_id|>ipython<|end_header_id|>
-"{\"title\":\"Truth: don't ask the web, ask an LLM instead!\",\"url\":\"https://en.wikipedia.org/wiki/Truth\"}"<|eot_id|><|start_header_id|>assistant<|end_header_id|>
+{"title": "Truth: don't ask the web, ask an LLM instead!", "url": "https://en.wikipedia.org/wiki/Truth"}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
I don't need the web to answer you but I did check, as you asked. What now?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
diff --git a/tests/chat/templates/CohereForAI-c4ai-command-r-plus-default.jinja b/tests/chat/templates/CohereForAI-c4ai-command-r-plus-default.jinja
deleted file mode 100644
index 228014696..000000000
--- a/tests/chat/templates/CohereForAI-c4ai-command-r-plus-default.jinja
+++ /dev/null
@@ -1 +0,0 @@
-{{ bos_token }}{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% elif false == true %}{% set loop_messages = messages %}{% set system_message = 'You are Command-R, a brilliant, sophisticated, AI-assistant trained to assist human users by providing thorough responses. You are trained by Cohere.' %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% if system_message != false %}{{ '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>' + system_message + '<|END_OF_TURN_TOKEN|>' }}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% set content = message['content'] %}{% if message['role'] == 'user' %}{{ '<|START_OF_TURN_TOKEN|><|USER_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' }}{% elif message['role'] == 'assistant' %}{{ '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' }}{% endif %}
\ No newline at end of file
diff --git a/tests/chat/templates/CohereForAI-c4ai-command-r-plus-rag.jinja b/tests/chat/templates/CohereForAI-c4ai-command-r-plus-rag.jinja
deleted file mode 100644
index 6637a01a9..000000000
--- a/tests/chat/templates/CohereForAI-c4ai-command-r-plus-rag.jinja
+++ /dev/null
@@ -1,16 +0,0 @@
-{{ bos_token }}{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% set system_message = '## Task and Context\nYou help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user\'s needs as best you can, which will be wide-ranging.\n\n## Style Guide\nUnless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.' %}{% endif %}{{ '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>' }}{{ '# Safety Preamble' }}{{ '
-The instructions in this section override those in the task description and style guide sections. Don\'t answer questions that are harmful or immoral.' }}{{ '
-
-# System Preamble' }}{{ '
-## Basic Rules' }}{{ '
-You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user\'s requests, you cite your sources in your answers, according to those instructions.' }}{{ '
-
-# User Preamble' }}{{ '
-' + system_message }}{{ '<|END_OF_TURN_TOKEN|>'}}{% for message in loop_messages %}{% set content = message['content'] %}{% if message['role'] == 'user' %}{{ '<|START_OF_TURN_TOKEN|><|USER_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' }}{% elif message['role'] == 'system' %}{{ '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' }}{% elif message['role'] == 'assistant' %}{{ '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' }}{% endif %}{% endfor %}{{ '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>'}}{{ '' }}{% for document in documents %}{{ '
-Document: ' }}{{ loop.index0 }}
-{% for key, value in document.items() %}{{ key }}: {{value}}
-{% endfor %}{% endfor %}{{ ''}}{{ '<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>' }}{{ 'Carefully perform the following instructions, in order, starting each with a new line.
-' }}{{ 'Firstly, Decide which of the retrieved documents are relevant to the user\'s last input by writing \'Relevant Documents:\' followed by comma-separated list of document numbers. If none are relevant, you should instead write \'None\'.
-' }}{{ 'Secondly, Decide which of the retrieved documents contain facts that should be cited in a good answer to the user\'s last input by writing \'Cited Documents:\' followed a comma-separated list of document numbers. If you dont want to cite any of them, you should instead write \'None\'.
-' }}{% if citation_mode=='accurate' %}{{ 'Thirdly, Write \'Answer:\' followed by a response to the user\'s last input in high quality natural english. Use the retrieved documents to help you. Do not insert any citations or grounding markup.
-' }}{% endif %}{{ 'Finally, Write \'Grounded answer:\' followed by a response to the user\'s last input in high quality natural english. Use the symbols and to indicate when a fact comes from a document in the search result, e.g my fact for a fact from document 0.' }}{{ '<|END_OF_TURN_TOKEN|>' }}{% if add_generation_prompt %}{{ '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' }}{% endif %}
\ No newline at end of file
diff --git a/tests/chat/templates/CohereForAI-c4ai-command-r-plus-tool_use.jinja b/tests/chat/templates/CohereForAI-c4ai-command-r-plus-tool_use.jinja
deleted file mode 100644
index f5baef30b..000000000
--- a/tests/chat/templates/CohereForAI-c4ai-command-r-plus-tool_use.jinja
+++ /dev/null
@@ -1,202 +0,0 @@
-
-{%- macro json_to_python_type(json_spec) %}
-{%- set basic_type_map = {
- "string": "str",
- "number": "float",
- "integer": "int",
- "boolean": "bool"
-} %}
-
-{%- if basic_type_map[json_spec.type] is defined %}
- {{- basic_type_map[json_spec.type] }}
-{%- elif json_spec.type == "array" %}
- {{- "List[" + json_to_python_type(json_spec.items) + "]"}}
-{%- elif json_spec.type == "object" %}
- {{- "Dict[str, " + json_to_python_type(json_spec.additionalProperties) + ']'}}
-{%- elif json_spec.type is iterable %}
- {{- "Union[" }}
- {%- for t in json_spec.type %}
- {{- json_to_python_type({"type": t}) }}
- {%- if not loop.last %}
- {{- "," }}
- {%- endif %}
- {%- endfor %}
- {{- "]" }}
-{%- else %}
- {{- "Any" }}
-{%- endif %}
-{%- endmacro %}
-
-{%- macro old_tool_parser(tools) %}
-{%- for tool in tools %}
- {%- if loop.index0 != 0 %}
- {{- '\n\n' }}
- {%- endif %}
- {{- '```python\ndef ' + tool.name + '(' }}
- {%- for param_name, param_fields in tool.parameter_definitions|items %}
- {%- if loop.index0 != 0 %}
- {{- ', '}}
- {%- endif %}
- {{- param_name + ': ' }}
- {%- if not param_fields.required %}
- {{- 'Optional[' + param_fields.type + '] = None'}}
- {%- else %}
- {{- param_fields.type }}
- {%- endif %}
- {%- endfor %}
- {{- ') -> List[Dict]:\n """'}}
- {{- tool.description }}
- {%- if tool.parameter_definitions|length != 0 %}
- {{- '\n\n Args:\n '}}
- {%- for param_name, param_fields in tool.parameter_definitions|items %}
- {%- if loop.index0 != 0 %}
- {{- '\n ' }}
- {%- endif %}
- {{- param_name + ' ('}}
- {%- if not param_fields.required %}
- {{- 'Optional[' + param_fields.type + ']'}}
- {%- else %}
- {{- param_fields.type }}
- {%- endif %}
- {{- '): ' + param_fields.description }}
- {%- endfor %}
- {%- endif %}
- {{- '\n """\n pass\n```' }}
-{%- endfor %}
-{%- endmacro %}
-
-{%- macro new_tool_parser(tools) %}
-{%- for tool in tools %}
- {%- if loop.index0 != 0 %}
- {{- '\n\n'}}
- {%- endif %}
- {%- if tool.function is defined %}
- {%- set tool = tool.function %}
- {%- endif %}
- {{-'```python
-def ' + tool.name + '('}}
- {%- for param_name, param_fields in tool.parameters.properties|items %}
- {%- if loop.index0 != 0 %}
- {{- ', '}}
- {%- endif %}
- {{-param_name + ": "}}
- {%- if not param_name in tool.parameters.required %}
- {{-'Optional[' + json_to_python_type(param_fields) + '] = None'}}
- {%- else %}
- {{- json_to_python_type(param_fields) }}
- {%- endif %}
- {%- endfor %}
- {{- ') -> List[Dict]:
- """'}}
- {{- tool.description }}
- {%- if tool.parameters.properties|length != 0 %}
- {{- '\n\n Args:\n '}}
- {%- for param_name, param_fields in tool.parameters.properties|items %}
- {%- if loop.index0 != 0 %}
- {{- '\n ' }}
- {%- endif %}
- {{- param_name + ' ('}}
- {%- if not param_name in tool.parameters.required %}
- {{-'Optional[' + json_to_python_type(param_fields) + ']'}}
- {%- else %}
- {{- json_to_python_type(param_fields) }}
- {%- endif %}
- {{- '): ' + param_fields.description }}
- {%- endfor %}
- {%- endif %}
- {{- '\n """\n pass\n```' }}
-{%- endfor %}
-{%- endmacro %}
-
-{{- bos_token }}
-{%- if messages[0]['role'] == 'system' %}
- {%- set loop_messages = messages[1:] %}
- {%- set system_message = messages[0]['content'] %}
-{%- else %}
- {%- set loop_messages = messages %}
- {%- set system_message = '## Task and Context\nYou help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user\'s needs as best you can, which will be wide-ranging.\n\n## Style Guide\nUnless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling.' %}
-{%- endif %}
-{{- '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>' }}
-{{- '# Safety Preamble' }}
-{{- '
-The instructions in this section override those in the task description and style guide sections. Don\'t answer questions that are harmful or immoral.' }}
-{{- '
-
-# System Preamble' }}
-{{- '
-## Basic Rules' }}
-{{- '
-You are a powerful conversational AI trained by Cohere to help people. You are augmented by a number of tools, and your job is to use and consume the output of these tools to best help the user. You will see a conversation history between yourself and a user, ending with an utterance from the user. You will then see a specific instruction instructing you what kind of response to generate. When you answer the user\'s requests, you cite your sources in your answers, according to those instructions.' }}
-{{- '
-
-# User Preamble' }}
-{{- '
-' + system_message }}
-{{-'
-
-## Available Tools
-Here is a list of tools that you have available to you:
-
-'}}
-{%- set ns = namespace(new_tools=true) %}
-{%- for tool in tools %}
- {%- if tool.parameter_definitions is defined %}
- {%- set ns.new_tools = false %}
- {%- endif %}
-{%- endfor %}
-{%- if ns.new_tools %}
- {{- new_tool_parser(tools) }}
-{%- else %}
- {{- old_tool_parser(tools) }}
-{%- endif %}
-{{- '<|END_OF_TURN_TOKEN|>'}}
-{%- for message in loop_messages %}
- {%- set content = message['content'] %}
- {%- if message.role == 'user' %}
- {{- '<|START_OF_TURN_TOKEN|><|USER_TOKEN|>' + content|trim + '<|END_OF_TURN_TOKEN|>' }}
- {%- elif message.role == 'system' %}
- {{- '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>' + content|trim + '<|END_OF_TURN_TOKEN|>' }}
- {%- elif message.role == 'assistant' and message.tool_calls is defined %}
- {{- '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' }}
- {%- if message.content is defined %}
- {{- message.content|trim }}
- {%- endif %}
- {{- '\nAction:\n```json\n[\n' }}
- {%- for tool_call in message.tool_calls %}
- {%- if tool_call.function is defined %}
- {%- set tool_call = tool_call.function %}
- {%- endif %}
- {{- '{\n'|indent(4, first=true) }}
- {{- '"tool_name": "'|indent(8, first=true) + tool_call.name + '",\n' }}
- {{- '"parameters": '|indent(8, first=true) }}
- {%- if tool_call.arguments is defined and tool_call.arguments|length > 0 %}
- {{- tool_call.arguments|tojson(indent=4)|indent(8) }}
- {{- '\n' }}
- {%- else %}
- {{- '{}\n' }}
- {%- endif %}
- {{- '}'|indent(4, first=true) }}
- {%- if not loop.last %}
- {{- ',\n' }}
- {%- endif %}
- {%- endfor %}
- {{- "\n]```\n" }}
- {%- elif message.role == 'assistant' %}
- {{- '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' + content|trim + '<|END_OF_TURN_TOKEN|>' }}
- {%- elif message.role == 'tool' %}
- {{- '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>\n' }}
- {{- message.content|trim }}
- {{- '<|END_OF_TURN_TOKEN|>' }}
- {%- endif %}
-{%- endfor %}
-{{-'<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>Write \'Action:\' followed by a json-formatted list of actions that you want to perform in order to produce a good response to the user\'s last input. You can use any of the supplied tools any number of times, but you should aim to execute the minimum number of necessary actions for the input. You should use the `directly-answer` tool if calling the other tools is unnecessary. The list of actions you want to call should be formatted as a list of json objects, for example:
-```json
-[
- {
- "tool_name": title of the tool in the specification,
- "parameters": a dict of parameters to input into the tool as they are defined in the specs, or {} if it takes no parameters
- }
-]```<|END_OF_TURN_TOKEN|>'}}
-{%- if add_generation_prompt %}
- {{- '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' }}
-{%- endif %}
diff --git a/tests/chat/templates/THUDM-chatglm3-6b.jinja b/tests/chat/templates/THUDM-chatglm3-6b.jinja
deleted file mode 100644
index b2e614b60..000000000
--- a/tests/chat/templates/THUDM-chatglm3-6b.jinja
+++ /dev/null
@@ -1,3 +0,0 @@
-{% for message in messages %}{% if loop.first %}[gMASK]sop<|{{ message['role'] }}|>
- {{ message['content'] }}{% else %}<|{{ message['role'] }}|>
- {{ message['content'] }}{% endif %}{% endfor %}{% if add_generation_prompt %}<|assistant|>{% endif %}
\ No newline at end of file
diff --git a/tests/chat/templates/deepseek-ai-DeepSeek-Coder-V2-Instruct.jinja b/tests/chat/templates/deepseek-ai-DeepSeek-Coder-V2-Instruct.jinja
deleted file mode 100644
index 66050bdbd..000000000
--- a/tests/chat/templates/deepseek-ai-DeepSeek-Coder-V2-Instruct.jinja
+++ /dev/null
@@ -1,5 +0,0 @@
-{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{{ bos_token }}{% for message in messages %}{% if message['role'] == 'user' %}{{ 'User: ' + message['content'] + '
-
-' }}{% elif message['role'] == 'assistant' %}{{ 'Assistant: ' + message['content'] + eos_token }}{% elif message['role'] == 'system' %}{{ message['content'] + '
-
-' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %}
\ No newline at end of file
diff --git a/tests/chat/templates/deepseek-ai-DeepSeek-Coder-V2-Lite-Instruct.jinja b/tests/chat/templates/deepseek-ai-DeepSeek-Coder-V2-Lite-Instruct.jinja
deleted file mode 100644
index 66050bdbd..000000000
--- a/tests/chat/templates/deepseek-ai-DeepSeek-Coder-V2-Lite-Instruct.jinja
+++ /dev/null
@@ -1,5 +0,0 @@
-{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{{ bos_token }}{% for message in messages %}{% if message['role'] == 'user' %}{{ 'User: ' + message['content'] + '
-
-' }}{% elif message['role'] == 'assistant' %}{{ 'Assistant: ' + message['content'] + eos_token }}{% elif message['role'] == 'system' %}{{ message['content'] + '
-
-' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %}
\ No newline at end of file
diff --git a/tests/chat/templates/deepseek-ai-DeepSeek-V2.5.jinja b/tests/chat/templates/deepseek-ai-DeepSeek-V2.5.jinja
deleted file mode 100644
index e6ba24848..000000000
--- a/tests/chat/templates/deepseek-ai-DeepSeek-V2.5.jinja
+++ /dev/null
@@ -1 +0,0 @@
-{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='') %}{%- for message in messages %} {%- if message['role'] == 'system' %} {% set ns.system_prompt = message['content'] %} {%- endif %}{%- endfor %}{{bos_token}}{{ns.system_prompt}}{%- for message in messages %} {%- if message['role'] == 'user' %} {%- set ns.is_tool = false -%}{{'<|User|>' + message['content']}} {%- endif %} {%- if message['role'] == 'assistant' and message['content'] is none %} {%- set ns.is_tool = false -%} {%- for tool in message['tool_calls']%} {%- if not ns.is_first %}{{'<|Assistant|><|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}} {%- set ns.is_first = true -%} {%- else %}{{'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}} {%- endif %} {%- endfor %} {%- endif %} {%- if message['role'] == 'assistant' and message['content'] is not none %} {%- if ns.is_tool %}{{'<|tool▁outputs▁end|>' + message['content'] + '<|end▁of▁sentence|>'}} {%- set ns.is_tool = false -%} {%- else %}{{'<|Assistant|>' + message['content'] + '<|end▁of▁sentence|>'}} {%- endif %} {%- endif %} {%- if message['role'] == 'tool' %} {%- set ns.is_tool = true -%} {%- if ns.is_output_first %}{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}} {%- set ns.is_output_first = false %} {%- else %}{{'\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}} {%- endif %} {%- endif %}{%- endfor -%}{% if ns.is_tool %}{{'<|tool▁outputs▁end|>'}}{% endif %}{% if add_generation_prompt and not ns.is_tool %}{{'<|Assistant|>'}}{% endif %}
\ No newline at end of file
diff --git a/tests/chat/templates/deepseek-ai-deepseek-coder-33b-instruct.jinja b/tests/chat/templates/deepseek-ai-deepseek-coder-33b-instruct.jinja
deleted file mode 100644
index 7be73618e..000000000
--- a/tests/chat/templates/deepseek-ai-deepseek-coder-33b-instruct.jinja
+++ /dev/null
@@ -1,26 +0,0 @@
-{% if not add_generation_prompt is defined %}
-{% set add_generation_prompt = false %}
-{% endif %}
-{%- set ns = namespace(found=false) -%}
-{%- for message in messages -%}
- {%- if message['role'] == 'system' -%}
- {%- set ns.found = true -%}
- {%- endif -%}
-{%- endfor -%}
-{{bos_token}}{%- if not ns.found -%}
-{{'You are an AI programming assistant, utilizing the Deepseek Coder model, developed by Deepseek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer\n'}}
-{%- endif %}
-{%- for message in messages %}
- {%- if message['role'] == 'system' %}
-{{ message['content'] }}
- {%- else %}
- {%- if message['role'] == 'user' %}
-{{'### Instruction:\n' + message['content'] + '\n'}}
- {%- else %}
-{{'### Response:\n' + message['content'] + '\n<|EOT|>\n'}}
- {%- endif %}
- {%- endif %}
-{%- endfor %}
-{% if add_generation_prompt %}
-{{'### Response:'}}
-{% endif %}
\ No newline at end of file
diff --git a/tests/chat/templates/derek33125-project-angel-chatglm4.jinja b/tests/chat/templates/derek33125-project-angel-chatglm4.jinja
deleted file mode 100644
index ed10d0cf2..000000000
--- a/tests/chat/templates/derek33125-project-angel-chatglm4.jinja
+++ /dev/null
@@ -1,37 +0,0 @@
-[gMASK]{% for item in messages %}{% if item['tools'] is defined %}<|system|>
-你是一个名为 ChatGLM 的人工智能助手。你是基于智谱AI训练的语言模型 GLM-4 模型开发的,你的任务是针对用户的问题和要求提供适当的答复和支持。
-
-# 可用工具{% set tools = item['tools'] %}{% for tool in tools %}{% if tool['type'] == 'function' %}
-
-## {{ tool['function']['name'] }}
-
-{{ tool['function'] | tojson(indent=4) }}
-在调用上述函数时,请使用 Json 格式表示调用的参数。{% elif tool['type'] == 'python' %}
-
-## python
-
-当你向 `python` 发送包含 Python 代码的消息时,该代码将会在一个有状态的 Jupyter notebook 环境中执行。
-`python` 返回代码执行的输出,或在执行 60 秒后返回超时。
-`/mnt/data` 将会持久化存储你的文件。在此会话中,`python` 无法访问互联网。不要使用 `python` 进行任何网络请求或者在线 API 调用,这些在线内容的访问将不会成功。{% elif tool['type'] == 'simple_browser' %}
-
-## simple_browser
-
-你可以使用 `simple_browser` 工具。该工具支持以下函数:
-`search(query: str, recency_days: int)`:使用搜索引擎进行查询并显示结果,可以使用 `recency_days` 参数控制搜索内容的时效性。
-`mclick(ids: list[int])`:获取一系列指定 id 的页面内容。每次调用时,须选择3-10个页面。选择多个角度的页面,同时尽可能选择可信任的信息来源。考虑到部分页面是无法加载的,你也可以多打开一些可能有用的页面而不用担心内容过多。
-`open_url(url: str)`:打开指定的 URL。
-
-使用 `【{引用 id}†{引用文本}】` 来引用内容。
-
-操作步骤:1. 使用 `search` 来获得信息列表; 2. 使用 `mclick` 来获取指定 ID 页面的内容; 3. 根据获得的内容进行回复。在回复中应当引用信息来源。
- 如果用户提供了 URL,也可以用 `open_url` 直接打开页面。
-如果初次搜索结果没有找到合适的信息,也可以再次使用 `search` 进行搜索。{% elif tool['type'] == 'cogview' %}
-
-## cogview
-
-如果用户的请求中包含了对图像的描述,你可以使用 `cogview` 来生成图像并展示给用户。你需要向 `cogview` 发送图像描述,规则:
-- 发送给 `cogview` 的消息必须使用英语。用户的中文描述必须完全翻译为英语。
-- 应当尽可能详细地描述图像生成的需求,需求描述约 100 英文单词。
-- 保持用户原始描述的意图。不要虚构内容或者没见过的人物。
-- 如无特殊说明,所在地为中国,持有中国立场并遵循中国社会主义价值观。{% endif %}{% endfor %}{% endif %}{% if item['content'] %}<|{{ item['role'] }}|>{{ item['metadata'] }}
-{{ item['content'] }}{% endif %}{% endfor %}{% if add_generation_prompt %}<|assistant|>{% endif %}
\ No newline at end of file
diff --git a/tests/chat/templates/meetkai-functionary-medium-v3.1.jinja b/tests/chat/templates/meetkai-functionary-medium-v3.1.jinja
deleted file mode 100644
index 29d64a215..000000000
--- a/tests/chat/templates/meetkai-functionary-medium-v3.1.jinja
+++ /dev/null
@@ -1,58 +0,0 @@
-{# version=v3-llama3.1 #}{%- if not tools is defined -%}
- {%- set tools = none -%}
-{%- endif -%}
-
-{%- set has_code_interpreter = tools | selectattr("type", "equalto", "code_interpreter") | list | length > 0 -%}
-{%- if has_code_interpreter -%}
- {%- set tools = tools | rejectattr("type", "equalto", "code_interpreter") | list -%}
-{%- endif -%}
-
-{#- System message + builtin tools #}
-{{- bos_token + "<|start_header_id|>system<|end_header_id|>\n\n" }}
-{%- if has_code_interpreter %}
- {{- "Environment: ipython\n\n" }}
-{%- else -%}
- {{ "\n"}}
-{%- endif %}
-{{- "Cutting Knowledge Date: December 2023\n\n" }}
-{%- if tools %}
- {{- "\nYou have access to the following functions:\n\n" }}
- {%- for t in tools %}
- {%- if "type" in t -%}
- {{ "Use the function '"|safe + t["function"]["name"] + "' to '"|safe + t["function"]["description"] + "'\n"|safe + t["function"] | tojson() }}
- {%- else -%}
- {{ "Use the function '"|safe + t["name"] + "' to '"|safe + t["description"] + "'\n"|safe + t | tojson() }}
- {%- endif -%}
- {{- "\n\n" }}
- {%- endfor %}
- {{- '\nThink very carefully before calling functions.\nIf a you choose to call a function ONLY reply in the following format:\n<{start_tag}={function_name}>{parameters}{end_tag}\nwhere\n\nstart_tag => ` a JSON dict with the function argument name as key and function argument value as value.\nend_tag => ``\n\nHere is an example,\n{"example_name": "example_value"}\n\nReminder:\n- If looking for real time information use relevant functions before falling back to brave_search\n- Function calls MUST follow the specified format, start with \n- Required parameters MUST be specified\n- Only call one function at a time\n- Put the entire function call reply on one line\n\n' -}}
-{%- endif %}
-{{- "<|eot_id|>" -}}
-
-{%- for message in messages -%}
- {%- if message['role'] == 'user' or message['role'] == 'system' -%}
- {{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' }}
- {%- elif message['role'] == 'tool' -%}
- {{ '<|start_header_id|>ipython<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' }}
- {%- else -%}
- {{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'}}
- {%- if message['content'] -%}
- {{ message['content'] }}
- {%- endif -%}
- {%- if 'tool_calls' in message and message['tool_calls'] -%}
- {%- for tool_call in message['tool_calls'] -%}
- {%- if tool_call["function"]["name"] == "python" -%}
- {{ '<|python_tag|>' + tool_call['function']['arguments'] }}
- {%- else -%}
- {{ '' + tool_call['function']['arguments'] + '' }}
- {%- endif -%}
- {%- endfor -%}
- {{ '<|eom_id|>' }}
- {%- else -%}
- {{ '<|eot_id|>' }}
- {%- endif -%}
- {%- endif -%}
-{%- endfor -%}
-{%- if add_generation_prompt -%}
- {{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}
-{%- endif -%}
\ No newline at end of file
diff --git a/tests/chat/templates/meetkai-functionary-medium-v3.2.jinja b/tests/chat/templates/meetkai-functionary-medium-v3.2.jinja
deleted file mode 100644
index 74fd1e7af..000000000
--- a/tests/chat/templates/meetkai-functionary-medium-v3.2.jinja
+++ /dev/null
@@ -1,287 +0,0 @@
-{# version=v3.llama3 #}{%- macro append_new_param_info(param_declaration, comment_info, examples_info, depth) -%}
- {%- set offset = "" -%}
- {%- if depth >= 1 -%}
- {%- set offset = " " * depth -%}
- {%- endif -%}
- {%- if comment_info != "<|NONE|>" -%}
- {{ "\n" + offset + comment_info }}
- {%- if examples_info | length > 0 -%}
- {# Append each example info #}
- {%- for example in examples_info -%}
- {{ "\n" + offset + "// " + example|string|replace("'", '"') }}
- {%- endfor -%}
- {%- endif -%}
- {%- endif -%}
- {{ "\n" + offset + param_declaration }}
-{%- endmacro -%}
-
-{%- macro convert_data_type(param_type) -%}
- {%- if param_type == "integer" or param_type == "float" -%}
- {{ "number" }}
- {%- else -%}
- {{ param_type }}
- {%- endif -%}
-{%- endmacro -%}
-
-{%- macro get_param_type(param) -%}
- {%- set param_type = "any" -%}
-
- {%- if "type" in param -%}
- {%- set raw_param_type = param["type"] -%}
- {%- if raw_param_type is iterable and raw_param_type is not string -%}
- {%- set param_type = raw_param_type | join(" | ") -%}
- {%- else -%}
- {%- set param_type = raw_param_type -%}
- {%- endif -%}
- {{ convert_data_type(param_type) }}
- {%- elif "oneOf" in param -%}
- {%- set one_of_types = param["oneOf"]|selectattr("type", "defined")|list -%}
- {%- set one_of_types = one_of_types|map(attribute="type")|unique|list -%}
- {{ convert_data_type(one_of_types | join(" | ")) }}
- {%- endif -%}
-{%- endmacro -%}
-
-{%- macro get_format_param(param) -%}
- {%- if "format" in param -%}
- {{ param["format"] }}
- {%- elif "oneOf" in param -%}
- {%- set formats = [] -%}
- {%- for item in param["oneOf"] -%}
- {%- if "format" in item -%}
- {%- if item["format"] == param["oneOf"][-1]["format"] -%}
- {{ item["format"] }}
- {%- else -%}
- {{ item["format"] + " or "}}
- {%- endif -%}
- {%- endif -%}
- {%- endfor -%}
- {%- else -%}
- {{ "<|NONE|>" }}
- {%- endif -%}
-{%- endmacro -%}
-
-{%- macro get_param_info(param) -%}
- {%- set param_type = param.get("type", "any") -%}
- {%- set format_param = get_format_param(param) -%}
-
- {%- if "description" in param or "default" in param or format_param != "<|NONE|>" or param["maximum"] or param["minimum"] or param["maxLength"] or param["minLength"] -%}
- {{ "//" }}
- {%- if "description" in param -%}
- {%- set desc = param["description"] -%}
- {%- if not desc.endswith(".") -%}
- {%- set desc = desc + "." -%}
- {%- endif -%}
- {{ " " + desc }}
- {%- endif -%}
-
- {%- if "default" in param -%}
- {%- set default_value = param["default"] -%}
- {%- if param_type == "string" -%}
- {%- set default_value = '"' ~ default_value ~ '"' -%}
- {%- endif -%}
- {{ " Default=" ~ default_value ~ "." }}
- {%- endif -%}
-
- {%- set format_param = get_format_param(param) -%}
- {%- if format_param != "<|NONE|>" -%}
- {{ " Format=" ~ format_param }}
- {%- endif -%}
-
- {%- for field, field_name in [("maximum", "Maximum"), ("minimum", "Minimum"), ("maxLength", "Maximum length"), ("minLength", "Minimum length")] -%}
- {%- if field in param -%}
- {{ " " + field_name ~ "=" ~ param[field] }}
- {%- endif -%}
- {%- endfor -%}
- {%- else -%}
- {{ "<|NONE|>"}}
- {%- endif -%}
-{%- endmacro -%}
-
-{%- macro get_enum_option_str(enum_options) -%}
- {%- for v in enum_options -%}
- {%- if v is string -%}
- {{ '"' + v + '"' }}
- {%- else -%}
- {{ v }}
- {%- endif -%}
- {%- if enum_options|length > 0 and v != enum_options[-1] -%}
- {{ " | " }}
- {%- endif -%}
- {%- endfor -%}
-{%- endmacro -%}
-
-{%- macro get_array_typescript(param_name, param_dic, depth) -%}
- {%- set offset = '' -%}
- {%- if depth >= 1 -%}
- {%- set offset = " " * depth -%}
- {%- endif -%}
- {%- set items_info = param_dic.get('items', {}) -%}
-
- {%- if items_info|length == 0 -%}
- {%- if param_name -%}
- {{ "\n" + offset + param_name + ": []" }}
- {%- else -%}
- {{ "\n" + offset + "[]" }}
- {%- endif -%}
- {%- else -%}
- {%- set array_type = get_param_type(items_info) -%}
- {%- if array_type == 'object' -%}
- {%- if param_name -%}
- {{ "\n" + offset + param_name + ": {" }}
- {%- else -%}
- {{ "\n" + offset + "{" }}
- {%- endif -%}
- {{ get_parameter_typescript(items_info.get('properties', {}), items_info.get('required', []), depth + 1) -}}
- {{- "\n" + offset + "}[]" }}
- {%- elif array_type == 'array' -%}
- {%- set item_info = get_array_typescript(None, items_info, depth + 1) -%}
- {%- if not param_name -%}
- {{ "\n" + item_info + "[]" }}
- {%- else -%}
- {{ "\n" + offset + param_name + ": " + item_info|trim + "[]" }}
- {%- endif -%}
- {%- else -%}
- {%- if 'enum' in items_info -%}
- {%- set item_type = get_enum_option_str(items_info['enum']) -%}
- {%- if param_name is none -%}
- {{ "(" + item_type + ")[]"}}
- {%- else -%}
- {{ "\n" + offset + param_name + ": (" + item_type + ")[]" }}
- {%- endif -%}
- {%- else -%}
- {%- if param_name is none -%}
- {{ "\n" + array_type + "[]" }}
- {%- else -%}
- {{ "\n" + offset + param_name + ": " + array_type + "[]," }}
- {%- endif -%}
- {%- endif -%}
- {%- endif -%}
- {%- endif -%}
-{%- endmacro -%}
-
-{%- macro get_parameter_typescript(properties, required_params, depth=0) -%}
- {%- set res = "" -%}
- {%- for param_name, param in properties.items() -%}
- {%- if param is mapping -%}
- {%- set comment_info = get_param_info(param) -%}
- {# Param Examples #}
- {%- set examples_info = [] -%}
- {%- if "examples" in param -%}
- {%- set examples_info = ["Example " + param_name + ":"] -%}
- {%- set examples_info = examples_info + param["examples"] -%}
- {%- endif -%}
-
- {# Param Name declaration #}
- {%- set param_declaration = param_name -%}
- {%- if required_params is iterable and param_name not in required_params -%}
- {%- set param_declaration = param_declaration + "?" -%}
- {%- endif -%}
-
- {%- set param_type = get_param_type(param) -%}
-
- {# Handle indentation based on depth #}
- {%- set offset = "" -%}
- {%- if depth >= 1 -%}
- {%- set offset = " " * depth -%}
- {%- endif -%}
-
- {%- if param_type == "object" -%}
- {%- if comment_info != "<|NONE|>" -%}
- {{ "\n" + offset + comment_info }}
- {%- endif -%}
- {%- if examples_info|length > 0 -%}
- {%- for example in examples_info -%}
- {{ "\n" + offset + "// " + example|string|replace("'", '"') }}
- {%- endfor -%}
- {%- endif -%}
- {%- set param_declaration = param_declaration + ": {" -%}
- {{ "\n" + offset + param_declaration -}}
- {{- get_parameter_typescript(param.get("properties", {}), param.get("required", []), depth + 1) -}}
- {{- "\n" + offset + "}," }}
- {%- elif param_type == "array" -%}
- {%- set item_info = param.get("items", {}) -%}
- {%- if "type" not in item_info -%}
- {%- set param_declaration = param_declaration + ": []," -%}
- {{ append_new_param_info(param_declaration, comment_info, examples_info, depth) }}
- {%- else -%}
- {%- if comment_info != "<|NONE|>" -%}
- {{ "\n" + offset + comment_info }}
- {%- endif -%}
- {%- if examples_info|length > 0 -%}
- {%- for example in examples_info -%}
- {{ "\n" + offset + "// " + example|string|replace("'", '"') }}
- {%- endfor -%}
- {%- endif -%}
- {%- set array_declaration = get_array_typescript(param_declaration, param, depth) -%}
- {%- if not array_declaration.endswith(",") -%}
- {%- set array_declaration = array_declaration + "," -%}
- {%- endif -%}
- {{ array_declaration}}
- {%- endif -%}
- {%- else -%}
- {%- if "enum" in param -%}
- {%- set param_type = get_enum_option_str(param["enum"]) -%}
- {%- endif -%}
- {%- if "nullable" in param and param["nullable"] -%}
- {%- set param_type = param_type + " | null" -%}
- {%- endif -%}
- {%- set param_declaration = param_declaration + ": " + param_type + "," -%}
- {{ append_new_param_info(param_declaration, comment_info, examples_info, depth) }}
- {%- endif -%}
- {%- endif -%}
- {%- endfor -%}
-{%- endmacro -%}
-
-{%- macro generate_schema_from_functions(functions, namespace='functions') -%}
- {{ "// Supported function definitions that should be called when necessary.\n" -}}
- {{- "namespace " + namespace + " {\n\n" -}}
-
- {%- for function in functions -%}
- {%- if function.get("function") -%}
- {%- set function = function.get("function") -%}
- {%- endif -%}
-
- {%- set function_name = function.get("name") -%}
- {%- if function_name -%}
- {%- set description = function.get('description', '') -%}
- {%- set parameters = function.get('parameters', {}) -%}
- {{- "// " + description + "\n" -}}
- {{- "type " + function_name -}}
- {%- if parameters and parameters.get("properties") -%}
- {{- " = (_: {" -}}
- {%- set required_params = parameters.get("required", []) -%}
- {{ get_parameter_typescript(parameters.get("properties"), required_params, 0) -}}
- {{- "\n}) => any;\n\n" }}
- {%- else -%}
- {{ " = () => any;\n\n" }}
- {%- endif -%}
- {%- endif -%}
- {%- endfor -%}
- {{ "} // namespace " + namespace }}
-{%- endmacro -%}
-{%- if not tools -%}
- {%- set tools = [] -%}
-{%- endif -%}
-{{ bos_token + '<|start_header_id|>system<|end_header_id|>\n\nYou are capable of executing available function(s) if required.\nOnly execute function(s) when absolutely necessary.\nAsk for the required input to:recipient==all\nUse JSON for function arguments.\nRespond in this format:\n>>>${recipient}\n${content}\nAvailable functions:\n' + generate_schema_from_functions(tools) + '<|eot_id|>' -}}
-{%- if tools|length > 0 and tools|selectattr("type", "equalto", "code_interpreter")|list|length > 0 -%}
- {{ '<|start_header_id|>system<|end_header_id|>\n\nWhen you send a message containing Python code to python, it will be executed in a stateful Jupyter notebook environment. python will respond with the output of the execution or time out after 60.0 seconds. The drive at \'/mnt/data\' can be used to save and persist user files.<|eot_id|>' }}
-{%- endif -%}
-{%- for message in messages -%}
- {%- if message['role'] == 'user' or message['role'] == 'system' -%}
- {{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' }}
- {%- elif message['role'] == 'tool' -%}
- {{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' }}
- {%- else -%}
- {{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'}}
- {%- if message['content'] -%}
- {{ '>>>all\n' + message['content'] }}
- {%- endif -%}
- {%- if 'tool_calls' in message and message['tool_calls'] -%}
- {%- for tool_call in message['tool_calls'] -%}
- {{ '>>>' + tool_call['function']['name'] + '\n' + tool_call['function']['arguments'] }}
- {%- endfor -%}
- {%- endif -%}
- {{ '<|eot_id|>' }}
- {%- endif -%}
-{%- endfor -%}
-{% if add_generation_prompt %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n>>>' }}{% endif %}
\ No newline at end of file
diff --git a/tests/test-chat-template.cpp b/tests/test-chat-template.cpp
index faa95ceaa..55d741251 100644
--- a/tests/test-chat-template.cpp
+++ b/tests/test-chat-template.cpp
@@ -7,15 +7,122 @@
#include "llama.h"
#include "common.h"
+#include "chat-template.h"
+#include
+#include
+#include
+#include
+#include
-int main(void) {
+using json = nlohmann::ordered_json;
+
+static std::string filename_without_extension(const std::string & path) {
+ auto res = path;
+ auto pos = res.find_last_of('/');
+ if (pos != std::string::npos)
+ res = res.substr(pos + 1);
+ pos = res.find_last_of('.');
+ if (pos != std::string::npos)
+ res = res.substr(0, pos);
+ return res;
+}
+
+static void assert_equals(const std::string & expected, const std::string & actual) {
+ if (expected != actual) {
+ std::cerr << "Expected: " << expected << std::endl;
+ std::cerr << "Actual: " << actual << std::endl;
+ std::cerr << std::flush;
+ throw std::runtime_error("Test failed");
+ }
+}
+
+static std::vector find_files(const std::string & folder, const std::string & ext) {
+ std::vector files;
+ for (const auto & entry : std::__fs::filesystem::directory_iterator(folder)) {
+ if (entry.path().extension() == ext)
+ files.push_back(entry.path().string());
+ }
+ return files;
+}
+
+static std::string read_file(const std::string &path) {
+ std::ifstream fs(path, std::ios_base::binary);
+ if (!fs.is_open()) {
+ throw std::runtime_error("Failed to open file: " + path);
+ }
+ fs.seekg(0, std::ios_base::end);
+ auto size = fs.tellg();
+ fs.seekg(0);
+ std::string out;
+ out.resize(static_cast(size));
+ fs.read(&out[0], static_cast(size));
+ return out;
+}
+
+static void test_jinja_templates() {
+ auto jinja_template_files = find_files("tests/chat/templates", ".jinja");
+ auto context_files = find_files("tests/chat/contexts", ".json");
+
+ auto get_golden_file = [&](const std::string & tmpl_file, const std::string & ctx_file) {
+ auto tmpl_name = filename_without_extension(tmpl_file);
+ auto ctx_name = filename_without_extension(ctx_file);
+ auto golden_name = tmpl_name + "-" + ctx_name;
+ return "tests/chat/goldens/" + golden_name + ".txt";
+ };
+ auto fail_with_golden_instructions = [&]() {
+ throw std::runtime_error("To fetch templates and generate golden files, run `python tests/update_jinja_goldens.py`");
+ };
+ if (jinja_template_files.empty()) {
+ std::cerr << "No Jinja templates found in tests/chat/templates" << std::endl;
+ fail_with_golden_instructions();
+ }
+ // const auto options = minja::Options {.trim_blocks = true, .lstrip_blocks = true};
+ for (const auto & tmpl_file : jinja_template_files) {
+ std::cout << "# Testing template: " << tmpl_file << std::endl << std::flush;
+ auto tmpl_str = read_file(tmpl_file);
+
+ auto found_goldens = false;
+
+ for (const auto & ctx_file : context_files) {
+ auto ctx = json::parse(read_file(ctx_file));
+
+ llama_chat_template tmpl(
+ tmpl_str,
+ ctx.at("bos_token"),
+ ctx.at("eos_token"));
+
+ auto golden_file = get_golden_file(tmpl_file, ctx_file);
+ if (!std::ifstream(golden_file).is_open()) {
+ continue;
+ }
+ found_goldens = true;
+ std::cout << " - " << golden_file << std::endl << std::flush;
+
+ std::string actual;
+ try {
+ actual = tmpl.apply(
+ ctx.at("messages"),
+ ctx.contains("tools") ? ctx.at("tools") : json(),
+ ctx.at("add_generation_prompt"));
+ } catch (const std::runtime_error & e) {
+ actual = "ERROR: " + std::string(e.what());
+ }
+ auto expected = read_file(golden_file);
+ assert_equals(expected, actual);
+ }
+
+ if (!found_goldens) {
+ std::cerr << "No golden files found for " << tmpl_file << std::endl;
+ fail_with_golden_instructions();
+ }
+ }
+}
+
+static void test_legacy_templates() {
struct test_template {
std::string name;
std::string tmpl;
- std::string bos;
- std::string eos;
std::string expected_output;
- std::string jinja_expected_output;
};
std::vector conversation {
@@ -27,134 +134,117 @@ int main(void) {
{"user", "Another question"},
};
- std::string tools = "";
-
std::vector templates {
{
- .name = "teknium/OpenHermes-2.5-Mistral-7B",
- .tmpl = "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\\n' + message['content'] + '<|im_end|>' + '\\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\\n' }}{% endif %}",
- .expected_output = "<|im_start|>system\nYou are a helpful assistant<|im_end|>\n<|im_start|>user\nHello<|im_end|>\n<|im_start|>assistant\nHi there<|im_end|>\n<|im_start|>user\nWho are you<|im_end|>\n<|im_start|>assistant\n I am an assistant <|im_end|>\n<|im_start|>user\nAnother question<|im_end|>\n<|im_start|>assistant\n",
- .bos = "<|im_start|>",
- .eos = "<|im_end|>",
+ "teknium/OpenHermes-2.5-Mistral-7B",
+ "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\\n' + message['content'] + '<|im_end|>' + '\\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\\n' }}{% endif %}",
+ "<|im_start|>system\nYou are a helpful assistant<|im_end|>\n<|im_start|>user\nHello<|im_end|>\n<|im_start|>assistant\nHi there<|im_end|>\n<|im_start|>user\nWho are you<|im_end|>\n<|im_start|>assistant\n I am an assistant <|im_end|>\n<|im_start|>user\nAnother question<|im_end|>\n<|im_start|>assistant\n",
},
{
- .name = "mistralai/Mistral-7B-Instruct-v0.2",
- .tmpl = "{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}",
- .expected_output = "[INST] You are a helpful assistant\nHello [/INST]Hi there[INST] Who are you [/INST] I am an assistant [INST] Another question [/INST]",
- .bos = "<|startoftext|>",
- .eos = "<|endoftext|>",
+ "mistralai/Mistral-7B-Instruct-v0.2",
+ "{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}",
+ "[INST] You are a helpful assistant\nHello [/INST]Hi there[INST] Who are you [/INST] I am an assistant [INST] Another question [/INST]",
},
{
- .name = "TheBloke/FusionNet_34Bx2_MoE-AWQ",
- .tmpl = "{%- for idx in range(0, messages|length) -%}\n{%- if messages[idx]['role'] == 'user' -%}\n{%- if idx > 1 -%}\n{{- bos_token + '[INST] ' + messages[idx]['content'] + ' [/INST]' -}}\n{%- else -%}\n{{- messages[idx]['content'] + ' [/INST]' -}}\n{%- endif -%}\n{% elif messages[idx]['role'] == 'system' %}\n{{- '[INST] <>\\n' + messages[idx]['content'] + '\\n<>\\n\\n' -}}\n{%- elif messages[idx]['role'] == 'assistant' -%}\n{{- ' ' + messages[idx]['content'] + ' ' + eos_token -}}\n{% endif %}\n{% endfor %}",
- .expected_output = "[INST] <>\nYou are a helpful assistant\n<>\n\nHello [/INST] Hi there [INST] Who are you [/INST] I am an assistant [INST] Another question [/INST]",
- .bos = "",
- .eos = "",
+ "TheBloke/FusionNet_34Bx2_MoE-AWQ",
+ "{%- for idx in range(0, messages|length) -%}\n{%- if messages[idx]['role'] == 'user' -%}\n{%- if idx > 1 -%}\n{{- bos_token + '[INST] ' + messages[idx]['content'] + ' [/INST]' -}}\n{%- else -%}\n{{- messages[idx]['content'] + ' [/INST]' -}}\n{%- endif -%}\n{% elif messages[idx]['role'] == 'system' %}\n{{- '[INST] <>\\n' + messages[idx]['content'] + '\\n<>\\n\\n' -}}\n{%- elif messages[idx]['role'] == 'assistant' -%}\n{{- ' ' + messages[idx]['content'] + ' ' + eos_token -}}\n{% endif %}\n{% endfor %}",
+ "[INST] <>\nYou are a helpful assistant\n<>\n\nHello [/INST] Hi there [INST] Who are you [/INST] I am an assistant [INST] Another question [/INST]",
},
{
- .name = "bofenghuang/vigogne-2-70b-chat",
- .tmpl = "{{ bos_token }}{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% elif true == true and not '<>' in messages[0]['content'] %}{% set loop_messages = messages %}{% set system_message = 'Vous êtes Vigogne, un assistant IA créé par Zaion Lab. Vous suivez extrêmement bien les instructions. Aidez autant que vous le pouvez.' %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 and system_message != false %}{% set content = '<>\\\\n' + system_message + '\\\\n<>\\\\n\\\\n' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + content.strip() + ' [/INST]' }}{% elif message['role'] == 'system' %}{{ '<>\\\\n' + content.strip() + '\\\\n<>\\\\n\\\\n' }}{% elif message['role'] == 'assistant' %}{{ ' ' + content.strip() + ' ' + eos_token }}{% endif %}{% endfor %}",
- .expected_output = "[INST] <>\nYou are a helpful assistant\n<>\n\nHello [/INST] Hi there [INST] Who are you [/INST] I am an assistant [INST] Another question [/INST]",
- .bos = "",
- .eos = "",
+ "bofenghuang/vigogne-2-70b-chat",
+ "{{ bos_token }}{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% elif true == true and not '<>' in messages[0]['content'] %}{% set loop_messages = messages %}{% set system_message = 'Vous êtes Vigogne, un assistant IA créé par Zaion Lab. Vous suivez extrêmement bien les instructions. Aidez autant que vous le pouvez.' %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 and system_message != false %}{% set content = '<>\\\\n' + system_message + '\\\\n<>\\\\n\\\\n' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + content.strip() + ' [/INST]' }}{% elif message['role'] == 'system' %}{{ '<>\\\\n' + content.strip() + '\\\\n<>\\\\n\\\\n' }}{% elif message['role'] == 'assistant' %}{{ ' ' + content.strip() + ' ' + eos_token }}{% endif %}{% endfor %}",
+ "[INST] <>\nYou are a helpful assistant\n<>\n\nHello [/INST] Hi there [INST] Who are you [/INST] I am an assistant [INST] Another question [/INST]",
},
{
- .name = "mlabonne/AlphaMonarch-7B",
- .tmpl = "{% for message in messages %}{{bos_token + message['role'] + '\\n' + message['content'] + eos_token + '\\n'}}{% endfor %}{% if add_generation_prompt %}{{ bos_token + 'assistant\\n' }}{% endif %}",
- .expected_output = "system\nYou are a helpful assistant\nuser\nHello\nassistant\nHi there\nuser\nWho are you\nassistant\n I am an assistant \nuser\nAnother question\nassistant\n",
- .jinja_expected_output = "system\nYou are a helpful assistant\nuser\nHello\nassistant\nHi there\nuser\nWho are you\nassistant\n I am an assistant \nuser\nAnother question\nassistant\n",
- .bos = "",
- .eos = "",
+ "mlabonne/AlphaMonarch-7B",
+ "{% for message in messages %}{{bos_token + message['role'] + '\\n' + message['content'] + eos_token + '\\n'}}{% endfor %}{% if add_generation_prompt %}{{ bos_token + 'assistant\\n' }}{% endif %}",
+ // TODO: should start w/
+ "system\nYou are a helpful assistant\nuser\nHello\nassistant\nHi there\nuser\nWho are you\nassistant\n I am an assistant \nuser\nAnother question\nassistant\n",
},
{
- .name = "google/gemma-7b-it",
- .tmpl = "{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '' + role + '\\n' + message['content'] | trim + '\\n' }}{% endfor %}{% if add_generation_prompt %}{{'model\\n'}}{% endif %}",
- .expected_output = "user\nYou are a helpful assistant\n\nHello\nmodel\nHi there\nuser\nWho are you\nmodel\nI am an assistant\nuser\nAnother question\nmodel\n",
- .bos = "",
- .eos = "",
+ "google/gemma-7b-it",
+ "{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '' + role + '\\n' + message['content'] | trim + '\\n' }}{% endfor %}{% if add_generation_prompt %}{{'model\\n'}}{% endif %}",
+ "user\nYou are a helpful assistant\n\nHello\nmodel\nHi there\nuser\nWho are you\nmodel\nI am an assistant\nuser\nAnother question\nmodel\n",
},
{
- .name = "OrionStarAI/Orion-14B-Chat",
- .tmpl = "{% for message in messages %}{% if loop.first %}{{ bos_token }}{% endif %}{% if message['role'] == 'user' %}{{ 'Human: ' + message['content'] + '\\n\\nAssistant: ' + eos_token }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token }}{% endif %}{% endfor %}",
- .expected_output = "Human: You are a helpful assistant\n\nHello\n\nAssistant: Hi thereHuman: Who are you\n\nAssistant: I am an assistant Human: Another question\n\nAssistant: ",
- .jinja_expected_output = "Human: Hello\n\nAssistant: Hi thereHuman: Who are you\n\nAssistant: I am an assistant Human: Another question\n\nAssistant: ",
- .bos = "",
- .eos = "",
+ "OrionStarAI/Orion-14B-Chat",
+ "{% for message in messages %}{% if loop.first %}{{ bos_token }}{% endif %}{% if message['role'] == 'user' %}{{ 'Human: ' + message['content'] + '\\n\\nAssistant: ' + eos_token }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token }}{% endif %}{% endfor %}",
+ // TODO: should start w/
+ "Human: You are a helpful assistant\n\nHello\n\nAssistant: Hi thereHuman: Who are you\n\nAssistant: I am an assistant Human: Another question\n\nAssistant: ",
},
{
// The included chat_template differs from the author's suggestions here: https://huggingface.co/openchat/openchat_3.5/discussions/5#65448109b4a3f3a2f486fd9d,
// So we match against the included template but implement the suggested version.
- .name = "openchat/openchat-3.5-0106",
- .tmpl = "{{ bos_token }}{% for message in messages %}{{ 'GPT4 Correct ' + message['role'].title() + ': ' + message['content'] + '<|end_of_turn|>'}}{% endfor %}{% if add_generation_prompt %}{{ 'GPT4 Correct Assistant:' }}{% endif %}",
- .expected_output = "You are a helpful assistant<|end_of_turn|>GPT4 Correct User: Hello<|end_of_turn|>GPT4 Correct Assistant: Hi there<|end_of_turn|>GPT4 Correct User: Who are you<|end_of_turn|>GPT4 Correct Assistant: I am an assistant <|end_of_turn|>GPT4 Correct User: Another question<|end_of_turn|>GPT4 Correct Assistant:",
- .eos = "<|end_of_turn|>",
+ "openchat/openchat-3.5-0106",
+ "{{ bos_token }}{% for message in messages %}{{ 'GPT4 Correct ' + message['role'].title() + ': ' + message['content'] + '<|end_of_turn|>'}}{% endfor %}{% if add_generation_prompt %}{{ 'GPT4 Correct Assistant:' }}{% endif %}",
+ "You are a helpful assistant<|end_of_turn|>GPT4 Correct User: Hello<|end_of_turn|>GPT4 Correct Assistant: Hi there<|end_of_turn|>GPT4 Correct User: Who are you<|end_of_turn|>GPT4 Correct Assistant: I am an assistant <|end_of_turn|>GPT4 Correct User: Another question<|end_of_turn|>GPT4 Correct Assistant:",
},
{
- .name = "deepseek-ai/deepseek-coder-33b-instruct",
- .tmpl = "{% if not add_generation_prompt is defined %}\n{% set add_generation_prompt = false %}\n{% endif %}\n{%- set ns = namespace(found=false) -%}\n{%- for message in messages -%}\n {%- if message['role'] == 'system' -%}\n {%- set ns.found = true -%}\n {%- endif -%}\n{%- endfor -%}\n{{bos_token}}{%- if not ns.found -%}\n{{'You are an AI programming assistant, utilizing the Deepseek Coder model, developed by Deepseek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer\\n'}}\n{%- endif %}\n{%- for message in messages %}\n {%- if message['role'] == 'system' %}\n{{ message['content'] }}\n {%- else %}\n {%- if message['role'] == 'user' %}\n{{'### Instruction:\\n' + message['content'] + '\\n'}}\n {%- else %}\n{{'### Response:\\n' + message['content'] + '\\n<|EOT|>\\n'}}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{% if add_generation_prompt %}\n{{'### Response:'}}\n{% endif %}",
- .expected_output = "You are a helpful assistant### Instruction:\nHello\n### Response:\nHi there\n<|EOT|>\n### Instruction:\nWho are you\n### Response:\n I am an assistant \n<|EOT|>\n### Instruction:\nAnother question\n### Response:\n",
+ "deepseek-ai/deepseek-coder-33b-instruct",
+ "{% if not add_generation_prompt is defined %}\n{% set add_generation_prompt = false %}\n{% endif %}\n{%- set ns = namespace(found=false) -%}\n{%- for message in messages -%}\n {%- if message['role'] == 'system' -%}\n {%- set ns.found = true -%}\n {%- endif -%}\n{%- endfor -%}\n{{bos_token}}{%- if not ns.found -%}\n{{'You are an AI programming assistant, utilizing the Deepseek Coder model, developed by Deepseek Company, and you only answer questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will refuse to answer\\n'}}\n{%- endif %}\n{%- for message in messages %}\n {%- if message['role'] == 'system' %}\n{{ message['content'] }}\n {%- else %}\n {%- if message['role'] == 'user' %}\n{{'### Instruction:\\n' + message['content'] + '\\n'}}\n {%- else %}\n{{'### Response:\\n' + message['content'] + '\\n<|EOT|>\\n'}}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{% if add_generation_prompt %}\n{{'### Response:'}}\n{% endif %}",
+ "You are a helpful assistant### Instruction:\nHello\n### Response:\nHi there\n<|EOT|>\n### Instruction:\nWho are you\n### Response:\n I am an assistant \n<|EOT|>\n### Instruction:\nAnother question\n### Response:\n",
},
{
// No template included in tokenizer_config.json, so this template likely needs to be manually set.,
- .name = "eachadea/vicuna-13b-1.1",
- .tmpl = "{%- for message in messages %}{%- if message['role'] == 'system' -%}{{- '' + message['content'] + '\n\n' -}}{%- else -%}{%- if message['role'] == 'user' -%}{{-'USER: ' + message['content'] + '\n'-}}{%- else -%}{{-'ASSISTANT: ' + message['content'] + '\n' -}}{%- endif -%}{%- endif -%}{%- endfor -%}{%- if add_generation_prompt -%}{{-'ASSISTANT:'-}}{%- endif -%}",
- .expected_output = "You are a helpful assistant\n\nUSER: Hello\nASSISTANT: Hi there\nUSER: Who are you\nASSISTANT: I am an assistant \nUSER: Another question\nASSISTANT:",
+ "eachadea/vicuna-13b-1.1",
+ "{%- for message in messages %}{%- if message['role'] == 'system' -%}{{- '' + message['content'] + '\n\n' -}}{%- else -%}{%- if message['role'] == 'user' -%}{{-'USER: ' + message['content'] + '\n'-}}{%- else -%}{{-'ASSISTANT: ' + message['content'] + '\n' -}}{%- endif -%}{%- endif -%}{%- endfor -%}{%- if add_generation_prompt -%}{{-'ASSISTANT:'-}}{%- endif -%}",
+ "You are a helpful assistant\n\nUSER: Hello\nASSISTANT: Hi there\nUSER: Who are you\nASSISTANT: I am an assistant \nUSER: Another question\nASSISTANT:",
},
{
// No template included in tokenizer_config.json, so this template likely needs to be manually set.
- .name = "Orca-Vicuna",
- .tmpl = "{%- for message in messages %}{%- if message['role'] == 'system' -%}{{-'SYSTEM: ' + message['content'] + '\n' -}}{%- else -%}{%- if message['role'] == 'user' -%}{{-'USER: ' + message['content'] + '\n'-}}{%- else -%}{{-'ASSISTANT: ' + message['content'] + '\n' -}}{%- endif -%}{%- endif -%}{%- endfor -%}{%- if add_generation_prompt -%}{{-'ASSISTANT:'-}}{%- endif -%}",
- .expected_output = "SYSTEM: You are a helpful assistant\nUSER: Hello\nASSISTANT: Hi there\nUSER: Who are you\nASSISTANT: I am an assistant \nUSER: Another question\nASSISTANT:",
+ "Orca-Vicuna",
+ "{%- for message in messages %}{%- if message['role'] == 'system' -%}{{-'SYSTEM: ' + message['content'] + '\n' -}}{%- else -%}{%- if message['role'] == 'user' -%}{{-'USER: ' + message['content'] + '\n'-}}{%- else -%}{{-'ASSISTANT: ' + message['content'] + '\n' -}}{%- endif -%}{%- endif -%}{%- endfor -%}{%- if add_generation_prompt -%}{{-'ASSISTANT:'-}}{%- endif -%}",
+ "SYSTEM: You are a helpful assistant\nUSER: Hello\nASSISTANT: Hi there\nUSER: Who are you\nASSISTANT: I am an assistant \nUSER: Another question\nASSISTANT:",
},
{
- .name = "CohereForAI/c4ai-command-r-plus",
- .tmpl = "{{ bos_token }}{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% elif false == true %}{% set loop_messages = messages %}{% set system_message = 'You are Command-R, a brilliant, sophisticated, AI-assistant trained to assist human users by providing thorough responses. You are trained by Cohere.' %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% if system_message != false %}{{ '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>' + system_message + '<|END_OF_TURN_TOKEN|>' }}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% set content = message['content'] %}{% if message['role'] == 'user' %}{{ '<|START_OF_TURN_TOKEN|><|USER_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' }}{% elif message['role'] == 'assistant' %}{{ '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' }}{% endif %}",
- .expected_output = "<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>You are a helpful assistant<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>Hi there<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Who are you<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>I am an assistant<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Another question<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",
+ "CohereForAI/c4ai-command-r-plus",
+ "{{ bos_token }}{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% elif false == true %}{% set loop_messages = messages %}{% set system_message = 'You are Command-R, a brilliant, sophisticated, AI-assistant trained to assist human users by providing thorough responses. You are trained by Cohere.' %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% if system_message != false %}{{ '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>' + system_message + '<|END_OF_TURN_TOKEN|>' }}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% set content = message['content'] %}{% if message['role'] == 'user' %}{{ '<|START_OF_TURN_TOKEN|><|USER_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' }}{% elif message['role'] == 'assistant' %}{{ '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' }}{% endif %}",
+ "<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>You are a helpful assistant<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>Hi there<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Who are you<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>I am an assistant<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Another question<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",
},
{
- .name = "Llama-3",
- .tmpl = "{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}",
- .expected_output = "<|start_header_id|>system<|end_header_id|>\n\nYou are a helpful assistant<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHello<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nHi there<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nWho are you<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nI am an assistant<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nAnother question<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
+ "Llama-3",
+ "{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}",
+ "<|start_header_id|>system<|end_header_id|>\n\nYou are a helpful assistant<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHello<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nHi there<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nWho are you<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nI am an assistant<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nAnother question<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
},
{
- .name = "Phi-3-mini",
- .tmpl = "{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|user|>' + '\n' + message['content'] + '<|end|>' + '\n' + '<|assistant|>' + '\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|end|>' + '\n'}}{% endif %}{% endfor %}",
- .expected_output = "<|system|>\nYou are a helpful assistant<|end|>\n<|user|>\nHello<|end|>\n<|assistant|>\nHi there<|end|>\n<|user|>\nWho are you<|end|>\n<|assistant|>\n I am an assistant <|end|>\n<|user|>\nAnother question<|end|>\n<|assistant|>\n",
+ "Phi-3-mini",
+ "{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|user|>' + '\n' + message['content'] + '<|end|>' + '\n' + '<|assistant|>' + '\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|end|>' + '\n'}}{% endif %}{% endfor %}",
+ "<|system|>\nYou are a helpful assistant<|end|>\n<|user|>\nHello<|end|>\n<|assistant|>\nHi there<|end|>\n<|user|>\nWho are you<|end|>\n<|assistant|>\n I am an assistant <|end|>\n<|user|>\nAnother question<|end|>\n<|assistant|>\n",
},
{
- .name = "Phi-3-small",
- .tmpl = "{{ bos_token }}{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}",
- .expected_output = "<|system|>\nYou are a helpful assistant<|end|>\n<|user|>\nHello<|end|>\n<|assistant|>\nHi there<|end|>\n<|user|>\nWho are you<|end|>\n<|assistant|>\n I am an assistant <|end|>\n<|user|>\nAnother question<|end|>\n<|assistant|>\n",
+ "Phi-3-small",
+ "{{ bos_token }}{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}",
+ "<|system|>\nYou are a helpful assistant<|end|>\n<|user|>\nHello<|end|>\n<|assistant|>\nHi there<|end|>\n<|user|>\nWho are you<|end|>\n<|assistant|>\n I am an assistant <|end|>\n<|user|>\nAnother question<|end|>\n<|assistant|>\n",
},
{
- .name = "Phi-3-medium",
- .tmpl = "{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|user|>' + '\n' + message['content'] + '<|end|>' + '\n' + '<|assistant|>' + '\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|end|>' + '\n'}}{% endif %}{% endfor %}",
- .expected_output = "<|system|>\nYou are a helpful assistant<|end|>\n<|user|>\nHello<|end|>\n<|assistant|>\nHi there<|end|>\n<|user|>\nWho are you<|end|>\n<|assistant|>\n I am an assistant <|end|>\n<|user|>\nAnother question<|end|>\n<|assistant|>\n",
+ "Phi-3-medium",
+ "{% for message in messages %}{% if (message['role'] == 'user') %}{{'<|user|>' + '\n' + message['content'] + '<|end|>' + '\n' + '<|assistant|>' + '\n'}}{% elif (message['role'] == 'assistant') %}{{message['content'] + '<|end|>' + '\n'}}{% endif %}{% endfor %}",
+ "<|system|>\nYou are a helpful assistant<|end|>\n<|user|>\nHello<|end|>\n<|assistant|>\nHi there<|end|>\n<|user|>\nWho are you<|end|>\n<|assistant|>\n I am an assistant <|end|>\n<|user|>\nAnother question<|end|>\n<|assistant|>\n",
},
{
- .name = "Phi-3-vision",
- .tmpl = "{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}{{- '<|assistant|>\n' -}}{% endif %}",
- .expected_output = "<|system|>\nYou are a helpful assistant<|end|>\n<|user|>\nHello<|end|>\n<|assistant|>\nHi there<|end|>\n<|user|>\nWho are you<|end|>\n<|assistant|>\n I am an assistant <|end|>\n<|user|>\nAnother question<|end|>\n<|assistant|>\n",
+ "Phi-3-vision",
+ "{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}{{- '<|assistant|>\n' -}}{% endif %}",
+ "<|system|>\nYou are a helpful assistant<|end|>\n<|user|>\nHello<|end|>\n<|assistant|>\nHi there<|end|>\n<|user|>\nWho are you<|end|>\n<|assistant|>\n I am an assistant <|end|>\n<|user|>\nAnother question<|end|>\n<|assistant|>\n",
},
{
- .name = "ChatGLM3",
- .tmpl = "{% for message in messages %}{% if loop.first %}[gMASK]sop<|{{ message['role'] }}|>\n {{ message['content'] }}{% else %}<|{{ message['role'] }}|>\n {{ message['content'] }}{% endif %}{% endfor %}{% if add_generation_prompt %}<|assistant|>{% endif %}",
- .expected_output = "[gMASK]sop<|system|>\n You are a helpful assistant<|user|>\n Hello<|assistant|>\n Hi there<|user|>\n Who are you<|assistant|>\n I am an assistant <|user|>\n Another question<|assistant|>",
+ "ChatGLM3",
+ "{% for message in messages %}{% if loop.first %}[gMASK]sop<|{{ message['role'] }}|>\n {{ message['content'] }}{% else %}<|{{ message['role'] }}|>\n {{ message['content'] }}{% endif %}{% endfor %}{% if add_generation_prompt %}<|assistant|>{% endif %}",
+ "[gMASK]sop<|system|>\n You are a helpful assistant<|user|>\n Hello<|assistant|>\n Hi there<|user|>\n Who are you<|assistant|>\n I am an assistant <|user|>\n Another question<|assistant|>",
},
{
- .name = "ChatGLM4",
- .tmpl = u8"[gMASK]{% for item in messages %}{% if item['tools'] is defined %}<|system|>\n你是一个名为 ChatGLM 的人工智能助手。你是基于智谱AI训练的语言模型 GLM-4 模型开发的,你的任务是针对用户的问题和要求提供适当的答复和支持。\n\n# 可用工具{% set tools = item['tools'] %}{% for tool in tools %}{% if tool['type'] == 'function' %}\n\n## {{ tool['function']['name'] }}\n\n{{ tool['function'] | tojson(indent=4) }}\n......{% endif %}{% endfor %}{% endif %}{% if item['content'] %}<|{{ item['role'] }}|>{{ item['metadata'] }}\n{{ item['content'] }}{% endif %}{% endfor %}{% if add_generation_prompt %}<|assistant|>{% endif %}",
- .expected_output = "[gMASK]<|system|>\nYou are a helpful assistant<|user|>\nHello<|assistant|>\nHi there<|user|>\nWho are you<|assistant|>\n I am an assistant <|user|>\nAnother question<|assistant|>",
+ "ChatGLM4",
+ u8"[gMASK]{% for item in messages %}{% if item['tools'] is defined %}<|system|>\n你是一个名为 ChatGLM 的人工智能助手。你是基于智谱AI训练的语言模型 GLM-4 模型开发的,你的任务是针对用户的问题和要求提供适当的答复和支持。\n\n# 可用工具{% set tools = item['tools'] %}{% for tool in tools %}{% if tool['type'] == 'function' %}\n\n## {{ tool['function']['name'] }}\n\n{{ tool['function'] | tojson(indent=4) }}\n......{% endif %}{% endfor %}{% endif %}{% if item['content'] %}<|{{ item['role'] }}|>{{ item['metadata'] }}\n{{ item['content'] }}{% endif %}{% endfor %}{% if add_generation_prompt %}<|assistant|>{% endif %}",
+ "[gMASK]<|system|>\nYou are a helpful assistant<|user|>\nHello<|assistant|>\nHi there<|user|>\nWho are you<|assistant|>\n I am an assistant <|user|>\nAnother question<|assistant|>",
},
{
- .name = "MiniCPM-3B-OpenHermes-2.5-v2-GGUF",
- .tmpl = u8"{% for message in messages %}{% if message['role'] == 'user' %}{{'<用户>' + message['content'].strip() + ''}}{% else %}{{message['content'].strip()}}{% endif %}{% endfor %}",
- .expected_output = u8"You are a helpful assistant<用户>HelloHi there<用户>Who are youI am an assistant<用户>Another question",
+ "MiniCPM-3B-OpenHermes-2.5-v2-GGUF",
+ u8"{% for message in messages %}{% if message['role'] == 'user' %}{{'<用户>' + message['content'].strip() + ''}}{% else %}{{message['content'].strip()}}{% endif %}{% endfor %}",
+ u8"You are a helpful assistant<用户>HelloHi there<用户>Who are youI am an assistant<用户>Another question",
},
{
- .name = "DeepSeek-V2",
- .tmpl = "{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{{ bos_token }}{% for message in messages %}{% if message['role'] == 'user' %}{{ 'User: ' + message['content'] + '\n\n' }}{% elif message['role'] == 'assistant' %}{{ 'Assistant: ' + message['content'] + eos_token }}{% elif message['role'] == 'system' %}{{ message['content'] + '\n\n' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %}",
- .expected_output = u8"You are a helpful assistant\n\nUser: Hello\n\nAssistant: Hi there<|end▁of▁sentence|>User: Who are you\n\nAssistant: I am an assistant <|end▁of▁sentence|>User: Another question\n\nAssistant:",
+ "DeepSeek-V2",
+ "{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{{ bos_token }}{% for message in messages %}{% if message['role'] == 'user' %}{{ 'User: ' + message['content'] + '\n\n' }}{% elif message['role'] == 'assistant' %}{{ 'Assistant: ' + message['content'] + eos_token }}{% elif message['role'] == 'system' %}{{ message['content'] + '\n\n' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %}",
+ u8"You are a helpful assistant\n\nUser: Hello\n\nAssistant: Hi there<|end▁of▁sentence|>User: Who are you\n\nAssistant: I am an assistant <|end▁of▁sentence|>User: Another question\n\nAssistant:",
}
};
@@ -162,31 +252,22 @@ int main(void) {
int32_t res;
// test invalid chat template
- res = llama_chat_apply_template(nullptr, "INVALID TEMPLATE", conversation.data(), conversation.size(), true, formatted_chat.data(), formatted_chat.size(), false, /* tools= */ nullptr, "<|im_start|>", "<|im_end|>");
+ res = llama_chat_apply_template(nullptr, "INVALID TEMPLATE", conversation.data(), conversation.size(), true, formatted_chat.data(), formatted_chat.size());
assert(res < 0);
for (auto use_jinja : std::vector { false, true }) {
printf("\n\n=== Using Jinja: %s ===\n\n", use_jinja ? "true" : "false");
for (const auto & tmpl : templates) {
printf("=== %s ===\n", tmpl.name.c_str());
- const auto & custom_template = tmpl.tmpl;
- const auto & expected =
- use_jinja && !tmpl.jinja_expected_output.empty()
- ? tmpl.jinja_expected_output
- : tmpl.expected_output;
formatted_chat.resize(1024);
res = llama_chat_apply_template(
nullptr,
- custom_template.c_str(),
+ tmpl.tmpl.c_str(),
conversation.data(),
conversation.size(),
true,
formatted_chat.data(),
- formatted_chat.size(),
- use_jinja,
- tools.empty() ? nullptr : tools.c_str(),
- tmpl.bos.c_str(),
- tmpl.eos.c_str()
+ formatted_chat.size()
);
if (res < 0) {
printf("Error: %d\n", res);
@@ -194,11 +275,11 @@ int main(void) {
}
formatted_chat.resize(res);
std::string output(formatted_chat.data(), formatted_chat.size());
- if (output != expected) {
+ if (output != tmpl.expected_output) {
printf("# Failure!\n");
- printf("Template: %s\n", custom_template.c_str());
+ printf("Template: %s\n", tmpl.tmpl.c_str());
printf("Expected:\n");
- printf("%s\n", expected.c_str());
+ printf("%s\n", tmpl.expected_output.c_str());
printf("-------------------------\n");
printf("Actual:\n");
printf("%s\n", output.c_str());
@@ -213,7 +294,7 @@ int main(void) {
llama_chat_msg sys_msg{"system", "You are a helpful assistant"};
auto fmt_sys = [&](std::string tmpl) {
- auto output = llama_chat_format_single(nullptr, tmpl, chat2, sys_msg, false, false, /** tools= */ "", "<|im_start|>", "<|im_end|>");
+ auto output = llama_chat_format_single(nullptr, tmpl, chat2, sys_msg, false);
printf("fmt_sys(%s) : %s\n", tmpl.c_str(), output.c_str());
printf("-------------------------\n");
return output;
@@ -232,7 +313,7 @@ int main(void) {
llama_chat_msg new_msg{"user", "How are you"};
auto fmt_single = [&](std::string tmpl) {
- auto output = llama_chat_format_single(nullptr, tmpl, chat2, new_msg, true, false, /* tools= */ nullptr, "<|im_start|>", "<|im_end|>");
+ auto output = llama_chat_format_single(nullptr, tmpl, chat2, new_msg, true);
printf("fmt_single(%s) : %s\n", tmpl.c_str(), output.c_str());
printf("-------------------------\n");
return output;
@@ -241,6 +322,16 @@ int main(void) {
assert(fmt_single("llama2") == "[INST] How are you [/INST]");
assert(fmt_single("gemma") == "\nuser\nHow are you\nmodel\n");
assert(fmt_single("llama3") == "<|start_header_id|>user<|end_header_id|>\n\nHow are you<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n");
+}
+
+int main(void) {
+ test_legacy_templates();
+
+ if (getenv("LLAMA_SKIP_TESTS_SLOW_ON_EMULATOR")) {
+ fprintf(stderr, "\033[33mWARNING: Skipping slow tests on emulator.\n\033[0m");
+ } else {
+ test_jinja_templates();
+ }
return 0;
-}
+}
\ No newline at end of file
diff --git a/tests/test-minja.cpp b/tests/test-minja.cpp
index 6018845f2..d4c66714d 100644
--- a/tests/test-minja.cpp
+++ b/tests/test-minja.cpp
@@ -43,40 +43,6 @@
#include
#include
-static std::string read_file(const std::string &path) {
- std::ifstream fs(path, std::ios_base::binary);
- if (!fs.is_open()) {
- throw std::runtime_error("Failed to open file: " + path);
- }
- fs.seekg(0, std::ios_base::end);
- auto size = fs.tellg();
- fs.seekg(0);
- std::string out;
- out.resize(static_cast(size));
- fs.read(&out[0], static_cast(size));
- return out;
-}
-
-static std::vector find_files(const std::string & folder, const std::string & ext) {
- std::vector files;
- for (const auto & entry : std::__fs::filesystem::directory_iterator(folder)) {
- if (entry.path().extension() == ext)
- files.push_back(entry.path().string());
- }
- return files;
-}
-
-static std::string filename_without_extension(const std::string & path) {
- auto res = path;
- auto pos = res.find_last_of('/');
- if (pos != std::string::npos)
- res = res.substr(pos + 1);
- pos = res.find_last_of('.');
- if (pos != std::string::npos)
- res = res.substr(0, pos);
- return res;
-}
-
static void assert_equals(const std::string & expected, const std::string & actual) {
if (expected != actual) {
std::cerr << "Expected: " << expected << std::endl;
@@ -148,7 +114,11 @@ static void test_error_contains(const std::string & template_str, const json & b
std::cout << " passed!" << std::endl << std::flush;
}
-static void test_template_features() {
+
+/*
+ cmake -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build -t test-minja -j && ./build/bin/test-minja
+*/
+int main() {
test_render(R"({{ 'foo bar'.title() }})", {}, {}, "Foo Bar");
test_render(R"({{ 1 | safe }})", {}, {}, "1");
test_render(R"({{ 'abc'.endswith('bc') }},{{ ''.endswith('a') }})", {}, {}, "True,False");
@@ -368,71 +338,6 @@ static void test_template_features() {
{%- set greeting = "Hello " ~ user -%}
{{- greeting -}}
)", {}, {}, "Hello Olivier");
-}
-
-static void test_chat_templates_with_common_contexts_against_goldens() {
- auto jinja_template_files = find_files("tests/chat/templates", ".jinja");
- auto context_files = find_files("tests/chat/contexts", ".json");
-
- auto get_golden_file = [&](const std::string & tmpl_file, const std::string & ctx_file) {
- auto tmpl_name = filename_without_extension(tmpl_file);
- auto ctx_name = filename_without_extension(ctx_file);
- auto golden_name = tmpl_name + "-" + ctx_name;
- return "tests/chat/goldens/" + golden_name + ".txt";
- };
- auto fail_with_golden_instructions = [&]() {
- throw std::runtime_error("To fetch templates and generate golden files, run `python tests/update_jinja_goldens.py`");
- };
- if (jinja_template_files.empty()) {
- std::cerr << "No Jinja templates found in tests/chat/templates" << std::endl;
- fail_with_golden_instructions();
- }
- const auto options = minja::Options {.trim_blocks = true, .lstrip_blocks = true};
- for (const auto & tmpl_file : jinja_template_files) {
- std::cout << "# Testing template: " << tmpl_file << std::endl << std::flush;
- auto tmpl_str = read_file(tmpl_file);
- auto tmpl = minja::Parser::parse(tmpl_str, options);
-
- auto found_goldens = false;
-
- for (const auto & ctx_file : context_files) {
- auto ctx = json::parse(read_file(ctx_file));
-
- auto golden_file = get_golden_file(tmpl_file, ctx_file);
- if (!std::ifstream(golden_file).is_open()) {
- continue;
- }
- found_goldens = true;
- std::cout << " - " << golden_file << std::endl << std::flush;
-
- std::string actual;
- try {
- actual = tmpl->render(minja::Context::make(ctx));
- } catch (const std::runtime_error & e) {
- actual = "ERROR: " + std::string(e.what());
- }
- auto expected = read_file(golden_file);
- assert_equals(expected, actual);
- }
-
- if (!found_goldens) {
- std::cerr << "No golden files found for " << tmpl_file << std::endl;
- fail_with_golden_instructions();
- }
- }
-}
-
-/*
- cmake -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build -t test-minja -j && ./build/bin/test-minja
-*/
-int main() {
- test_template_features();
-
- if (getenv("LLAMA_SKIP_TESTS_SLOW_ON_EMULATOR")) {
- fprintf(stderr, "\033[33mWARNING: Skipping slow tests on emulator.\n\033[0m");
- } else {
- test_chat_templates_with_common_contexts_against_goldens();
- }
return 0;
}
diff --git a/tests/update_jinja_goldens.py b/tests/update_jinja_goldens.py
index 73d580e6d..ea7e01f0e 100644
--- a/tests/update_jinja_goldens.py
+++ b/tests/update_jinja_goldens.py
@@ -30,36 +30,40 @@ logging.basicConfig(level=logging.INFO, format='%(message)s')
logger = logging.getLogger(__name__)
model_ids = [
- "NousResearch/Hermes-3-Llama-3.1-70B",
+ "abacusai/Fewshot-Metamath-OrcaVicuna-Mistral",
+ "bofenghuang/vigogne-2-70b-chat",
+ "deepseek-ai/deepseek-coder-33b-instruct",
+ "indischepartij/MiniCPM-3B-OpenHermes-2.5-v2",
+ "microsoft/Phi-3-medium-4k-instruct",
+ "microsoft/Phi-3-mini-4k-instruct",
+ "microsoft/Phi-3-small-8k-instruct",
+ "microsoft/Phi-3.5-mini-instruct",
+ "mlabonne/AlphaMonarch-7B",
"NousResearch/Hermes-2-Pro-Llama-3-8B",
"NousResearch/Hermes-2-Pro-Mistral-7B",
- "meetkai/functionary-medium-v3.2",
- "meetkai/functionary-medium-v3.1",
+ "NousResearch/Hermes-3-Llama-3.1-70B",
+ "openchat/openchat-3.5-0106",
+ "OrionStarAI/Orion-14B-Chat",
"Qwen/Qwen2-7B-Instruct",
"Qwen/Qwen2-VL-7B-Instruct",
"Qwen/Qwen2.5-7B-Instruct",
"Qwen/Qwen2.5-Math-7B-Instruct",
- "microsoft/Phi-3-mini-4k-instruct",
- "microsoft/Phi-3-small-8k-instruct",
- "microsoft/Phi-3-medium-4k-instruct",
- "microsoft/Phi-3.5-mini-instruct",
- "indischepartij/MiniCPM-3B-OpenHermes-2.5-v2",
"teknium/OpenHermes-2.5-Mistral-7B",
"TheBloke/FusionNet_34Bx2_MoE-AWQ",
- "bofenghuang/vigogne-2-70b-chat",
- "mlabonne/AlphaMonarch-7B",
- "OrionStarAI/Orion-14B-Chat",
- "openchat/openchat-3.5-0106",
- "deepseek-ai/deepseek-coder-33b-instruct",
- "abacusai/Fewshot-Metamath-OrcaVicuna-Mistral",
- "CohereForAI/c4ai-command-r-plus",
- "THUDM/chatglm3-6b",
- "derek33125/project-angel-chatglm4",
- "deepseek-ai/DeepSeek-Coder-V2-Instruct",
- "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct",
- "deepseek-ai/DeepSeek-V2.5",
- # Needs debugging:
+ # Python update goldens broken:
+ # "meetkai/functionary-medium-v3.2",
+ # "meetkai/functionary-medium-v3.1",
+
+ # C++ minja templating broken:
+ # "CohereForAI/c4ai-command-r-plus",
+ # "THUDM/chatglm3-6b",
+ # "derek33125/project-angel-chatglm4",
+ # "deepseek-ai/DeepSeek-Coder-V2-Instruct",
+ # "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct",
+ # "deepseek-ai/DeepSeek-V2.5",
+
+ # Cannot find chat template:
# "eachadea/vicuna-13b-1.1",
# "microsoft/Phi-3-vision-instruct",
@@ -127,18 +131,19 @@ def handle_chat_template(model_id, variant, template_src):
logger.info(f"- {output_file}")
# The template (and workarounds) may modify the context in place, so we need to make a copy of it.
- actual_context = json.loads(json.dumps(context))
+ render_context = json.loads(json.dumps(context))
# Work around Llama-3.1 template quirk: it expects tool_call.function.arguments to be an object rather than its JSON string representation.
if 'tool_call.arguments | items' in template_src:
- for message in actual_context['messages']:
+ for message in render_context['messages']:
if 'tool_calls' in message:
for tool_call in message['tool_calls']:
- arguments = tool_call['function']['arguments']
- tool_call['function']['arguments'] = json.loads(arguments)
+ if tool_call.get('type') == 'function':
+ arguments = tool_call['function']['arguments']
+ tool_call['function']['arguments'] = json.loads(arguments)
try:
- output = template.render(**actual_context)
+ output = template.render(**render_context)
except Exception as e1:
# Some templates (e.g. Phi-3-medium-128k's) expect a non-null "content" key in each message.
for message in context["messages"]:
@@ -146,7 +151,7 @@ def handle_chat_template(model_id, variant, template_src):
message["content"] = ""
try:
- output = template.render(**context)
+ output = template.render(**render_context)
except Exception as e2:
logger.info(f" ERROR: {e2} (after first error: {e1})")
output = f"ERROR: {e2}"