Skip to content

Commit

Permalink
revert(inference): additional changes
Browse files Browse the repository at this point in the history
Signed-off-by: axel7083 <[email protected]>
  • Loading branch information
axel7083 committed Mar 8, 2024
1 parent 2f678cc commit c758db3
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 131 deletions.
18 changes: 12 additions & 6 deletions packages/backend/src/managers/inference/inferenceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ import {
import { Publisher } from '../../utils/Publisher';
import { MSG_INFERENCE_SERVERS_UPDATE } from '@shared/Messages';
import type { InferenceServerConfig } from '@shared/src/models/InferenceServerConfig';
import type { Manager } from '../../utils/IManager';
import type { ModelsManager } from '../modelsManager';

export class InferenceManager extends Publisher<InferenceServer[]> implements Manager {
export class InferenceManager extends Publisher<InferenceServer[]> implements Disposable {
// Inference server map (containerId -> InferenceServer)
#servers: Map<string, InferenceServer>;
// Is initialized
Expand All @@ -59,22 +58,29 @@ export class InferenceManager extends Publisher<InferenceServer[]> implements Ma
this.#initialized = false;
}

init(): Disposable {
init(): void {
this.podmanConnection.onMachineStart(this.watchMachineEvent.bind(this, 'start'));
this.podmanConnection.onMachineStop(this.watchMachineEvent.bind(this, 'stop'));
const onStartContainerEventDisposable = this.containerRegistry.onStartContainerEvent(
this.containerRegistry.onStartContainerEvent(
this.watchContainerStart.bind(this),
);

this.retryableRefresh(3);

return Disposable.from(onStartContainerEventDisposable, this.cleanDisposables.bind(this));
}

public isInitialize(): boolean {
return this.#initialized;
}

/**
* Cleanup the manager
*/
dispose(): void {
this.cleanDisposables();
this.#servers.clear();
this.#initialized = false;
}

/**
* Clean class disposables
*/
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/studio-api-impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import userContent from './ai-user-test.json';
import type { ApplicationManager } from './managers/applicationManager';
import { StudioApiImpl } from './studio-api-impl';
import type { PlayGroundManager } from './managers/playground';
import type { InferenceManager } from './managers/inference/inferenceManager';
import type { TelemetryLogger, Webview } from '@podman-desktop/api';
import { EventEmitter } from '@podman-desktop/api';
import { CatalogManager } from './managers/catalogManager';
Expand Down Expand Up @@ -104,7 +103,6 @@ beforeEach(async () => {
{} as TelemetryLogger,
{} as LocalRepositoryRegistry,
{} as unknown as TaskRegistry,
{} as unknown as InferenceManager,
);
vi.mock('node:fs');

Expand Down
27 changes: 0 additions & 27 deletions packages/backend/src/studio-api-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ import type { TaskRegistry } from './registries/TaskRegistry';
import type { LocalRepository } from '@shared/src/models/ILocalRepository';
import type { LocalRepositoryRegistry } from './registries/LocalRepositoryRegistry';
import path from 'node:path';
import type { InferenceServer } from '@shared/src/models/IInference';
import type { InferenceServerConfig } from '@shared/src/models/InferenceServerConfig';
import type { InferenceManager } from './managers/inference/inferenceManager';

export class StudioApiImpl implements StudioAPI {
constructor(
Expand All @@ -46,32 +43,8 @@ export class StudioApiImpl implements StudioAPI {
private telemetry: podmanDesktopApi.TelemetryLogger,
private localRepositories: LocalRepositoryRegistry,
private taskRegistry: TaskRegistry,
private inferenceManager: InferenceManager,
) {}

async getInferenceServer(): Promise<InferenceServer[]> {
return this.inferenceManager.getServers();
}

// idea: creating a LogRegistry, and return a LogId
// so the front can listen on it to see logs;
createInferenceServer(config: InferenceServerConfig): Promise<void> {
try {
return this.inferenceManager.createInferenceServer(config);
} catch (err: unknown) {
console.error('Something went wrong while trying to start inference server', err);
throw err;
}
}

startInferenceServer(containerId: string): Promise<void> {
return this.inferenceManager.startInferenceServer(containerId);
}

stopInferenceServer(containerId: string): Promise<void> {
return this.inferenceManager.stopInferenceServer(containerId);
}

async ping(): Promise<string> {
return 'pong';
}
Expand Down
17 changes: 0 additions & 17 deletions packages/backend/src/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import fs from 'node:fs';
import { ContainerRegistry } from './registries/ContainerRegistry';
import { PodmanConnection } from './managers/podmanConnection';
import { LocalRepositoryRegistry } from './registries/LocalRepositoryRegistry';
import { InferenceManager } from './managers/inference/inferenceManager';

// TODO: Need to be configured
export const AI_STUDIO_FOLDER = path.join('podman-desktop', 'ai-studio');
Expand All @@ -55,8 +54,6 @@ export class Studio {
modelsManager: ModelsManager;
telemetry: TelemetryLogger;

#inferenceManager: InferenceManager;

constructor(readonly extensionContext: ExtensionContext) {
this.#extensionContext = extensionContext;
}
Expand Down Expand Up @@ -150,20 +147,7 @@ export class Studio {
localRepositoryRegistry,
);

this.#inferenceManager = new InferenceManager(
this.#panel.webview,
containerRegistry,
podmanConnection,
this.modelsManager,
this.telemetry,
);

this.#panel.onDidChangeViewState((e: WebviewPanelOnDidChangeViewStateEvent) => {
// Lazily init inference manager
if (!this.#inferenceManager.isInitialize()) {
this.#extensionContext.subscriptions.push(this.#inferenceManager.init());
}

this.telemetry.logUsage(e.webviewPanel.visible ? 'opened' : 'closed');
});

Expand All @@ -176,7 +160,6 @@ export class Studio {
this.telemetry,
localRepositoryRegistry,
taskRegistry,
this.#inferenceManager,
);

this.catalogManager.init();
Expand Down
22 changes: 0 additions & 22 deletions packages/backend/src/utils/IManager.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/frontend/src/stores/inferenceServers.ts

This file was deleted.

25 changes: 0 additions & 25 deletions packages/shared/src/StudioAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import type { TelemetryTrustedValue } from '@podman-desktop/api';
import type { ApplicationState } from './models/IApplicationState';
import type { Task } from './models/ITask';
import type { LocalRepository } from './models/ILocalRepository';
import type { InferenceServer } from './models/IInference';
import type { InferenceServerConfig } from './models/InferenceServerConfig';

export abstract class StudioAPI {
abstract ping(): Promise<string>;
Expand Down Expand Up @@ -73,27 +71,4 @@ export abstract class StudioAPI {
* @param modelId the id of the model we want to download
*/
abstract downloadModel(modelId: string): Promise<void>;

/**
* Get inference servers
*/
abstract getInferenceServer(): Promise<InferenceServer[]>;

/**
* Start an inference server
* @param config The configuration to use
*/
abstract createInferenceServer(config: InferenceServerConfig): Promise<void>;

/**
* Start an inference server
* @param containerId the container id of the inference server
*/
abstract startInferenceServer(containerId: string): Promise<void>;

/**
* Stop an inference server
* @param containerId the container id of the inference server
*/
abstract stopInferenceServer(containerId: string): Promise<void>;
}
5 changes: 0 additions & 5 deletions packages/shared/src/models/IInference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,4 @@ export interface InferenceServer {
* Exit code
*/
exit?: number;
/**
* Logs
* @deprecated
*/
logs?: string[];
}

0 comments on commit c758db3

Please sign in to comment.