29 lines
1.0 KiB
JavaScript
29 lines
1.0 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.buildTestConnectionRouter = buildTestConnectionRouter;
|
|
const express_1 = require("express");
|
|
const config_1 = require("../config");
|
|
const http_1 = require("../utils/http");
|
|
function buildTestConnectionRouter(client) {
|
|
const router = (0, express_1.Router)();
|
|
router.post("/api/openai/test-connection", async (req, res, next) => {
|
|
try {
|
|
const body = (req.body ?? {});
|
|
const result = await client.testConnection({
|
|
apiKey: String(body.apiKey ?? process.env.OPENAI_API_KEY ?? ""),
|
|
model: String(body.model ?? config_1.DEFAULT_MODEL),
|
|
baseUrl: String(body.baseUrl ?? config_1.DEFAULT_OPENAI_BASE_URL)
|
|
});
|
|
(0, http_1.ok)(res, {
|
|
ok: true,
|
|
model: result.model,
|
|
timestamp: new Date().toISOString()
|
|
});
|
|
}
|
|
catch (error) {
|
|
next(error);
|
|
}
|
|
});
|
|
return router;
|
|
}
|