Skip to content
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

feat(console): auto fill runtime if possible in online eval page #1809

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}