-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an endpoints to expose models and conversations (#694)
* Add an endpoint to expose available models * Add a route to list conversations history * use authCondition to filter current user's conversations * map models object to only keep needed params and also change the route path to /api/models * Put API feature behind feature flag (#695) * Puts the API behind a feature flag * Update src/hooks.server.ts Co-authored-by: Eliott C. <[email protected]> --------- Co-authored-by: Eliott C. <[email protected]> * add a better error when session's cookie is missing * rename error to message to be consistent --------- Co-authored-by: Kevin CATHALY <[email protected]> Co-authored-by: Nathan Sarrazin <[email protected]> Co-authored-by: Eliott C. <[email protected]>
- Loading branch information
1 parent
41f8b74
commit c30d191
Showing
5 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { collections } from "$lib/server/database"; | ||
import { authCondition } from "$lib/server/auth"; | ||
|
||
export async function GET({ locals }) { | ||
if (locals.user?._id || locals.sessionId) { | ||
const res = await collections.conversations | ||
.find({ | ||
...authCondition(locals), | ||
}) | ||
.toArray(); | ||
|
||
return Response.json(res); | ||
} else { | ||
return Response.json({ message: "Must have session cookie" }, { status: 401 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { models } from "$lib/server/models"; | ||
|
||
export async function GET() { | ||
const res = models.map((model) => ({ | ||
id: model.id, | ||
name: model.name, | ||
websiteUrl: model.websiteUrl, | ||
modelUrl: model.modelUrl, | ||
datasetName: model.datasetName, | ||
datasetUrl: model.datasetUrl, | ||
displayName: model.displayName, | ||
description: model.description, | ||
promptExamples: model.promptExamples, | ||
preprompt: model.preprompt, | ||
multimodal: model.multimodal, | ||
unlisted: model.unlisted, | ||
})); | ||
return Response.json(res); | ||
} |