Skip to content

Commit dd29482

Browse files
Merge branch 'huggingface:main' into main
2 parents a0c7b9b + 8e300b6 commit dd29482

22 files changed

+937
-215
lines changed

README.md

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ app_port: 3000
1212

1313
# Chat UI
1414

15-
![Chat UI repository thumbnail](https://huggingface.co/datasets/huggingface/documentation-images/raw/f038917dd40d711a72d654ab1abfc03ae9f177e6/chat-ui-repo-thumbnail.svg)
15+
![Chat UI repository thumbnail](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/chatui-websearch.png)
1616

1717
A chat interface using open source models, eg OpenAssistant or Llama. It is a SvelteKit app and it powers the [HuggingChat app on hf.co/chat](https://huggingface.co/chat).
1818

1919
0. [No Setup Deploy](#no-setup-deploy)
2020
1. [Setup](#setup)
2121
2. [Launch](#launch)
22-
3. [Extra parameters](#extra-parameters)
23-
4. [Deploying to a HF Space](#deploying-to-a-hf-space)
24-
5. [Building](#building)
22+
3. [Web Search](#web-search)
23+
4. [Extra parameters](#extra-parameters)
24+
5. [Deploying to a HF Space](#deploying-to-a-hf-space)
25+
6. [Building](#building)
2526

2627
##  No Setup Deploy
2728

@@ -70,6 +71,16 @@ npm install
7071
npm run dev
7172
```
7273

74+
## Web Search
75+
76+
Chat UI features a powerful Web Search feature. It works by:
77+
78+
1. Generating an appropriate Google query from the user prompt.
79+
2. Performing Google search and extracting content from webpages.
80+
3. Creating embeddings from texts using [transformers.js](https://huggingface.co/docs/transformers.js). Specifically, using [Xenova/e5-small-v2](https://huggingface.co/Xenova/e5-small-v2) model.
81+
4. From these embeddings, find the ones that are closest to the user query using vector similarity search. Specifically, we use `inner product` distance.
82+
5. Get the corresponding texts to those closest embeddings and perform [Retrieval-Augmented Generation](https://huggingface.co/papers/2005.11401) (i.e. expand user prompt by adding those texts so that a LLM can use this information).
83+
7384
## Extra parameters
7485

7586
### OpenID connect
@@ -155,7 +166,7 @@ You can change things like the parameters, or customize the preprompt to better
155166

156167
By default the prompt is constructed using `userMessageToken`, `assistantMessageToken`, `userMessageEndToken`, `assistantMessageEndToken`, `preprompt` parameters and a series of default templates.
157168

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.
169+
However, these templates can be modified by setting the `chatPromptTemplate` 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.
159170

160171
For example:
161172

@@ -187,33 +198,14 @@ The following is the default `chatPromptTemplate`, although newlines and indenti
187198

188199
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.
189200

190-
The following is the default `webSearchQueryPromptTemplate`. Note that not all models supports consecutive user-messages which this template uses.
201+
The following is the default `webSearchQueryPromptTemplate`.
191202

192203
```
193204
{{userMessageToken}}
194-
The following messages were written by a user, trying to answer a question.
205+
My question is: {{message.content}}.
206+
Based on the conversation history (my previous questions are: {{previousMessages}}), give me an appropriate query to answer my question for google search. You should not say more than query. You should not say any words except the query. For the context, today is {{currentDate}}
195207
{{userMessageEndToken}}
196-
{{#each messages}}
197-
{{#ifUser}}{{@root.userMessageToken}}{{content}}{{@root.userMessageEndToken}}{{/ifUser}}
198-
{{/each}}
199-
{{userMessageToken}}
200-
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.
210-
211-
```
212-
{{userMessageToken}}{{answer}}{{userMessageEndToken}}
213-
{{userMessageToken}}
214-
The text above should be summarized to best answer the query: {{query}}.
215-
{{userMessageEndToken}}
216-
{{assistantMessageToken}}Summary:
208+
{{assistantMessageToken}}
217209
```
218210

219211
#### Running your own models using a custom endpoint

0 commit comments

Comments
 (0)