Skip to content

Commit 1f23930

Browse files
committed
feat: let tweak how chat messages are merged together
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 57ef494 commit 1f23930

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

core/config/backend_config.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ type Diffusers struct {
9393
ControlNet string `yaml:"control_net"`
9494
}
9595

96+
// LLMConfig is a struct that holds the configuration that are
97+
// generic for most of the LLM backends.
9698
type LLMConfig struct {
9799
SystemPrompt string `yaml:"system_prompt"`
98100
TensorSplit string `yaml:"tensor_split"`
@@ -144,20 +146,39 @@ type LLMConfig struct {
144146
YarnBetaSlow float32 `yaml:"yarn_beta_slow"`
145147
}
146148

149+
// AutoGPTQ is a struct that holds the configuration specific to the AutoGPTQ backend
147150
type AutoGPTQ struct {
148151
ModelBaseName string `yaml:"model_base_name"`
149152
Device string `yaml:"device"`
150153
Triton bool `yaml:"triton"`
151154
UseFastTokenizer bool `yaml:"use_fast_tokenizer"`
152155
}
153156

157+
// TemplateConfig is a struct that holds the configuration of the templating system
154158
type TemplateConfig struct {
155-
Chat string `yaml:"chat"`
156-
ChatMessage string `yaml:"chat_message"`
157-
Completion string `yaml:"completion"`
158-
Edit string `yaml:"edit"`
159-
Functions string `yaml:"function"`
160-
UseTokenizerTemplate bool `yaml:"use_tokenizer_template"`
159+
// Chat is the template used in the chat completion endpoint
160+
Chat string `yaml:"chat"`
161+
162+
// ChatMessage is the template used for chat messages
163+
ChatMessage string `yaml:"chat_message"`
164+
165+
// Completion is the template used for completion requests
166+
Completion string `yaml:"completion"`
167+
168+
// Edit is the template used for edit completion requests
169+
Edit string `yaml:"edit"`
170+
171+
// Functions is the template used when tools are present in the client requests
172+
Functions string `yaml:"function"`
173+
174+
// UseTokenizerTemplate is a flag that indicates if the tokenizer template should be used.
175+
// Note: this is mostly consumed for backends such as vllm and transformers
176+
// that can use the tokenizers specified in the JSON config files of the models
177+
UseTokenizerTemplate bool `yaml:"use_tokenizer_template"`
178+
179+
// JoinChatMessagesByCharacter is a string that will be used to join chat messages together.
180+
// It defaults to \n
181+
JoinChatMessagesByCharacter *string `yaml:"join_chat_messages_by_character"`
161182
}
162183

163184
func (c *BackendConfig) SetFunctionCallString(s string) {

core/http/endpoints/openai/chat.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,12 @@ func ChatEndpoint(cl *config.BackendConfigLoader, ml *model.ModelLoader, startup
349349
mess = append(mess, content)
350350
}
351351

352-
predInput = strings.Join(mess, "\n")
352+
joinCharacter := "\n"
353+
if config.TemplateConfig.JoinChatMessagesByCharacter != nil {
354+
joinCharacter = *config.TemplateConfig.JoinChatMessagesByCharacter
355+
}
356+
357+
predInput = strings.Join(mess, joinCharacter)
353358
log.Debug().Msgf("Prompt (before templating): %s", predInput)
354359

355360
templateFile := ""

0 commit comments

Comments
 (0)