Skip to content

Commit dd7a81b

Browse files
committed
feat: add model routes to server
1 parent 1e67ecf commit dd7a81b

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/routes/models/route.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import consola from "consola"
2+
import { Hono } from "hono"
3+
import { FetchError } from "ofetch"
4+
5+
import { getModels } from "~/services/copilot/get-models/service"
6+
7+
export const modelRoutes = new Hono()
8+
9+
modelRoutes.get("/models", async (c) => {
10+
try {
11+
const models = await getModels()
12+
return c.json(models)
13+
} catch (error) {
14+
if (error instanceof FetchError) {
15+
consola.error(`Request failed: ${error.message}`, error.response?._data)
16+
}
17+
throw error
18+
}
19+
})

src/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { cors } from "hono/cors"
33
import { logger } from "hono/logger"
44

55
import { chatCompletionsRoutes } from "./routes/chat-completions/route"
6+
import { modelRoutes } from "./routes/models/route"
67

78
export const server = new Hono()
89

@@ -11,3 +12,4 @@ server.use(cors())
1112

1213
server.get("/", (c) => c.text("Server running"))
1314
server.route("/", chatCompletionsRoutes)
15+
server.route("/", modelRoutes)

0 commit comments

Comments
 (0)