-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Expand file tree
/
Copy pathmodels.ts
More file actions
70 lines (64 loc) · 1.98 KB
/
models.ts
File metadata and controls
70 lines (64 loc) · 1.98 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { CoreSetup, IRouter, Logger } from '@kbn/core/server';
import type { ElasticConsolePluginStart, ElasticConsoleStartDependencies } from '../types';
import { isElasticConsoleEnabled } from './is_enabled';
export const registerModelsRoute = ({
router,
coreSetup,
logger,
}: {
router: IRouter;
coreSetup: CoreSetup<ElasticConsoleStartDependencies, ElasticConsolePluginStart>;
logger: Logger;
}) => {
router.get(
{
path: '/internal/elastic_ramen/v1/models',
security: {
authz: { enabled: false, reason: 'This route delegates to the inference plugin' },
},
options: {
access: 'internal',
},
validate: {},
},
async (ctx, request, response) => {
try {
const [coreStart, { inference }] = await coreSetup.getStartServices();
if (!(await isElasticConsoleEnabled(coreStart, request))) {
return response.notFound();
}
const connectors = await inference.getConnectorList(request);
const models = connectors.map((connector) => ({
id: connector.connectorId,
object: 'model',
created: Math.floor(Date.now() / 1000),
owned_by: connector.type,
permission: [],
root: connector.connectorId,
parent: null,
context_window_size: connector.capabilities.contextWindowSize,
}));
return response.ok({
body: {
object: 'list',
data: models,
},
});
} catch (error) {
logger.error(`Models listing error: ${error.message}`);
return response.customError({
statusCode: 500,
body: {
message: error.message,
},
});
}
}
);
};