-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add inferencing routes #1097
Merged
Merged
Add inferencing routes #1097
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2ccc2bf
Add inferencing routes
GB27247 b7dc290
Add configs to UI
GB27247 6af7675
Add auditing and getInference
GB27247 7e7c4c8
Add testing to inferencing backend changes
GB27247 d63f7e4
Merge remote-tracking branch 'origin/main' into BAI-1161/add-settings…
GB27247 2a1ffbe
Change ModelAction path
GB27247 12347c5
Merge branch 'main' into BAI-1161/add-settings-to-inferencing
GB27247 b61f619
Revert "Merge branch 'main' into BAI-1161/add-settings-to-inferencing"
GB27247 b8a533b
Merge branch 'main' into BAI-1161/add-settings-to-inferencing
GB27247 597dc19
Fix coverage report
JR40159 3ef3db0
Add more testing
GB27247 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Document, model, Schema } from 'mongoose' | ||
|
||
import config from '../../utils/v2/config.js' | ||
|
||
// This interface stores information about the properties on the base object. | ||
// It should be used for plain object representations, e.g. for sending to the | ||
// client. | ||
export const ProcessorType = { CPU: 'cpu', ...config.inference.gpus } | ||
|
||
export type ProcessorTypeKeys = (typeof ProcessorType)[keyof typeof ProcessorType] | ||
|
||
export interface InferenceSetting { | ||
processorType: ProcessorTypeKeys | ||
memory?: number | ||
port: number | ||
} | ||
|
||
export interface InferenceInterface { | ||
modelId: string | ||
image: string | ||
tag: string | ||
|
||
description: string | ||
|
||
settings: InferenceSetting | ||
|
||
createdBy: string | ||
createdAt: Date | ||
updatedAt: Date | ||
} | ||
|
||
export type InferenceDoc = InferenceInterface & Document<any, any, InferenceInterface> | ||
|
||
const InferenceSchema = new Schema<InferenceInterface>( | ||
{ | ||
modelId: { type: String, required: true }, | ||
image: { type: String, required: true }, | ||
tag: { type: String, required: true }, | ||
|
||
description: { type: String, required: false, default: '' }, | ||
|
||
settings: { | ||
processorType: { type: String, required: true }, | ||
memory: { | ||
type: Number, | ||
required: function (this: InferenceInterface): boolean { | ||
return this.settings.processorType === ProcessorType.CPU | ||
}, | ||
validate: function (this: InferenceInterface, val: any): boolean { | ||
if (this.settings.processorType === ProcessorType.CPU && val) { | ||
return true | ||
} | ||
throw new Error(`Cannot specify memory allocation without choosing cpu as the processor type`) | ||
}, | ||
}, | ||
port: { type: Number, required: true }, | ||
}, | ||
|
||
createdBy: { type: String, required: true }, | ||
}, | ||
{ | ||
timestamps: true, | ||
collection: 'v2_model_inferences', | ||
}, | ||
) | ||
|
||
InferenceSchema.index({ modelId: 1, image: 1, tag: 1 }, { unique: true }) | ||
|
||
const InferenceModel = model<InferenceInterface>('v2_Model_Inference', InferenceSchema) | ||
|
||
export default InferenceModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
backend/src/routes/v2/model/inferencing/getInferenceService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import bodyParser from 'body-parser' | ||
import { Request, Response } from 'express' | ||
import { z } from 'zod' | ||
|
||
import { InferenceInterface } from '../../../../models/v2/Inference.js' | ||
import { getInferencesByModel } from '../../../../services/v2/inference.js' | ||
import { inferenceInterfaceSchema, registerPath } from '../../../../services/v2/specification.js' | ||
import { parse } from '../../../../utils/v2/validate.js' | ||
|
||
export const getInferenceSchema = z.object({ | ||
params: z.object({ | ||
modelId: z.string({ | ||
required_error: 'Must specify model id as param', | ||
}), | ||
}), | ||
}) | ||
|
||
registerPath({ | ||
method: 'get', | ||
path: '/api/v2/model/{modelId}/inferences', | ||
tags: ['inference'], | ||
description: 'Get all of the inferencing services associated with a model.', | ||
schema: getInferenceSchema, | ||
responses: { | ||
200: { | ||
description: 'An array of inferencing services.', | ||
content: { | ||
'application/json': { | ||
schema: z.object({ | ||
inferences: z.array(inferenceInterfaceSchema), | ||
}), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
interface GetInferenceService { | ||
inferences: Array<InferenceInterface> | ||
} | ||
|
||
export const getInferences = [ | ||
bodyParser.json(), | ||
async (req: Request, res: Response<GetInferenceService>) => { | ||
const { params } = parse(req, getInferenceSchema) | ||
|
||
const inferences = await getInferencesByModel(req.user, params.modelId) | ||
return res.json({ | ||
inferences, | ||
}) | ||
}, | ||
] |
63 changes: 63 additions & 0 deletions
63
backend/src/routes/v2/model/inferencing/postInferenceService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import bodyParser from 'body-parser' | ||
import { Request, Response } from 'express' | ||
import { z } from 'zod' | ||
|
||
import { InferenceInterface, ProcessorType } from '../../../../models/v2/Inference.js' | ||
import { createInference } from '../../../../services/v2/inference.js' | ||
import { inferenceInterfaceSchema, registerPath } from '../../../../services/v2/specification.js' | ||
import { parse } from '../../../../utils/v2/validate.js' | ||
|
||
export const postInferenceSchema = z.object({ | ||
params: z.object({ | ||
modelId: z.string({ | ||
required_error: 'Must specify model id as param', | ||
}), | ||
}), | ||
body: z.object({ | ||
image: z.string(), | ||
tag: z.string(), | ||
description: z.string(), | ||
settings: z.object({ | ||
processorType: z.nativeEnum(ProcessorType), | ||
memory: z.number().optional(), | ||
port: z.number(), | ||
}), | ||
}), | ||
}) | ||
|
||
registerPath({ | ||
method: 'post', | ||
path: '/api/v2/model/{modelId}/inference', | ||
tags: ['inference'], | ||
description: 'Create a inferencing service within Bailo', | ||
schema: postInferenceSchema, | ||
responses: { | ||
200: { | ||
description: 'The created inferencing service.', | ||
content: { | ||
'application/json': { | ||
schema: inferenceInterfaceSchema, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
interface PostInferenceService { | ||
inference: InferenceInterface | ||
} | ||
|
||
export const postInference = [ | ||
bodyParser.json(), | ||
async (req: Request, res: Response<PostInferenceService>) => { | ||
const { | ||
params: { modelId }, | ||
body, | ||
} = parse(req, postInferenceSchema) | ||
|
||
const inference = await createInference(req.user, modelId, body) | ||
return res.json({ | ||
inference, | ||
}) | ||
}, | ||
] |
63 changes: 63 additions & 0 deletions
63
backend/src/routes/v2/model/inferencing/putInferenceService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import bodyParser from 'body-parser' | ||
import { Request, Response } from 'express' | ||
import { z } from 'zod' | ||
|
||
import { InferenceInterface, ProcessorType } from '../../../../models/v2/Inference.js' | ||
import { updateInference } from '../../../../services/v2/inference.js' | ||
import { inferenceInterfaceSchema, registerPath } from '../../../../services/v2/specification.js' | ||
import { parse } from '../../../../utils/v2/validate.js' | ||
|
||
export const putInferenceSchema = z.object({ | ||
params: z.object({ | ||
modelId: z.string({ | ||
required_error: 'Must specify model id as param', | ||
}), | ||
}), | ||
body: z.object({ | ||
image: z.string(), | ||
tag: z.string(), | ||
description: z.string(), | ||
settings: z.object({ | ||
processorType: z.nativeEnum(ProcessorType), | ||
memory: z.number().optional(), | ||
port: z.number(), | ||
}), | ||
}), | ||
}) | ||
|
||
registerPath({ | ||
method: 'put', | ||
path: '/api/v2/model/{modelId}/inference', | ||
tags: ['inference'], | ||
description: 'Update a inferencing service within Bailo', | ||
schema: putInferenceSchema, | ||
responses: { | ||
200: { | ||
description: 'The created inferencing service.', | ||
content: { | ||
'application/json': { | ||
schema: inferenceInterfaceSchema, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
interface PutInferenceService { | ||
inference: InferenceInterface | ||
} | ||
|
||
export const putInference = [ | ||
bodyParser.json(), | ||
async (req: Request, res: Response<PutInferenceService>) => { | ||
const { | ||
params: { modelId }, | ||
body, | ||
} = parse(req, putInferenceSchema) | ||
|
||
const inference = await updateInference(req.user, modelId, body) | ||
return res.json({ | ||
inference, | ||
}) | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove custom Zod error