nsarrazin HF staff commited on
Commit
10d1ab5
1 Parent(s): 3baa389

Add support for HF summarization endpoint in the websearch (#319)

Browse files
src/lib/server/websearch/summarizeWeb.ts CHANGED
@@ -1,7 +1,28 @@
 
 
1
  import { generateFromDefaultEndpoint } from "../generateFromDefaultEndpoint";
2
  import type { BackendModel } from "../models";
3
 
4
  export async function summarizeWeb(content: string, query: string, model: BackendModel) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  const summaryPrompt =
6
  model.userMessageToken +
7
  content
 
1
+ import { HF_ACCESS_TOKEN } from "$env/static/private";
2
+ import { HfInference } from "@huggingface/inference";
3
  import { generateFromDefaultEndpoint } from "../generateFromDefaultEndpoint";
4
  import type { BackendModel } from "../models";
5
 
6
  export async function summarizeWeb(content: string, query: string, model: BackendModel) {
7
+ // if HF_ACCESS_TOKEN is set, we use a HF dedicated endpoint for summarization
8
+ try {
9
+ if (HF_ACCESS_TOKEN) {
10
+ const summary = (
11
+ await new HfInference(HF_ACCESS_TOKEN).summarization({
12
+ model: "facebook/bart-large-cnn",
13
+ inputs: content,
14
+ parameters: {
15
+ max_length: 512,
16
+ },
17
+ })
18
+ ).summary_text;
19
+ return summary;
20
+ }
21
+ } catch (e) {
22
+ console.log(e);
23
+ }
24
+
25
+ // else we use the LLM to generate a summary
26
  const summaryPrompt =
27
  model.userMessageToken +
28
  content