Skip to content

Commit

Permalink
added chat template for llama-3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
matt200-ok committed Dec 20, 2024
1 parent cdba56c commit ae8b093
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class PicoLLM {
DIALOGS.put("llama-2-70b-chat", Llama2ChatDialog.class);
DIALOGS.put("llama-3-8b-instruct", Llama3ChatDialog.class);
DIALOGS.put("llama-3-70b-instruct", Llama3ChatDialog.class);
DIALOGS.put("llama-3.2-1b-instruct", Llama32ChatDialog.class);
DIALOGS.put("llama-3.2-3b-instruct", Llama32ChatDialog.class);
DIALOGS.put("mistral-7b-instruct-v0.1", MistralChatDialog.class);
DIALOGS.put("mistral-7b-instruct-v0.2", MistralChatDialog.class);
DIALOGS.put("mixtral-8x7b-instruct-v0.1", MixtralChatDialog.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2024 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
limitations under the License.
*/

package ai.picovoice.picollm;

/**
* Represents a dialog helper specific for the `phi3.5` model.
*/
public class Llama32ChatDialog extends Llama3ChatDialog {

/**
* Builder class for constructing Llama32ChatDialog instances.
*/
public static class Builder extends PicoLLMDialog.Builder {
/**
* Builds a new instance of Llama32ChatDialog based on the configured settings.
*
* @return A new instance of Llama32ChatDialog.
*/
public Llama32ChatDialog build() {
return new Llama32ChatDialog(this.history, this.system);
}
}

/**
* Constructs a Llama32ChatDialog instance with the specified history and system settings.
*
* @param history The history length for the dialog.
* @param system The system instruction for configuring the model's responses.
*/
Llama32ChatDialog(Integer history, String system) {
super(history, system);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import ai.picovoice.picollm.GemmaChatDialog;
import ai.picovoice.picollm.Llama2ChatDialog;
import ai.picovoice.picollm.Llama3ChatDialog;
import ai.picovoice.picollm.Llama32ChatDialog;
import ai.picovoice.picollm.MistralChatDialog;
import ai.picovoice.picollm.Phi2ChatDialog;
import ai.picovoice.picollm.Phi2QADialog;
Expand Down Expand Up @@ -672,6 +673,8 @@ public PicoLLMDialog.Builder getDialogBuilder(String dialogName) {
return new Llama2ChatDialog.Builder();
case "llama-3-chat-dialog":
return new Llama3ChatDialog.Builder();
case "llama-3.2-chat-dialog":
return new Llama32ChatDialog.Builder();
case "mistral-chat-dialog":
return new MistralChatDialog.Builder();
case "phi2-chat-dialog":
Expand All @@ -682,6 +685,8 @@ public PicoLLMDialog.Builder getDialogBuilder(String dialogName) {
return new Phi3ChatDialog.Builder();
case "phi3.5-chat-dialog":
return new Phi35ChatDialog.Builder();
case "llama-3.2-chat-dialog":
return new Llama32ChatDialog.Builder();
default:
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions binding/ios/PicoLLM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ public class PicoLLM {
"llama-2-70b-chat": Llama2ChatDialog.self,
"llama-3-8b-chat": Llama3ChatDialog.self,
"llama-3-70b-chat": Llama3ChatDialog.self,
"llama-3.2-1b-chat": Llama32ChatDialog.self,
"llama-3.2-3b-chat": Llama32ChatDialog.self,
"mistral-7b-instruct-v0.1": MistralChatDialog.self,
"mistral-7b-instruct-v0.2": MistralChatDialog.self,
"mixtral-8x7b-instruct-v0.1": MixtralChatDialog.self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ class PicoLLMAppTestUITests: BaseTest {
"gemma-chat-dialog": GemmaChatDialog.self,
"llama-2-chat-dialog": Llama2ChatDialog.self,
"llama-3-chat-dialog": Llama3ChatDialog.self,
"llama-3.2-chat-dialog": Llama32ChatDialog.self,
"mistral-chat-dialog": MistralChatDialog.self,
"phi2-chat-dialog": Phi2ChatDialog.self,
"phi2-qa-dialog": Phi2QADialog.self,
Expand Down
5 changes: 5 additions & 0 deletions binding/ios/PicoLLMDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ public class Llama3ChatDialog: BasePicoLLMDialog {
}
}

/// Dialog helper for `llama-3.2-1b-instruct` and `llama-3.2-3b-instruct`.
public class Llama32ChatDialog: Llama3ChatDialog {

Check failure on line 328 in binding/ios/PicoLLMDialog.swift

View workflow job for this annotation

GitHub Actions / check-swift-codestyle

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
}

/// Dialog helper for `gemma-2b-it` and `gemma-7b-it`.
public class GemmaChatDialog: BasePicoLLMDialog {
public override func prompt() throws -> String {
Expand Down
9 changes: 9 additions & 0 deletions binding/nodejs/src/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ export class Llama3ChatDialog extends Dialog {
}
}

/**
* Dialog helper for `llama-3.2-1b-instruct` and `llama-3.2-3b-instruct`.
*/
export class Llama32ChatDialog extends Llama3ChatDialog {

}

/**
* Dialog helper for `mistral-7b-instruct-v0.1` and `mistral-7b-instruct-v0.2`.
*/
Expand Down Expand Up @@ -273,6 +280,8 @@ export const DIALOGS: { [key: string]: typeof Dialog | { [key: string]: typeof D
'llama-2-70b-chat': Llama2ChatDialog,
'llama-3-8b-instruct': Llama3ChatDialog,
'llama-3-70b-instruct': Llama3ChatDialog,
'llama-3.2-1b-instruct': Llama32ChatDialog,
'llama-3.2-3b-instruct': Llama32ChatDialog,
'mistral-7b-instruct-v0.1': MistralChatDialog,
'mistral-7b-instruct-v0.2': MistralChatDialog,
'mixtral-8x7b-instruct-v0.1': MixtralChatDialog,
Expand Down
2 changes: 2 additions & 0 deletions binding/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
GemmaChatDialog,
Llama2ChatDialog,
Llama3ChatDialog,
Llama32ChatDialog,
MistralChatDialog,
MixtralChatDialog,
Phi2Dialog,
Expand All @@ -58,6 +59,7 @@ export {
GemmaChatDialog,
Llama2ChatDialog,
Llama3ChatDialog,
Llama32ChatDialog,
MistralChatDialog,
MixtralChatDialog,
Phi2Dialog,
Expand Down
3 changes: 3 additions & 0 deletions binding/nodejs/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
GemmaChatDialog,
Llama2ChatDialog,
Llama3ChatDialog,
Llama32ChatDialog,
MistralChatDialog,
Phi2ChatDialog,
Phi2QADialog,
Expand Down Expand Up @@ -46,6 +47,7 @@ const DIALOG_CLASSES: { [key: string]: typeof Dialog } = {
'gemma-chat-dialog': GemmaChatDialog,
"llama-2-chat-dialog": Llama2ChatDialog,
"llama-3-chat-dialog": Llama3ChatDialog,
"llama-3.2-chat-dialog": Llama32ChatDialog,
"mistral-chat-dialog": MistralChatDialog,
'phi2-chat-dialog': Phi2ChatDialog,
'phi2-qa-dialog': Phi2QADialog,
Expand All @@ -65,6 +67,7 @@ type DialogExpectations = {
'gemma-chat-dialog': string,
"llama-2-chat-dialog": string,
"llama-3-chat-dialog": string,
"llama-3.2-chat-dialog": string,
"mistral-chat-dialog": string,
'phi2-chat-dialog': string,
'phi2-qa-dialog': string,
Expand Down
12 changes: 12 additions & 0 deletions binding/python/_picollm.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ def prompt(self) -> str:
return ''.join(res)


class Llama32ChatDialog(Llama3ChatDialog):
"""
Dialog helper for `llama-3.2-1b-instruct` and `llama-3.2-3b-instruct`.
"""

def __init__(self, history: Optional[int] = None, system: Optional[str] = None) -> None:
super().__init__(history=history, system=system)


class MistralChatDialog(Dialog):
"""
Dialog helper for `mistral-7b-instruct-v0.1` and `mistral-7b-instruct-v0.2`.
Expand Down Expand Up @@ -975,6 +984,8 @@ def get_error_stack(self) -> Sequence[str]:
'llama-2-70b-chat': Llama2ChatDialog,
'llama-3-8b-instruct': Llama3ChatDialog,
'llama-3-70b-instruct': Llama3ChatDialog,
'llama-3.2-1b-instruct': Llama32ChatDialog,
'llama-3.2-3b-instruct': Llama32ChatDialog,
'mistral-7b-instruct-v0.1': MistralChatDialog,
'mistral-7b-instruct-v0.2': MistralChatDialog,
'mixtral-8x7b-instruct-v0.1': MixtralChatDialog,
Expand Down Expand Up @@ -1034,6 +1045,7 @@ def get_dialog(
'GemmaChatDialog',
'Llama2ChatDialog',
'Llama3ChatDialog',
'Llama32ChatDialog',
'MistralChatDialog',
'MixtralChatDialog',
'Phi2ChatDialog',
Expand Down
2 changes: 2 additions & 0 deletions binding/python/test_picollm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
GemmaChatDialog,
Llama2ChatDialog,
Llama3ChatDialog,
Llama32ChatDialog,
MistralChatDialog,
Phi2ChatDialog,
Phi2QADialog,
Expand Down Expand Up @@ -466,6 +467,7 @@ def setUpClass(cls) -> None:
"gemma-chat-dialog": GemmaChatDialog,
"llama-2-chat-dialog": Llama2ChatDialog,
"llama-3-chat-dialog": Llama3ChatDialog,
"llama-3.2x-chat-dialog": Llama32ChatDialog,
"mistral-chat-dialog": MistralChatDialog,
"phi2-chat-dialog": Phi2ChatDialog,
"phi2-qa-dialog": Phi2QADialog,
Expand Down
9 changes: 9 additions & 0 deletions binding/web/src/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ export class Llama3ChatDialog extends Dialog {
}
}

/**
* Dialog helper for `llama-3.2-1b-instruct` and `llama-3.2-3b-instruct`.
*/
export class Llama32ChatDialog extends Llama3ChatDialog {

}

/**
* Dialog helper for `mistral-7b-instruct-v0.1` and `mistral-7b-instruct-v0.2`.
*/
Expand Down Expand Up @@ -272,6 +279,8 @@ export const DIALOGS: { [key: string]: typeof Dialog | { [key: string]: typeof D
'llama-2-70b-chat': Llama2ChatDialog,
'llama-3-8b-instruct': Llama3ChatDialog,
'llama-3-70b-instruct': Llama3ChatDialog,
'llama-3.2-1b-instruct': Llama32ChatDialog,
'llama-3.2-3b-instruct': Llama32ChatDialog,
'mistral-7b-instruct-v0.1': MistralChatDialog,
'mistral-7b-instruct-v0.2': MistralChatDialog,
'mixtral-8x7b-instruct-v0.1': MixtralChatDialog,
Expand Down
2 changes: 2 additions & 0 deletions binding/web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
GemmaChatDialog,
Llama2ChatDialog,
Llama3ChatDialog,
Llama32ChatDialog,
MistralChatDialog,
MixtralChatDialog,
Phi2Dialog,
Expand Down Expand Up @@ -54,6 +55,7 @@ export {
GemmaChatDialog,
Llama2ChatDialog,
Llama3ChatDialog,
Llama32ChatDialog,
MistralChatDialog,
MixtralChatDialog,
Phi2Dialog,
Expand Down
2 changes: 2 additions & 0 deletions binding/web/test/picollm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
GemmaChatDialog,
Llama2ChatDialog,
Llama3ChatDialog,
Llama32ChatDialog,
MistralChatDialog,
Phi2ChatDialog,
Phi2QADialog,
Expand All @@ -27,6 +28,7 @@ const DIALOG_CLASSES: { [key: string]: typeof Dialog } = {
'gemma-chat-dialog': GemmaChatDialog,
"llama-2-chat-dialog": Llama2ChatDialog,
"llama-3-chat-dialog": Llama3ChatDialog,
"llama-3.2-chat-dialog": Llama32ChatDialog,
"mistral-chat-dialog": MistralChatDialog,
'phi2-chat-dialog': Phi2ChatDialog,
'phi2-qa-dialog': Phi2QADialog,
Expand Down
4 changes: 4 additions & 0 deletions resources/.test/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"gemma-chat-dialog": "<start_of_turn>user\nHi<end_of_turn>\n<start_of_turn>model\nHey<end_of_turn>\n<start_of_turn>user\nHola<end_of_turn>\n<start_of_turn>model\n¡Oye!<end_of_turn>\n<start_of_turn>user\nSalut<end_of_turn>\n<start_of_turn>model",
"llama-2-chat-dialog": "<s>[INST] Hi [/INST] Hey </s><s>[INST] Hola [/INST] ¡Oye! </s><s>[INST] Salut [/INST]",
"llama-3-chat-dialog": "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nHi<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nHey<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHola<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n¡Oye!<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nSalut<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
"llama-3.2-chat-dialog": "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nHi<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nHey<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHola<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n¡Oye!<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nSalut<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
"mistral-chat-dialog": "[INST] Hi [/INST] Hey</s>[INST] Hola [/INST] ¡Oye!</s>[INST] Salut [/INST]",
"phi2-chat-dialog": "Human: Hi\nAI: Hey\nHuman: Hola\nAI: ¡Oye!\nHuman: Salut\nAI:",
"phi2-qa-dialog": "Instruct: Hi\nOutput: Hey\nInstruct: Hola\nOutput: ¡Oye!\nInstruct: Salut\nOutput:",
Expand All @@ -198,6 +199,7 @@
"gemma-chat-dialog": "<start_of_turn>user\nHi<end_of_turn>\n<start_of_turn>model\nHey<end_of_turn>\n<start_of_turn>user\nHola<end_of_turn>\n<start_of_turn>model\n¡Oye!<end_of_turn>\n<start_of_turn>user\nSalut<end_of_turn>\n<start_of_turn>model",
"llama-2-chat-dialog": "<s>[INST] <<SYS>>\nrespond with ❤️ and \uD83E\uDEE1\n<</SYS>>\n\nHi [/INST] Hey </s><s>[INST] Hola [/INST] ¡Oye! </s><s>[INST] Salut [/INST]",
"llama-3-chat-dialog": "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nHi<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nHey<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHola<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n¡Oye!<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nSalut<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
"llama-3.2-chat-dialog": "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nHi<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nHey<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHola<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n¡Oye!<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nSalut<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
"mistral-chat-dialog": "[INST] Hi [/INST] Hey</s>[INST] Hola [/INST] ¡Oye!</s>[INST] Salut [/INST]",
"phi2-chat-dialog": "Human: Hi\nAI: Hey\nHuman: Hola\nAI: ¡Oye!\nHuman: Salut\nAI:",
"phi2-qa-dialog": "Instruct: Hi\nOutput: Hey\nInstruct: Hola\nOutput: ¡Oye!\nInstruct: Salut\nOutput:",
Expand All @@ -208,6 +210,7 @@
"gemma-chat-dialog": "<start_of_turn>user\nSalut<end_of_turn>\n<start_of_turn>model",
"llama-2-chat-dialog": "<s>[INST] Salut [/INST]",
"llama-3-chat-dialog": "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nSalut<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
"llama-3.2-chat-dialog": "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nSalut<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
"mistral-chat-dialog": "[INST] Salut [/INST]",
"phi2-chat-dialog": "Human: Salut\nAI:",
"phi2-qa-dialog": "Instruct: Salut\nOutput:",
Expand All @@ -218,6 +221,7 @@
"gemma-chat-dialog": "<start_of_turn>user\nSalut<end_of_turn>\n<start_of_turn>model",
"llama-2-chat-dialog": "<s>[INST] <<SYS>>\nrespond with ❤️ and \uD83E\uDEE1\n<</SYS>>\n\nSalut [/INST]",
"llama-3-chat-dialog": "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nSalut<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
"llama-3.2-chat-dialog": "<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\nSalut<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",
"mistral-chat-dialog": "[INST] Salut [/INST]",
"phi2-chat-dialog": "Human: Salut\nAI:",
"phi2-qa-dialog": "Instruct: Salut\nOutput:",
Expand Down

0 comments on commit ae8b093

Please sign in to comment.