forked from ericc-ch/copilot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
34 lines (29 loc) · 840 Bytes
/
route.ts
File metadata and controls
34 lines (29 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Hono } from "hono"
import { forwardError } from "~/lib/error"
import { state } from "~/lib/state"
import { cacheModels } from "~/lib/utils"
export const modelRoutes = new Hono()
modelRoutes.get("/", async (c) => {
try {
if (!state.models) {
// This should be handled by startup logic, but as a fallback.
await cacheModels()
}
const models = state.models?.data.map((model) => ({
id: model.id,
object: "model",
type: "model",
created: 0, // No date available from source
created_at: new Date(0).toISOString(), // No date available from source
owned_by: model.vendor,
display_name: model.name,
}))
return c.json({
object: "list",
data: models,
has_more: false,
})
} catch (error) {
return await forwardError(c, error)
}
})