MariaK commited on
Commit
b489da3
1 Parent(s): 6546e1f

Update src/routes/conversation/[id]/+server.ts

Browse files
src/routes/conversation/[id]/+server.ts CHANGED
@@ -70,6 +70,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
70
 
71
  // fetch the model
72
  const model = models.find((m) => m.id === conv.model);
 
73
 
74
  if (!model) {
75
  throw error(410, "Model not available anymore");
@@ -84,6 +85,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
84
  id: messageId,
85
  is_retry,
86
  web_search: webSearch,
 
87
  } = z
88
  .object({
89
  inputs: z.string().trim().min(1),
@@ -91,6 +93,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
91
  response_id: z.optional(z.string().uuid()),
92
  is_retry: z.optional(z.boolean()),
93
  web_search: z.optional(z.boolean()),
 
94
  })
95
  .parse(json);
96
 
@@ -121,27 +124,6 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
121
  ];
122
  })() satisfies Message[];
123
 
124
- if (conv.title.startsWith("Untitled")) {
125
- try {
126
- conv.title = (await summarize(newPrompt)) ?? conv.title;
127
- } catch (e) {
128
- console.error(e);
129
- }
130
- }
131
-
132
- await collections.conversations.updateOne(
133
- {
134
- _id: convId,
135
- },
136
- {
137
- $set: {
138
- messages,
139
- title: conv.title,
140
- updatedAt: new Date(),
141
- },
142
- }
143
- );
144
-
145
  // we now build the stream
146
  const stream = new ReadableStream({
147
  async start(controller) {
@@ -159,7 +141,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
159
  let webSearchResults: WebSearch | undefined;
160
 
161
  if (webSearch) {
162
- webSearchResults = await runWebSearch(conv, newPrompt, update);
163
  }
164
 
165
  // we can now build the prompt using the messages
@@ -167,7 +149,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
167
  messages,
168
  model,
169
  webSearch: webSearchResults,
170
- preprompt: conv.preprompt ?? model.preprompt,
171
  locals: locals,
172
  });
173
 
@@ -189,7 +171,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
189
 
190
  async function saveLast(generated_text: string) {
191
  if (!conv) {
192
- throw error(404, "Conversation not found");
193
  }
194
 
195
  const lastMessage = messages[messages.length - 1];
@@ -220,7 +202,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
220
  {
221
  $set: {
222
  messages,
223
- title: conv.title,
224
  updatedAt: new Date(),
225
  },
226
  }
@@ -303,7 +285,7 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
303
  {
304
  $set: {
305
  messages,
306
- title: conv.title,
307
  updatedAt: new Date(),
308
  },
309
  }
@@ -360,4 +342,4 @@ export async function PATCH({ request, locals, params }) {
360
  );
361
 
362
  return new Response();
363
- }
 
70
 
71
  // fetch the model
72
  const model = models.find((m) => m.id === conv.model);
73
+ const settings = await collections.settings.findOne(authCondition(locals));
74
 
75
  if (!model) {
76
  throw error(410, "Model not available anymore");
 
85
  id: messageId,
86
  is_retry,
87
  web_search: webSearch,
88
+ domainFilters: domainFilters,
89
  } = z
90
  .object({
91
  inputs: z.string().trim().min(1),
 
93
  response_id: z.optional(z.string().uuid()),
94
  is_retry: z.optional(z.boolean()),
95
  web_search: z.optional(z.boolean()),
96
+ domainFilters: z.optional(z.string()),
97
  })
98
  .parse(json);
99
 
 
124
  ];
125
  })() satisfies Message[];
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  // we now build the stream
128
  const stream = new ReadableStream({
129
  async start(controller) {
 
141
  let webSearchResults: WebSearch | undefined;
142
 
143
  if (webSearch) {
144
+ webSearchResults = await runWebSearch(conv, newPrompt, update, domainFilters);
145
  }
146
 
147
  // we can now build the prompt using the messages
 
149
  messages,
150
  model,
151
  webSearch: webSearchResults,
152
+ preprompt: settings?.customPrompts?.[model.id] ?? model.preprompt,
153
  locals: locals,
154
  });
155
 
 
171
 
172
  async function saveLast(generated_text: string) {
173
  if (!conv) {
174
+ throw new Error("Conversation not found");
175
  }
176
 
177
  const lastMessage = messages[messages.length - 1];
 
202
  {
203
  $set: {
204
  messages,
205
+ title: (await summarize(newPrompt)) ?? conv.title,
206
  updatedAt: new Date(),
207
  },
208
  }
 
285
  {
286
  $set: {
287
  messages,
288
+ title: (await summarize(newPrompt)) ?? conv.title,
289
  updatedAt: new Date(),
290
  },
291
  }
 
342
  );
343
 
344
  return new Response();
345
+ }