add user to to prompt template

This commit is contained in:
Bruce MacDonald 2023-11-20 12:42:45 -05:00
parent 75657e30e0
commit 3befd3dad9
3 changed files with 10 additions and 6 deletions

View File

@ -125,11 +125,11 @@ PARAMETER <parameter> <parametervalue>
#### Template Variables
| Variable | Description |
| --------------- | ------------------------------------------------------------------------------------------------------------ |
| `{{ .System }}` | The system prompt used to specify custom behavior, this must also be set in the Modelfile as an instruction. |
| `{{ .Prompt }}` | The incoming prompt, this is not specified in the model file and will be set based on input. |
| `{{ .First }}` | A boolean value used to render specific template information for the first generation of a session. |
| Variable | Description |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `{{ .System }}` | The system prompt used to specify custom behavior, this must also be set in the Modelfile as an instruction. |
| `{{ .Prompt }}` or `{{ .User }}` | The incoming prompt from the user, this is not specified in the model file and will be set based on input. |
| `{{ .First }}` | A boolean value used to render specific template information for the first generation of a session. |
```modelfile
TEMPLATE """

View File

@ -50,7 +50,8 @@ type Model struct {
type PromptVars struct {
System string
Prompt string
Prompt string // prompt and user are considered the same thing
User string
}
func (m *Model) Prompt(vars *PromptVars) (string, error) {

View File

@ -321,6 +321,7 @@ func promptFromRequestParams(c *gin.Context, model *Model, req api.GenerateReque
p, err := model.Prompt(&PromptVars{
System: req.System,
Prompt: req.Prompt,
User: req.Prompt,
})
if err != nil {
return "", err
@ -340,6 +341,7 @@ func promptFromMessages(model *Model, messages []api.Message) (string, error) {
prompt.WriteString(p)
vars.Prompt = ""
vars.User = ""
vars.System = ""
return nil
}
@ -364,6 +366,7 @@ func promptFromMessages(model *Model, messages []api.Message) (string, error) {
vars.System = m.Content
case "user":
vars.Prompt = m.Content
vars.User = m.Content
case "assistant":
prompt.WriteString(m.Content)
default: