Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.2.7 #146

Merged
merged 11 commits into from
Apr 19, 2024
2 changes: 1 addition & 1 deletion .github/doxygen/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = "LLM for Unity"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = v1.2.6
PROJECT_NUMBER = v1.2.7

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v1.2.7
#### 🚀 Features

- Add Llama 3 and Vicuna chat templates (PR: #145)

#### 📦 General

- Use the context size of the model by default for longer history (PR: #147)


## v1.2.6
#### 🚀 Features

Expand Down Expand Up @@ -144,4 +154,4 @@
- closes #9
- Fix sample scenes for different screen resolutions
- closes #10
- Allow parallel prompts
- Allow parallel prompts
9 changes: 2 additions & 7 deletions CHANGELOG.release.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
### 🚀 Features

- Add documentation (PR: #135)

### 🐛 Fixes

- Add server security for interceptions from external llamafile servers (PR: #132)
- Adapt server security for macOS (PR: #137)
- Add Llama 3 and Vicuna chat templates (PR: #145)

### 📦 General

- Add sample to demonstrates the async functionality (PR: #136)
- Use the context size of the model by default for longer history (PR: #147)

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ LLM for Unity is built on top of the awesome [llama.cpp](https://github.com/gger
## Games using LLM for Unity
- [Verbal Verdict](https://store.steampowered.com/app/2778780/Verbal_Verdict/)
- [I, Chatbot: AISYLUM](https://store.steampowered.com/app/2786750/I_Chatbot_AISYLUM)
- [Nameless Souls of the Void](https://unicorninteractive.itch.io/nameless-souls-of-the-void)

## Setup
_Method 1: Install using the asset store_
Expand Down
2 changes: 1 addition & 1 deletion Runtime/LLM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class LLM : LLMClient
[ModelAddonAdvanced] public string lora = "";
/// <summary> Size of the prompt context (0 = context size of the model).
/// This is the number of tokens the model can take as input when generating responses. </summary>
[ModelAdvanced] public int contextSize = 512;
[ModelAdvanced] public int contextSize = 0;
/// <summary> Batch size for prompt processing. </summary>
[ModelAdvanced] public int batchSize = 512;
/// <summary> Boolean set to true if the server has started and is ready to receive requests, false otherwise. </summary>
Expand Down
57 changes: 54 additions & 3 deletions Runtime/LLMChatTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ static ChatTemplate()
new MistralInstructTemplate(),
new LLama2ChatTemplate(),
new LLama2Template(),
new LLama3ChatTemplate(),
new Phi2Template(),
new VicunaTemplate(),
new ZephyrTemplate(),
};

Expand Down Expand Up @@ -228,7 +230,7 @@ public override string[] GetStop(string playerName, string AIName)
public class LLama2Template : ChatTemplate
{
public override string GetName() { return "llama"; }
public override string GetDescription() { return "llama"; }
public override string GetDescription() { return "llama 2"; }

protected override string SystemPrefix() { return "<<SYS>>\n"; }
protected override string SystemSuffix() { return "\n<</SYS>> "; }
Expand All @@ -249,8 +251,8 @@ public override string[] GetStop(string playerName, string AIName)
public class LLama2ChatTemplate : LLama2Template
{
public override string GetName() { return "llama chat"; }
public override string GetDescription() { return "llama (modified for chat)"; }
public override string[] GetNameMatches() { return new string[] {"llama"}; }
public override string GetDescription() { return "llama 2 (modified for chat)"; }
public override string[] GetNameMatches() { return new string[] {"llama-2", "llama v2"}; }

protected override string PlayerPrefix(string playerName) { return "### " + playerName + ":"; }
protected override string AIPrefix(string AIName) { return "### " + AIName + ":"; }
Expand All @@ -262,6 +264,33 @@ public override string[] GetStop(string playerName, string AIName)
}
}

/// @ingroup template
/// <summary>
/// Class implementing the LLama3 template for chat
/// </summary>
public class LLama3ChatTemplate : ChatTemplate
{
public override string GetName() { return "llama3 chat"; }
public override string GetDescription() { return "llama 3 (chat)"; }
public override string[] GetNameMatches() { return new string[] {"llama-3", "llama v3"}; }
public override string[] GetChatTemplateMatches() { return new string[] {"{% 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' }}"};}

protected override string PromptPrefix() { return "<|begin_of_text|>"; }
protected override string SystemPrefix() { return "<|start_header_id|>system<|end_header_id|>\n\n"; }
protected override string SystemSuffix() { return "<|eot_id|>"; }

protected override string RequestSuffix() { return "<|eot_id|>"; }
protected override string PairSuffix() { return "<|eot_id|>"; }

protected override string PlayerPrefix(string playerName) { return $"<|start_header_id|>{playerName}<|end_header_id|>\n\n"; }
protected override string AIPrefix(string AIName) { return $"<|start_header_id|>{AIName}<|end_header_id|>\n\n"; }

public override string[] GetStop(string playerName, string AIName)
{
return AddStopNewlines(new string[] { "<|eot_id|>" });
}
}

/// @ingroup template
/// <summary>
/// Class implementing the Mistral Instruct template
Expand Down Expand Up @@ -328,6 +357,28 @@ public override string[] GetStop(string playerName, string AIName)
}
}

/// @ingroup template
/// <summary>
/// Class implementing the Vicuna template
/// </summary>
public class VicunaTemplate : ChatTemplate
{
public override string GetName() { return "vicuna"; }
public override string GetDescription() { return "vicuna"; }
public override string[] GetNameMatches() { return new string[] {"vicuna"}; }
public override string[] GetChatTemplateMatches() { return new string[] {"{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{% if message['role'] == 'system' %}{{message['content'] + ' '}}{% elif message['role'] == 'user' %}{{ 'USER: ' + message['content'] + ' '}}{% elif message['role'] == 'assistant' %}{{ 'ASSISTANT: ' + message['content'] + ' '}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ 'ASSISTANT: '}}{% endif %}"}; }

protected override string SystemSuffix() { return "\n"; }
protected override string PlayerPrefix(string playerName) { return "\n" + playerName + ":"; }
protected override string AIPrefix(string AIName) { return "\n" + AIName + ":"; }
protected override string PrefixMessageSeparator() { return " "; }

public override string[] GetStop(string playerName, string AIName)
{
return AddStopNewlines(new string[] { playerName + ":", AIName + ":" });
}
}

/// @ingroup template
/// <summary>
/// Class implementing the Phi-2 template
Expand Down
2 changes: 1 addition & 1 deletion Runtime/LLMUnitySetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class LLMUnitySetup : MonoBehaviour
{
// DON'T CHANGE! the version is autocompleted with a GitHub action
/// <summary> LLM for Unity version </summary>
public static string Version = "v1.2.6";
public static string Version = "v1.2.7";

/// \cond HIDE
public static Process CreateProcess(
Expand Down
18 changes: 18 additions & 0 deletions Tests/Runtime/TestLLMChatTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ public void TestLLama2Chat()
);
}

[Test]
public void TestLLama3Chat()
{
Assert.AreEqual(
new LLama3ChatTemplate().ComputePrompt(messages, "assistant"),
"<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nyou are a bot<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHello, how are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nI'm doing great. How can I help you today?<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nI'd like to show off how chat templating works!<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nchat template is awesome<|eot_id|><|start_header_id|>user<|end_header_id|>\n\ndo you think so?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
);
}

[Test]
public void TestAlpaca()
{
Expand All @@ -71,6 +80,15 @@ public void TestAlpaca()
);
}

[Test]
public void TestVicuna()
{
Assert.AreEqual(
new VicunaTemplate().ComputePrompt(messages, "assistant"),
"you are a bot\n\nuser: Hello, how are you?\nassistant: I'm doing great. How can I help you today?\nuser: I'd like to show off how chat templating works!\nassistant: chat template is awesome\nuser: do you think so?\nassistant:"
);
}

[Test]
public void TestPhi2()
{
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.2.6
v1.2.7
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ai.undream.llm",
"version": "1.2.6",
"version": "1.2.7",
"displayName": "LLM for Unity",
"description": "LLM for Unity allows to run and distribute Large Language Models (LLMs) in the Unity engine.",
"unity": "2022.3",
Expand Down
Loading