Skip to content

Commit

Permalink
Return an error on unknown model in new conversation (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin committed Mar 8, 2024
1 parent 5b199ff commit 403d4bd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/routes/conversation/+server.ts
Expand Up @@ -16,14 +16,19 @@ export const POST: RequestHandler = async ({ locals, request }) => {

let title = "";

const values = z
const parsedBody = z
.object({
fromShare: z.string().optional(),
model: validateModel(models),
assistantId: z.string().optional(),
preprompt: z.string().optional(),
})
.parse(JSON.parse(body));
.safeParse(JSON.parse(body));

if (!parsedBody.success) {
throw error(400, "Invalid request");
}
const values = parsedBody.data;

const convCount = await collections.conversations.countDocuments(authCondition(locals));

Expand All @@ -34,14 +39,13 @@ export const POST: RequestHandler = async ({ locals, request }) => {
);
}

// get preprompt from assistant if it exists

const model = models.find((m) => m.name === values.model);

if (!model) {
throw error(400, "Invalid model");
}

// get preprompt from assistant if it exists
const assistant = await collections.assistants.findOne({
_id: new ObjectId(values.assistantId),
});
Expand Down

0 comments on commit 403d4bd

Please sign in to comment.