Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit d8b4523

Browse files
committed
fix: add llama3 chat template
1 parent c549d2e commit d8b4523

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cortex-js/src/infrastructure/commanders/prompt-constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export const ZEPHYR_JINJA = `{% for message in messages %}
1717
{% endif %}
1818
{% endfor %}`;
1919

20+
export const LLAMA_3_JINJA = `{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>
21+
22+
'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{% if add_generation_prompt %}{{ '<|start_header_id|>assistant<|end_header_id|>
23+
24+
' }}{% endif %}`;
25+
2026
//// Corresponding prompt template
2127
export const OPEN_CHAT_3_5 = `GPT4 Correct User: {prompt}<|end_of_turn|>GPT4 Correct Assistant:`;
2228

@@ -35,3 +41,5 @@ export const LLAMA_2 = `[INST] <<SYS>>
3541
{system_message}
3642
<</SYS>>
3743
{prompt}[/INST]`;
44+
export const LLAMA_3 =
45+
'<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{system_message}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n';

cortex-js/src/infrastructure/commanders/usecases/models.cli.usecases.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { Inject, Injectable } from '@nestjs/common';
1414
import { Presets, SingleBar } from 'cli-progress';
1515
import {
1616
LLAMA_2,
17+
LLAMA_3,
18+
LLAMA_3_JINJA,
1719
OPEN_CHAT_3_5,
1820
OPEN_CHAT_3_5_JINJA,
1921
ZEPHYR,
@@ -262,6 +264,9 @@ export class ModelsCliUsecases {
262264
case OPEN_CHAT_3_5_JINJA:
263265
return OPEN_CHAT_3_5;
264266

267+
case LLAMA_3_JINJA:
268+
return LLAMA_3;
269+
265270
default:
266271
// console.log(
267272
// 'Unknown jinja code:',

0 commit comments

Comments
 (0)