Skip to content

Commit

Permalink
feat: Introduce OpenChat prompt format
Browse files Browse the repository at this point in the history
  • Loading branch information
macie committed Jan 2, 2024
1 parent b4c49e3 commit 9599f53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions llama/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ var promptFormats = map[string]func(Prompt) string{

return fmt.Sprintf("%s%s<|im_start|>assistant\n", systemPrompt, userPrompt)
},
"openchat": func(p Prompt) string {
systemPrompt := p.System
if systemPrompt != "" {
systemPrompt += "<|end_of_turn|>"
}
userPrompt := ""
for i := range p.userPrompt {
userPrompt += fmt.Sprintf("GPT4 Correct User: %s<|end_of_turn|>", p.userPrompt[i])
}
if userPrompt == "" {
userPrompt = "GPT4 Correct User: <|end_of_turn|>"
}

return fmt.Sprintf("%s%sGPT4 Correct Assistant: ", systemPrompt, userPrompt)
},
}

// Prompt represents prompt for the LLM.
Expand Down
2 changes: 2 additions & 0 deletions llama/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func TestPromptString(t *testing.T) {
}{
{Prompt{Format: "chatml"}, "<|im_start|>system\n<|im_end|>\n<|im_start|>user\n<|im_end|>\n<|im_start|>assistant\n"},
{Prompt{Format: "ChatML", System: "You are a helpful assistant."}, "<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<|im_end|>\n<|im_start|>assistant\n"},
{Prompt{Format: "openchat"}, "GPT4 Correct User: <|end_of_turn|>GPT4 Correct Assistant: "},
{Prompt{Format: "openchat", System: "You are a helpful assistant."}, "You are a helpful assistant.<|end_of_turn|>GPT4 Correct User: <|end_of_turn|>GPT4 Correct Assistant: "},
}

for _, tc := range testcases {
Expand Down

0 comments on commit 9599f53

Please sign in to comment.