Skip to content

Commit

Permalink
update (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
swuecho authored Dec 4, 2023
1 parent 3f0d7bd commit c9aaebc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/chat_main_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ func (h *ChatHandler) chatOllamStram(w http.ResponseWriter, chatSession sqlc_que
prompt = formatNeuralChatPrompt(chat_compeletion_messages)
} else if chatSession.Model == "ollama-minstral" {
prompt = formatMinstralPrompt(chat_compeletion_messages)
} else if chatSession.Model =="ollama-openhermes-neural-chat" {
prompt = formatNeuralChatPrompt(chat_compeletion_messages)
} else {
prompt = formatNeuralChatPrompt(chat_compeletion_messages)
}
Expand Down Expand Up @@ -807,7 +809,7 @@ func (h *ChatHandler) chatOllamStram(w http.ResponseWriter, chatSession sqlc_que
if err != nil {
return "", "", true
}
answer += streamResp.Response
answer += strings.ReplaceAll(streamResp.Response, "<0x0A>", "\n")
if streamResp.Done {
// stream.isFinished = true
fmt.Println("DONE break")
Expand Down
23 changes: 23 additions & 0 deletions api/ollama.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ func formatNeuralChatPrompt(chat_compeletion_messages []Message) string {
print(prompt)
return prompt
}

// <|im_start|>system
// {system}<|im_end|>
// <|im_start|>user
// {user}<|im_end|>
// <|im_start|>assistant
// {asistant}<|im_end|>
func formatOpenHermesNeuralChatPrompt(chat_compeletion_messages []Message) string {
var sb strings.Builder

for _, message := range chat_compeletion_messages {
if message.Role == "system" {
sb.WriteString(fmt.Sprintf("<|im_start|>system\n%s<|im_end|>\n", message.Content))
} else if message.Role == "user" {
sb.WriteString(fmt.Sprintf("<|im_start|>user\n%s<|im_end|>\n", message.Content))
} else {
sb.WriteString(fmt.Sprintf("<|im_start|>assistant\n%s<|im_end|>\n", message.Content))
}
}
prompt := sb.String()
print(prompt)
return prompt
}

0 comments on commit c9aaebc

Please sign in to comment.