You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Make all prompt templates configurable
This PR enables all prompts to be configurable using handlebar
templates as described in #382.
For backward compatibility the old hardcoded templates are
reimplemented as the default templates. The old template parameters
such as `preprompt`, `userMessageToken`, `userMessageEndToken`,
`assistantMessageToken`, `assistantMessageEndToken` are now considered
legacy. They still work as they are exposed as variables to the default
template. However, new prompt configurations should not use these. And
it is recommended that the legacy support is eventually removed.
As an example, this is how the default chat prompt template is
implemented:
```
{{preprompt}}
{{#each messages}}
{{#ifUser}}{{@root.userMessageToken}}{{content}}{{@root.userMessageEndToken}}{{/ifUser}}
{{#ifAssistant}}{{@root.assistantMessageToken}}{{content}}{{@root.assistantMessageEndToken}}{{/ifAssistant}}
{{/each}}
{{assistantMessageToken}}
```
In addition, this PR fixes an issue where the `model` configuration was used
to generate the prompts in WebSearch. However, the `defaultModel` was used
to query. This caused issues when the `model` and `defaultModel` uses
different prompt configurations. This has now been changed to always use
the `defaultModel`.
Note, when developing this PR, it has been observed that the WebSearch
prompts can violate typical model assumptions. For example, a query may
be generated as:
```
Assistant: The following context ...
User: content ...
```
```
User: user message 1
User: user message 2
Assistant:
```
Models typically assume the prompts to be User -> Assistant -> User. For
best compatability with existing configurations, this issues was not
fixed. Instead, the old behavior is maintained with the default
templates. This is also the reason why `defaultModel` was chosen as the
WebSearch model instead of `model`. As `defaultModel` may allow the
WebSearch format, while `model` might not.
This behavior, as well as the overall aritecture of chat-ui,
necessitated that the template input maintained the format
```
messages: [{from: 'user' | 'assistant', content: string }]
```
For the template to be able to detect which source a message comes from
a `ifUser` and a `ifAssistant` handlebar block-helper was implemented.
The original proposed format in #382 was:
```
history: [{ user: string, assistant: string }]
```
However, using such format would require significant changes to the
project and would make it impossible to implement the existing
websearch templates.
Finally, there may be minor differences in how truncation is
implemented. As in some cases, truncation is now applied to the entire
prompt, rather than part of the prompt.
Fixes: #382
* Add Sagemaker support (#401)
* work on sagemaker support
* fix sagemaker integration
* remove unnecessary deps
* fix default endpoint
* remove unneeded deps, fixed types
* Use conditional validation for endpoints
This was needed because the discriminated union couldn't handle the legacy case where `host` is undefined.
* add note in readme about aws sagemaker
* lint
* -summery +summary
---------
Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
Copy file name to clipboardExpand all lines: README.md
+68-4Lines changed: 68 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -120,9 +120,8 @@ MODELS=`[
120
120
"websiteUrl": "https://open-assistant.io",
121
121
"userMessageToken": "<|prompter|>", # This does not need to be a token, can be any string
122
122
"assistantMessageToken": "<|assistant|>", # This does not need to be a token, can be any string
123
-
"messageEndToken": "<|endoftext|>", # This does not need to be a token, can be any string
124
-
# "userMessageEndToken": "", # Applies only to user messages, messageEndToken has no effect if specified. Can be any string.
125
-
# "assistantMessageEndToken": "", # Applies only to assistant messages, messageEndToken has no effect if specified. Can be any string.
123
+
"userMessageEndToken": "<|endoftext|>", # Applies only to user messages. Can be any string.
124
+
"assistantMessageEndToken": "<|endoftext|>", # Applies only to assistant messages. Can be any string.
126
125
"preprompt": "Below are a series of dialogues between various people and an AI assistant. The AI tries to be helpful, polite, honest, sophisticated, emotionally aware, and humble-but-knowledgeable. The assistant is happy to help with almost anything, and will do its best to understand exactly what is needed. It also tries to avoid giving false or misleading information, and it caveats when it isn't entirely sure about the right answer. That said, the assistant is practical and really does its best, and doesn't let caution get too much in the way of being useful.\n-----\n",
127
126
"promptExamples": [
128
127
{
@@ -152,7 +151,72 @@ MODELS=`[
152
151
153
152
You can change things like the parameters, or customize the preprompt to better suit your needs. You can also add more models by adding more objects to the array, with different preprompts for example.
154
153
155
-
### Running your own models using a custom endpoint
154
+
#### Custom prompt templates:
155
+
156
+
By default the prompt is constructed using `userMessageToken`, `assistantMessageToken`, `userMessageEndToken`, `assistantMessageEndToken`, `preprompt` parameters and a series of default templates.
157
+
158
+
However, these templates can be modified by setting the `chatPromptTemplate`, `webSearchSummaryPromptTemplate`, and `webSearchQueryPromptTemplate` parameters. Note that if WebSearch is not enabled, only `chatPromptTemplate` needs to be set. The template language is https://handlebarsjs.com. The templates have access to the model's prompt parameters (`preprompt`, etc.). However, if the templates are specified it is recommended to inline the prompt parameters, as using the references (`{{preprompt}}`) is deprecated.
When quering the model for a chat response, the `chatPromptTemplate` template is used. `messages` is an array of chat messages, it has the format `[{ content: string }, ...]`. To idenify if a message is a user message or an assistant message the `ifUser` and `ifAssistant` block helpers can be used.
174
+
175
+
The following is the default `chatPromptTemplate`, although newlines and indentiation have been added for readability.
When performing a websearch, the search query is constructed using the `webSearchQueryPromptTemplate` template. It is recommended that that the prompt instructs the chat model to only return a few keywords.
189
+
190
+
The following is the default `webSearchQueryPromptTemplate`. Note that not all models supports consecutive user-messages which this template uses.
191
+
192
+
```
193
+
{{userMessageToken}}
194
+
The following messages were written by a user, trying to answer a question.
What plain-text english sentence would you input into Google to answer the last question? Answer with a short (10 words max) simple sentence.
201
+
{{userMessageEndToken}}
202
+
{{assistantMessageToken}}Query:
203
+
```
204
+
205
+
**webSearchSummaryPromptTemplate**
206
+
207
+
The search-engine response (`answer`) is summarized using the following prompt template. However, when `HF_ACCESS_TOKEN` is provided, a dedicated summary model is used instead. Additionally, the model's `query` response to `webSearchQueryPromptTemplate` is also available to this template.
208
+
209
+
The following is the default `webSearchSummaryPromptTemplate`. Note that not all models supports consecutive user-messages which this template uses.
0 commit comments