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
+44
-7
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Get,
|
||||
Body,
|
||||
Res,
|
||||
HttpStatus,
|
||||
@@ -22,6 +23,12 @@ import {
|
||||
GeminiResponse,
|
||||
} from './interfaces/request-interfaces';
|
||||
import { ProxyGuard } from './proxy.guard';
|
||||
import {
|
||||
getAllDynamicModels,
|
||||
MODEL_LIST_CREATED_AT,
|
||||
MODEL_LIST_OWNER,
|
||||
} from '../../../lib/antigravity/ModelMapping';
|
||||
import { getServerConfig } from '../../server-config';
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +37,37 @@ import { ProxyGuard } from './proxy.guard';
|
||||
export class ProxyController {
|
||||
private readonly logger = new Logger(ProxyController.name);
|
||||
|
||||
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')
|
||||
async chatCompletions(@Body() body: OpenAIChatRequest, @Res() res: FastifyReply) {
|
||||
@@ -186,12 +223,12 @@ export class ProxyController {
|
||||
content:
|
||||
imageParts.length > 0
|
||||
? [
|
||||
{
|
||||
type: 'text',
|
||||
text: body.prompt ?? 'Please edit this image based on the provided instruction.',
|
||||
},
|
||||
...imageParts,
|
||||
]
|
||||
{
|
||||
type: 'text',
|
||||
text: body.prompt ?? 'Please edit this image based on the provided instruction.',
|
||||
},
|
||||
...imageParts,
|
||||
]
|
||||
: (body.prompt ?? 'Please edit this image based on the provided instruction.'),
|
||||
},
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user