diff --git a/frontend/src/api/k8s/inferenceServices.ts b/frontend/src/api/k8s/inferenceServices.ts index fded27ccbc..0a5c4a8ca4 100644 --- a/frontend/src/api/k8s/inferenceServices.ts +++ b/frontend/src/api/k8s/inferenceServices.ts @@ -15,7 +15,7 @@ import { ContainerResources } from '~/types'; import { AcceleratorProfileFormData } from '~/utilities/useAcceleratorProfileFormState'; import { AcceleratorProfileState } from '~/utilities/useReadAcceleratorState'; import { getModelServingProjects } from './projects'; -import { assemblePodSpecOptions } from './utils'; +import { assemblePodSpecOptions, parseCommandLine } from './utils'; export const assembleInferenceService = ( data: CreatingInferenceServiceObject, @@ -45,6 +45,8 @@ export const assembleInferenceService = ( const dataConnectionKey = secretKey || dataConnection; const nonEmptyArgs = servingRuntimeArgs?.filter(Boolean) || []; + // Ensure that we properly handle separating args + const splitArgs: string[] = nonEmptyArgs.flatMap(parseCommandLine); const nonEmptyEnvVars = servingRuntimeEnvVars?.filter((ev) => ev.name) || []; const updateInferenceService: InferenceServiceKind = inferenceService @@ -87,7 +89,7 @@ export const assembleInferenceService = ( path, }, }), - args: nonEmptyArgs, + args: splitArgs, env: nonEmptyEnvVars, }, }, @@ -135,7 +137,7 @@ export const assembleInferenceService = ( path, }, }), - args: nonEmptyArgs, + args: splitArgs, env: nonEmptyEnvVars, }, }, diff --git a/frontend/src/api/k8s/utils.ts b/frontend/src/api/k8s/utils.ts index 2399f3eca8..caec06914d 100644 --- a/frontend/src/api/k8s/utils.ts +++ b/frontend/src/api/k8s/utils.ts @@ -74,3 +74,24 @@ export const getshmVolume = (sizeLimit?: string): Volume => ({ name: 'shm', emptyDir: { medium: 'Memory', ...(sizeLimit && { sizeLimit }) }, }); + +export const parseCommandLine = (input: string): string[] => { + const args: string[] = []; + const regex = /(?:[^\s"']+|"[^"]*"|'[^']*')+/g; + let match: RegExpExecArray | null; + + while ((match = regex.exec(input)) !== null) { + let arg: string = match[0]; + + // Remove surrounding quotes if any + if (arg.startsWith('"') && arg.endsWith('"')) { + arg = arg.slice(1, -1).replace(/\\"/g, '"'); // Unescape double quotes + } else if (arg.startsWith("'") && arg.endsWith("'")) { + arg = arg.slice(1, -1); // Remove single quotes + } + + args.push(arg); + } + + return args; +};