Skip to content

Commit

Permalink
feat(console): auto fill runtime if possible in online eval page
Browse files Browse the repository at this point in the history
  • Loading branch information
jialeicui committed Feb 9, 2023
1 parent 57e6cac commit f6ce234
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
13 changes: 12 additions & 1 deletion console/src/domain/model/components/CreateOnlineEvalForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from 'react'
import React, { useCallback, useEffect, useState } from 'react'
import useTranslation from '@/hooks/useTranslation'
import { createForm } from '@/components/Form'
import RuntimeSelector from '@runtime/components/RuntimeSelector'
Expand All @@ -12,6 +12,7 @@ import { createUseStyles } from 'react-jss'
import FlatResourceSelector, { Dict } from '@/domain/setting/components/FlatResourceSelector'
import { ISystemResourcePool } from '@/domain/setting/schemas/system'
import { Toggle } from '@starwhale/ui/Select'
import { useFetchRuntimeVersionSuggestion } from '@runtime/hooks/useFetchRuntimeVersionSuggestion'

interface ICreateOnlineEvalProps {
modelId: string
Expand Down Expand Up @@ -59,6 +60,16 @@ function CreateOnlineEvalForm({ onSubmit }: ICreateOnlineEvalFormProps, formRef:
const [resourcePool, setResourcePool] = React.useState<ISystemResourcePool | undefined>()
const [showAdvanced, setShowAdvanced] = useState(false)

// get runtime suggestion
const runtimes = useFetchRuntimeVersionSuggestion(projectId, $modelVersionId).data?.runtimes
useEffect(() => {
if (runtimes !== undefined && runtimes?.length !== 0) {
const { id, runtimeId: $runtimeId } = runtimes[0]
form.setFieldsValue({ runtimeId: $runtimeId, runtimeVersionUrl: id })
setRuntimeId($runtimeId)
}
}, [form, runtimes])

const handleValuesChange = useCallback(
(changes, values) => {
if (values.modelId) setModelId(values.modelId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useQuery } from 'react-query'
import { fetchRuntimeVersionSuggestion } from '../services/runtimeVersion'

export function useFetchRuntimeVersionSuggestion(projectId: string, modelId: string) {
return useQuery(
['fetchRuntimeVersionSuggestion', projectId, modelId],
() => fetchRuntimeVersionSuggestion(projectId, modelId),
{
refetchOnWindowFocus: false,
}
)
}
5 changes: 5 additions & 0 deletions console/src/domain/runtime/schemas/runtimeVersion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IRuntimeVersionSchema extends IResourceSchema {
owner?: IUserSchema
alias: string
image: string
runtimeId: string
}

export interface IRuntimeVersionListSchema extends IResourceSchema {
Expand Down Expand Up @@ -36,3 +37,7 @@ export interface IRuntimeVersionListQuerySchema extends IListQuerySchema {
vName?: string
vTag?: string
}

export interface IRuntimeVersionSuggestionSchema {
runtimes: IRuntimeVersionSchema[]
}
11 changes: 11 additions & 0 deletions console/src/domain/runtime/services/runtimeVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IUpdateRuntimeVersionSchema,
IRuntimeVersionDetailSchema,
IRuntimeVersionListQuerySchema,
IRuntimeVersionSuggestionSchema,
} from '../schemas/runtimeVersion'

export async function listRuntimeVersions(
Expand Down Expand Up @@ -70,3 +71,13 @@ export async function recoverRuntimeVersion(
)
return resp.data
}

export async function fetchRuntimeVersionSuggestion(
projectId: string,
modelVersionId: string
): Promise<IRuntimeVersionSuggestionSchema> {
const { data } = await axios.get<IRuntimeVersionSuggestionSchema>('/api/v1/job/suggestion/runtime', {
params: { projectId, modelVersionId },
})
return data
}

0 comments on commit f6ce234

Please sign in to comment.