Skip to content

Commit

Permalink
fix: uses sha512 instead of model-id
Browse files Browse the repository at this point in the history
Signed-off-by: axel7083 <[email protected]>
  • Loading branch information
axel7083 committed Sep 10, 2024
1 parent eed8f54 commit 3b81fee
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 117 deletions.
4 changes: 2 additions & 2 deletions packages/backend/src/managers/inference/inferenceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type { InferenceProviderRegistry } from '../../registries/InferenceProvid
import type { InferenceProvider } from '../../workers/provider/InferenceProvider';
import type { ModelInfo } from '@shared/src/models/IModelInfo';
import type { CatalogManager } from '../catalogManager';
import { anonymiseModel } from '../../utils/telemetry-utils';
import { getHash } from '../../utils/sha';

export class InferenceManager extends Publisher<InferenceServer[]> implements Disposable {
// Inference server map (containerId -> InferenceServer)
Expand Down Expand Up @@ -232,7 +232,7 @@ export class InferenceManager extends Publisher<InferenceServer[]> implements Di

// Log usage
this.telemetry.logUsage('inference.start', {
models: config.modelsInfo.map(model => anonymiseModel(model)),
models: config.modelsInfo.map(model => getHash(model.id)),
});

this.notify();
Expand Down
7 changes: 3 additions & 4 deletions packages/backend/src/managers/modelsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ import { Uploader } from '../utils/uploader';
import { deleteRemoteModel, getLocalModelFile, isModelUploaded } from '../utils/modelsUtils';
import { getPodmanMachineName } from '../utils/podman';
import type { CancellationTokenRegistry } from '../registries/CancellationTokenRegistry';
import { hasValidSha } from '../utils/sha';
import { getHash, hasValidSha } from '../utils/sha';
import type { GGUFParseOutput } from '@huggingface/gguf';
import { gguf } from '@huggingface/gguf';
import type { PodmanConnection } from './podmanConnection';
import { VMType } from '@shared/src/models/IPodman';
import { anonymiseModel } from '../utils/telemetry-utils';

export class ModelsManager implements Disposable {
#models: Map<string, ModelInfo>;
Expand Down Expand Up @@ -199,7 +198,7 @@ export class ModelsManager implements Disposable {
}
await fs.promises.rm(modelPath, { recursive: true, force: true, maxRetries: 3 });

this.telemetry.logUsage('model.delete', { 'model.id': anonymiseModel(model) });
this.telemetry.logUsage('model.delete', { 'model.id': getHash(modelId) });
model.file = model.state = undefined;
} catch (err: unknown) {
this.telemetry.logError('model.delete', {
Expand Down Expand Up @@ -445,7 +444,7 @@ export class ModelsManager implements Disposable {

const before = performance.now();
const data: Record<string, unknown> = {
'model-id': anonymiseModel(model), // filter imported models
'model-id': getHash(modelId),
};

try {
Expand Down
21 changes: 8 additions & 13 deletions packages/backend/src/managers/playgroundV2Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import { withDefaultConfiguration } from '../utils/inferenceUtils';
import { getRandomString } from '../utils/randomUtils';
import type { TaskRegistry } from '../registries/TaskRegistry';
import type { CancellationTokenRegistry } from '../registries/CancellationTokenRegistry';
import { anonymiseModel, IMPORTED_PLACEHOLDER } from '../utils/telemetry-utils';
import { isAbsolute } from 'node:path';
import { getHash } from '../utils/sha';

export class PlaygroundV2Manager implements Disposable {
#conversationRegistry: ConversationRegistry;
Expand All @@ -55,7 +54,7 @@ export class PlaygroundV2Manager implements Disposable {
const conversation = this.#conversationRegistry.get(conversationId);
this.telemetry.logUsage('playground.delete', {
totalMessages: conversation.messages.length,
modelId: isAbsolute(conversation.modelId) ? IMPORTED_PLACEHOLDER : conversation.modelId,
modelId: getHash(conversation.modelId),
});
this.#conversationRegistry.deleteConversation(conversationId);
}
Expand All @@ -68,7 +67,7 @@ export class PlaygroundV2Manager implements Disposable {

const telemetry: Record<string, unknown> = {
hasName: !!name,
modelId: anonymiseModel(model),
modelId: getHash(model.id),
};
this.createPlayground(name, model, trackingId)
.then((playgroundId: string) => {
Expand Down Expand Up @@ -151,12 +150,8 @@ export class PlaygroundV2Manager implements Disposable {
id: this.#conversationRegistry.getUniqueId(),
timestamp: Date.now(),
} as SystemPrompt);

const conversation = this.#conversationRegistry.get(conversationId);
if (!conversation) return;

this.telemetry.logUsage('playground.system-prompt.create', {
modelId: isAbsolute(conversation.modelId) ? IMPORTED_PLACEHOLDER : conversation.modelId,
modelId: getHash(this.#conversationRegistry.get(conversationId).modelId),
});
}

Expand All @@ -172,7 +167,7 @@ export class PlaygroundV2Manager implements Disposable {
if (content === undefined || content.length === 0) {
this.#conversationRegistry.removeMessage(conversationId, conversation.messages[0].id);
this.telemetry.logUsage('playground.system-prompt.delete', {
modelId: isAbsolute(conversation.modelId) ? IMPORTED_PLACEHOLDER : conversation.modelId,
modelId: getHash(conversation.modelId),
});
return;
}
Expand All @@ -184,7 +179,7 @@ export class PlaygroundV2Manager implements Disposable {
content,
});
this.telemetry.logUsage('playground.system-prompt.update', {
modelId: isAbsolute(conversation.modelId) ? IMPORTED_PLACEHOLDER : conversation.modelId,
modelId: getHash(conversation.modelId),
});
} else {
throw new Error('Cannot change system prompt on started conversation.');
Expand Down Expand Up @@ -233,7 +228,7 @@ export class PlaygroundV2Manager implements Disposable {
conversationId: conversationId,
...options,
promptLength: userInput.length,
modelId: anonymiseModel(modelInfo),
modelId: getHash(modelInfo.id),
};

// create an abort controller
Expand Down Expand Up @@ -318,7 +313,7 @@ export class PlaygroundV2Manager implements Disposable {
this.#conversationRegistry.completeMessage(conversationId, messageId);
this.telemetry.logUsage('playground.message.complete', {
duration: Date.now() - start,
modelId: isAbsolute(conversation.modelId) ? IMPORTED_PLACEHOLDER : conversation.modelId,
modelId: getHash(conversation.modelId),
});
}

Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/utils/sha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ export async function hasValidSha(filePath: string, expectedSha: string): Promis
const actualSha = checkSum.digest('hex');
return actualSha === expectedSha;
}

export function getHash(content: string): string {
return crypto.createHash('sha512').update(content).digest('hex');
}
68 changes: 0 additions & 68 deletions packages/backend/src/utils/telemetry-utils.spec.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/backend/src/utils/telemetry-utils.ts

This file was deleted.

0 comments on commit 3b81fee

Please sign in to comment.