Spaces:
Running
Running
Return an error on unknown model in new conversation (#916)
Browse files
src/routes/conversation/+server.ts
CHANGED
|
@@ -16,14 +16,19 @@ export const POST: RequestHandler = async ({ locals, request }) => {
|
|
| 16 |
|
| 17 |
let title = "";
|
| 18 |
|
| 19 |
-
const
|
| 20 |
.object({
|
| 21 |
fromShare: z.string().optional(),
|
| 22 |
model: validateModel(models),
|
| 23 |
assistantId: z.string().optional(),
|
| 24 |
preprompt: z.string().optional(),
|
| 25 |
})
|
| 26 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
const convCount = await collections.conversations.countDocuments(authCondition(locals));
|
| 29 |
|
|
@@ -34,14 +39,13 @@ export const POST: RequestHandler = async ({ locals, request }) => {
|
|
| 34 |
);
|
| 35 |
}
|
| 36 |
|
| 37 |
-
// get preprompt from assistant if it exists
|
| 38 |
-
|
| 39 |
const model = models.find((m) => m.name === values.model);
|
| 40 |
|
| 41 |
if (!model) {
|
| 42 |
throw error(400, "Invalid model");
|
| 43 |
}
|
| 44 |
|
|
|
|
| 45 |
const assistant = await collections.assistants.findOne({
|
| 46 |
_id: new ObjectId(values.assistantId),
|
| 47 |
});
|
|
|
|
| 16 |
|
| 17 |
let title = "";
|
| 18 |
|
| 19 |
+
const parsedBody = z
|
| 20 |
.object({
|
| 21 |
fromShare: z.string().optional(),
|
| 22 |
model: validateModel(models),
|
| 23 |
assistantId: z.string().optional(),
|
| 24 |
preprompt: z.string().optional(),
|
| 25 |
})
|
| 26 |
+
.safeParse(JSON.parse(body));
|
| 27 |
+
|
| 28 |
+
if (!parsedBody.success) {
|
| 29 |
+
throw error(400, "Invalid request");
|
| 30 |
+
}
|
| 31 |
+
const values = parsedBody.data;
|
| 32 |
|
| 33 |
const convCount = await collections.conversations.countDocuments(authCondition(locals));
|
| 34 |
|
|
|
|
| 39 |
);
|
| 40 |
}
|
| 41 |
|
|
|
|
|
|
|
| 42 |
const model = models.find((m) => m.name === values.model);
|
| 43 |
|
| 44 |
if (!model) {
|
| 45 |
throw error(400, "Invalid model");
|
| 46 |
}
|
| 47 |
|
| 48 |
+
// get preprompt from assistant if it exists
|
| 49 |
const assistant = await collections.assistants.findOne({
|
| 50 |
_id: new ObjectId(values.assistantId),
|
| 51 |
});
|