coyotte508 HF staff olivierdehaene HF staff commited on
Commit
ffa4f55
1 Parent(s): b56bba1

✨ Add preprompt (#124)

Browse files
.env CHANGED
@@ -13,6 +13,7 @@ PUBLIC_DISABLE_INTRO_TILES=false
13
  PUBLIC_USER_MESSAGE_TOKEN=<|prompter|>
14
  PUBLIC_ASSISTANT_MESSAGE_TOKEN=<|assistant|>
15
  PUBLIC_SEP_TOKEN=<|endoftext|>
 
16
 
17
  # [{"endpoint": "https://api-inference.huggingface.co/models/...", authorization: "Bearer hf_<token>", weight: 1}] to load balance
18
  # Eg if one endpoint has weight 2 and the other has weight 1, the first endpoint will be called twice as often
 
13
  PUBLIC_USER_MESSAGE_TOKEN=<|prompter|>
14
  PUBLIC_ASSISTANT_MESSAGE_TOKEN=<|assistant|>
15
  PUBLIC_SEP_TOKEN=<|endoftext|>
16
+ PUBLIC_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."
17
 
18
  # [{"endpoint": "https://api-inference.huggingface.co/models/...", authorization: "Bearer hf_<token>", weight: 1}] to load balance
19
  # Eg if one endpoint has weight 2 and the other has weight 1, the first endpoint will be called twice as often
src/lib/buildPrompt.ts CHANGED
@@ -1,6 +1,7 @@
1
  import {
2
  PUBLIC_ASSISTANT_MESSAGE_TOKEN,
3
  PUBLIC_MAX_INPUT_TOKENS,
 
4
  PUBLIC_SEP_TOKEN,
5
  PUBLIC_USER_MESSAGE_TOKEN,
6
  } from "$env/static/public";
@@ -24,5 +25,9 @@ export function buildPrompt(messages: Message[]): string {
24
  .join("") + PUBLIC_ASSISTANT_MESSAGE_TOKEN;
25
 
26
  // Not super precise, but it's truncated in the model's backend anyway
27
- return prompt.split(" ").slice(-parseInt(PUBLIC_MAX_INPUT_TOKENS)).join(" ");
 
 
 
 
28
  }
 
1
  import {
2
  PUBLIC_ASSISTANT_MESSAGE_TOKEN,
3
  PUBLIC_MAX_INPUT_TOKENS,
4
+ PUBLIC_PREPROMPT,
5
  PUBLIC_SEP_TOKEN,
6
  PUBLIC_USER_MESSAGE_TOKEN,
7
  } from "$env/static/public";
 
25
  .join("") + PUBLIC_ASSISTANT_MESSAGE_TOKEN;
26
 
27
  // Not super precise, but it's truncated in the model's backend anyway
28
+ return (
29
+ PUBLIC_PREPROMPT +
30
+ "\n-----\n" +
31
+ prompt.split(" ").slice(-parseInt(PUBLIC_MAX_INPUT_TOKENS)).join(" ")
32
+ );
33
  }
src/routes/conversation/[id]/summarize/+server.ts CHANGED
@@ -21,7 +21,7 @@ export async function POST({ params, locals, fetch }) {
21
  const firstMessage = conversation.messages.find((m) => m.from === "user");
22
 
23
  const userPrompt =
24
- `You are a summarizing assistant. Please summarize the following message as a single sentence of less than 5 words:\n` +
25
  firstMessage?.content;
26
 
27
  const prompt = buildPrompt([{ from: "user", content: userPrompt }]);
 
21
  const firstMessage = conversation.messages.find((m) => m.from === "user");
22
 
23
  const userPrompt =
24
+ `Please summarize the following message as a single sentence of less than 5 words:\n` +
25
  firstMessage?.content;
26
 
27
  const prompt = buildPrompt([{ from: "user", content: userPrompt }]);