coyotte508 HF staff commited on
Commit
88e9476
β€’
1 Parent(s): b8a746c

πŸ› Fix DL link in shared convo

Browse files
src/routes/r/[id]/message/[messageId]/prompt/+server.ts ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { buildPrompt } from "$lib/buildPrompt.js";
2
+ import { collections } from "$lib/server/database";
3
+ import { models } from "$lib/server/models.js";
4
+ import { error } from "@sveltejs/kit";
5
+
6
+ export async function GET({ params }) {
7
+ const conv = await collections.sharedConversations.findOne({
8
+ _id: params.id,
9
+ });
10
+
11
+ if (!conv) {
12
+ throw error(404, "Conversation not found");
13
+ }
14
+
15
+ const messageId = params.messageId;
16
+
17
+ const messageIndex = conv.messages.findIndex((msg) => msg.id === messageId);
18
+
19
+ if (messageIndex === -1) {
20
+ throw error(404, "Message not found");
21
+ }
22
+
23
+ const model = models.find((m) => m.name === conv.model);
24
+
25
+ if (!model) {
26
+ throw error(404, "Conversation model not found");
27
+ }
28
+
29
+ const prompt = buildPrompt(conv.messages.slice(0, messageIndex + 1), model);
30
+
31
+ return new Response(
32
+ JSON.stringify(
33
+ {
34
+ note: "This is a preview of the prompt that will be sent to the model when retrying the message. It may differ from what was sent in the past if the parameters have been updated since",
35
+ prompt,
36
+ model: model.name,
37
+ parameters: {
38
+ ...model.parameters,
39
+ return_full_text: false,
40
+ },
41
+ },
42
+ null,
43
+ 2
44
+ ),
45
+ { headers: { "Content-Type": "application/json" } }
46
+ );
47
+ }