diff --git a/Runtime/LLMChatTemplates.cs b/Runtime/LLMChatTemplates.cs index 0820078d..e5e436b0 100644 --- a/Runtime/LLMChatTemplates.cs +++ b/Runtime/LLMChatTemplates.cs @@ -43,6 +43,7 @@ static ChatTemplate() new LLama3ChatTemplate(), new LLama2ChatTemplate(), new LLama2Template(), + new Phi3_5Template(), new Phi3Template(), new Phi2Template(), new VicunaTemplate(), @@ -448,7 +449,7 @@ public override string[] GetStop(string playerName, string AIName) /// @ingroup template /// - /// Class implementing the Zephyr template + /// Class implementing the Phi-3 template /// public class Phi3Template : ChatTemplate { @@ -488,6 +489,30 @@ public override string[] GetStop(string playerName, string AIName) } } + /// @ingroup template + /// + /// Class implementing the Phi-3.5 template + /// + public class Phi3_5Template : ChatTemplate + { + public override string GetName() { return "phi-3.5"; } + public override string GetDescription() { return "phi-3.5"; } + public override string[] GetNameMatches() { return new string[] {"phi-3.5"}; } + public override string[] GetChatTemplateMatches() { return new string[] {"{% for message in messages %}{% if message['role'] == 'system' and message['content'] %}{{'<|system|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'user' %}{{'<|user|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'assistant' %}{{'<|assistant|>\n' + message['content'] + '<|end|>\n'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}"};} + + protected override string PlayerPrefix(string playerName) { return $"<|user|>\n"; } + protected override string AIPrefix(string AIName) { return $"<|assistant|>\n"; } + protected override string RequestSuffix() { return "<|end|>\n"; } + protected override string PairSuffix() { return "<|end|>\n"; } + protected override string SystemPrefix() { return "<|system|>\n"; } + protected override string SystemSuffix() { return "<|end|>\n"; } + + public override string[] GetStop(string playerName, string AIName) + { + return AddStopNewlines(new string[] { "<|end|>", "<|user|>", "<|assistant|>" }); + } + } + /// @ingroup template /// /// Class implementing the Zephyr template diff --git a/Runtime/LLMUnitySetup.cs b/Runtime/LLMUnitySetup.cs index d92966fa..643be536 100644 --- a/Runtime/LLMUnitySetup.cs +++ b/Runtime/LLMUnitySetup.cs @@ -114,7 +114,7 @@ public class LLMUnitySetup ("OpenHermes 2.5 7B", "https://huggingface.co/TheBloke/OpenHermes-2.5-Mistral-7B-GGUF/resolve/main/openhermes-2.5-mistral-7b.Q4_K_M.gguf?download=true", null), }}, {"Small models", new(string, string, string)[] - { + { ("Llama 3.2 3B", "https://huggingface.co/hugging-quants/Llama-3.2-3B-Instruct-Q4_K_M-GGUF/resolve/main/llama-3.2-3b-instruct-q4_k_m.gguf", null), ("Phi 3.5 4B", "https://huggingface.co/bartowski/Phi-3.5-mini-instruct-GGUF/resolve/main/Phi-3.5-mini-instruct-Q4_K_M.gguf", null), }}, diff --git a/Tests/Runtime/TestLLMChatTemplates.cs b/Tests/Runtime/TestLLMChatTemplates.cs index bfedf6c8..de40f549 100644 --- a/Tests/Runtime/TestLLMChatTemplates.cs +++ b/Tests/Runtime/TestLLMChatTemplates.cs @@ -116,6 +116,15 @@ public void TestPhi3() ); } + [Test] + public void TestPhi3_5() + { + Assert.AreEqual( + new Phi3_5Template().ComputePrompt(messages, "user", "assistant"), + "<|system|>\nyou are a bot<|end|>\n<|user|>\nHello, how are you?<|end|>\n<|assistant|>\nI'm doing great. How can I help you today?<|end|>\n<|user|>\nI'd like to show off how chat templating works!<|end|>\n<|assistant|>\nchat template is awesome<|end|>\n<|user|>\ndo you think so?<|end|>\n<|assistant|>\n" + ); + } + [Test] public void TestZephyr() {