forked from containers/podman-desktop-extension-ai-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show warning if no machine is running or there are not enough r…
…esources (containers#227) Signed-off-by: lstocchi <lstocchi@redhat.com>
- Loading branch information
Showing
7 changed files
with
275 additions
and
1 deletion.
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
94 changes: 94 additions & 0 deletions
94
packages/frontend/src/lib/notification/ContainerConnectionStatusInfo.svelte
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,94 @@ | ||
<script lang="ts"> | ||
import Fa from 'svelte-fa'; | ||
import { faCircleExclamation } from '@fortawesome/free-solid-svg-icons'; | ||
import Button from '../button/Button.svelte'; | ||
import { filesize } from 'filesize'; | ||
import { studioClient } from '/@/utils/client'; | ||
import type { ContainerConnectionInfo } from '@shared/src/models/IContainerConnectionInfo'; | ||
export let connectionInfo: ContainerConnectionInfo; | ||
type BannerBackgroundColor = 'light' | 'dark'; | ||
export let background: BannerBackgroundColor = 'light'; | ||
let title: string | undefined = ''; | ||
let description: string | undefined = ''; | ||
let actionName: string | undefined = ''; | ||
$: updateTitleDescription(connectionInfo); | ||
function updateTitleDescription(connectionInfo: ContainerConnectionInfo) { | ||
if (connectionInfo.status === 'no-machine') { | ||
title = 'No Podman machine is running'; | ||
description = 'Please start a Podman Machine before proceeding further.'; | ||
actionName = 'Start now'; | ||
return; | ||
} | ||
if (connectionInfo.status === 'not-enough-resources') { | ||
title = 'Upgrade your Podman machine for best AI performance'; | ||
const hasEnoughCPU = connectionInfo.cpus >= connectionInfo.cpusExpected; | ||
const hasEnoughMemory = connectionInfo.memoryIdle > connectionInfo.memoryExpected; | ||
let machineCurrentStateDescription = ''; | ||
let machinePreferredStateDescription = ''; | ||
if (hasEnoughCPU) { | ||
machineCurrentStateDescription += `${connectionInfo.cpus} vCPUs`; | ||
machinePreferredStateDescription += `${connectionInfo.cpusExpected} vCPUs`; | ||
if (!hasEnoughMemory) { | ||
machineCurrentStateDescription += ` and ${filesize(connectionInfo.memoryIdle, { base: 2 })} of memory available`; | ||
machinePreferredStateDescription += ` and ${filesize(connectionInfo.memoryExpected, { base: 2 })} of memory`; | ||
} | ||
} else { | ||
machineCurrentStateDescription += `${filesize(connectionInfo.memoryIdle, { base: 2 })} of memory available`; | ||
machinePreferredStateDescription += `${filesize(connectionInfo.memoryExpected, { base: 2 })} of memory`; | ||
} | ||
const machineName = `${connectionInfo.name.includes('Podman Machine') ? connectionInfo.name : `Podman Machine ${connectionInfo.name}`}`; | ||
description = `Your ${machineName} has ${machineCurrentStateDescription}.`; | ||
if (connectionInfo?.canEdit) { | ||
description += `We recommend upgrading your Podman machine with at least ${machinePreferredStateDescription} for better AI performance.`; | ||
actionName = 'Upgrade now'; | ||
} else { | ||
description += `We recommend freeing some resources on your Podman machine to have at least ${machinePreferredStateDescription} for better AI performance.`; | ||
} | ||
return; | ||
} | ||
title = undefined; | ||
description = undefined; | ||
actionName = undefined; | ||
} | ||
function executeCommand() { | ||
if (connectionInfo.status === 'not-enough-resources' && connectionInfo.canEdit) { | ||
studioClient.navigateToEditConnectionProvider(connectionInfo.name); | ||
return; | ||
} | ||
if (connectionInfo.status == 'no-machine') { | ||
studioClient.navigateToResources(); | ||
} | ||
} | ||
</script> | ||
|
||
{#if title && description} | ||
<div | ||
class="w-full {background === 'light' | ||
? 'bg-charcoal-500' | ||
: 'bg-charcoal-800'} border-t-[3px] border-red-700 p-4 mt-5 shadow-inner"> | ||
<div class="flex flex-row space-x-3"> | ||
<div class="flex"> | ||
<Fa icon="{faCircleExclamation}" class="text-red-600" /> | ||
</div> | ||
<div class="flex flex-col grow"> | ||
<span class="font-medium text-sm">{title}</span> | ||
<span class="text-sm">{description}</span> | ||
</div> | ||
{#if actionName} | ||
<div class="flex items-center"> | ||
<Button class="grow text-gray-500" on:click="{executeCommand}">{actionName}</Button> | ||
</div> | ||
{/if} | ||
</div> | ||
</div> | ||
{/if} |
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,37 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import type { ModelInfo } from '@shared/src/models/IModelInfo'; | ||
import { studioClient } from './client'; | ||
import type { ContainerConnectionInfo } from '@shared/src/models/IContainerConnectionInfo'; | ||
|
||
export async function checkContainerConnectionStatus( | ||
localModels: ModelInfo[], | ||
modelId: string, | ||
): Promise<ContainerConnectionInfo | undefined> { | ||
const model: ModelInfo | undefined = localModels.find(model => model.id === modelId); | ||
let connection: ContainerConnectionInfo | undefined; | ||
if (model) { | ||
try { | ||
connection = await studioClient.checkContainerConnectionStatusAndResources(model.memory); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
return connection; | ||
} |
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,43 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
export type ContainerConnectionInfo = | ||
| RunningContainerConnection | ||
| NotEnoughResourcesContainerConnection | ||
| NoContainerConnection; | ||
|
||
export type ContainerConnectionInfoStatus = 'running' | 'no-machine' | 'not-enough-resources'; | ||
|
||
export interface RunningContainerConnection { | ||
name: string; | ||
status: 'running'; | ||
} | ||
|
||
export interface NotEnoughResourcesContainerConnection { | ||
name: string; | ||
cpus: number; | ||
memoryIdle: number; | ||
cpusExpected: number; | ||
memoryExpected: number; | ||
status: 'not-enough-resources'; | ||
canEdit: boolean; | ||
} | ||
|
||
export interface NoContainerConnection { | ||
status: 'no-machine'; | ||
} |