add model list endpoint (#96)
* add model list endpoint * fix: guard models list endpoint errors
This commit is contained in:
1 parent
6f8e8085ef
commit
4dc4e4e5a7
1 file changed
+37
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
Controller,
|
Controller,
|
||||||
Post,
|
Post,
|
||||||
|
Get,
|
||||||
Body,
|
Body,
|
||||||
Res,
|
Res,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
@@ -22,6 +23,12 @@ import {
|
|||||||
GeminiResponse,
|
GeminiResponse,
|
||||||
} from './interfaces/request-interfaces';
|
} from './interfaces/request-interfaces';
|
||||||
import { ProxyGuard } from './proxy.guard';
|
import { ProxyGuard } from './proxy.guard';
|
||||||
|
import {
|
||||||
|
getAllDynamicModels,
|
||||||
|
MODEL_LIST_CREATED_AT,
|
||||||
|
MODEL_LIST_OWNER,
|
||||||
|
} from '../../../lib/antigravity/ModelMapping';
|
||||||
|
import { getServerConfig } from '../../server-config';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -32,6 +39,36 @@ export class ProxyController {
|
|||||||
|
|
||||||
constructor(@Inject(ProxyService) private readonly proxyService: ProxyService) { }
|
constructor(@Inject(ProxyService) private readonly proxyService: ProxyService) { }
|
||||||
|
|
||||||
|
@Get('models')
|
||||||
|
listModels(@Res() res: FastifyReply) {
|
||||||
|
try {
|
||||||
|
const config = getServerConfig();
|
||||||
|
const customMapping = config?.custom_mapping ?? {};
|
||||||
|
const modelIds = getAllDynamicModels(customMapping);
|
||||||
|
|
||||||
|
const data = modelIds.map((id) => ({
|
||||||
|
id,
|
||||||
|
object: 'model',
|
||||||
|
created: MODEL_LIST_CREATED_AT,
|
||||||
|
owned_by: MODEL_LIST_OWNER,
|
||||||
|
}));
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).send({
|
||||||
|
object: 'list',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : 'Failed to list models';
|
||||||
|
this.logger.error(message, error instanceof Error ? error.stack : undefined);
|
||||||
|
res.status(HttpStatus.INTERNAL_SERVER_ERROR).send({
|
||||||
|
error: {
|
||||||
|
message,
|
||||||
|
type: 'server_error',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Post('chat/completions')
|
@Post('chat/completions')
|
||||||
async chatCompletions(@Body() body: OpenAIChatRequest, @Res() res: FastifyReply) {
|
async chatCompletions(@Body() body: OpenAIChatRequest, @Res() res: FastifyReply) {
|
||||||
await this.sendOpenAIChatCompletionResponse(body, res);
|
await this.sendOpenAIChatCompletionResponse(body, res);
|
||||||
|
|||||||
Reference in new issue
Block a user