Skip to content

Add inference providers details #37

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
56 changes: 55 additions & 1 deletion packages/mcp/src/model-detail.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod';
import { modelInfo } from '@huggingface/hub';
import { z } from 'zod';
import { formatDate, formatNumber } from './utilities.js';

const SPACES_TO_INCLUDE = 12;
Expand Down Expand Up @@ -58,11 +58,20 @@ interface ModelMetadata {
fineTunedFrom?: string;
}

// Inference providers information
interface InferenceProvider {
provider: string;
status?: string;
providerId?: string;
task?: string;
}

// Complete model information structure
interface ModelInformation extends ModelBasicInfo {
extended?: ModelExtendedInfo;
technical?: ModelTechnicalDetails;
metadata?: ModelMetadata;
inferenceProviders?: InferenceProvider[];
spaces?: Array<{
id: string;
name: string;
Expand All @@ -87,6 +96,7 @@ export class ModelDetailTool {
this.hubUrl = hubUrl;
}


/**
* Get detailed information about a specific model
*
Expand All @@ -106,6 +116,7 @@ export class ModelDetailTool {
'safetensors',
'cardData',
'spaces',
'inferenceProviderMapping',
] as const;

const modelData = await modelInfo<(typeof additionalFields)[number]>({
Expand All @@ -115,6 +126,18 @@ export class ModelDetailTool {
...(this.hubUrl && { hubUrl: this.hubUrl }),
});

// Extract inference providers from modelData if available
let inferenceProviders: InferenceProvider[] | undefined;

if (modelData.inferenceProviderMapping && typeof modelData.inferenceProviderMapping === 'object') {
inferenceProviders = Object.entries(modelData.inferenceProviderMapping).map(([providerName, providerData]: [string, any]) => ({
provider: providerName,
status: providerData.status,
providerId: providerData.providerId,
task: providerData.task,
}));
}

// Build the structured model information
const modelDetails: ModelInformation = {
// Basic info (required fields)
Expand All @@ -134,6 +157,9 @@ export class ModelDetailTool {
downloadsAllTime: modelData.downloadsAllTime,
tags: modelData.tags,
},

// Inference providers (if available)
...(inferenceProviders && inferenceProviders.length > 0 && { inferenceProviders }),
};

// Technical details (requires validation)
Expand Down Expand Up @@ -352,6 +378,34 @@ function formatModelDetails(model: ModelInformation): string {
r.push('');
}

// Inference Providers - if available
if (model.inferenceProviders && model.inferenceProviders.length > 0) {
r.push('## Inference Providers');
console.log('DEBUG: inferenceProviders:', model.inferenceProviders);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll move the logging utility to a shared package (amongst other build improvements) and remove the console.log when ready to merge


for (const provider of model.inferenceProviders) {
let providerLine = `- **${provider.provider}**`;

// Add status if available
if (provider.status) {
providerLine += ` (${provider.status})`;
}

// Add provider ID if available
if (provider.providerId) {
providerLine += ` | Provider ID: ${provider.providerId}`;
}

// Add task if available
if (provider.task) {
providerLine += ` | Task: ${provider.task}`;
}
Comment on lines +394 to +402
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Add provider ID if available
if (provider.providerId) {
providerLine += ` | Provider ID: ${provider.providerId}`;
}
// Add task if available
if (provider.task) {
providerLine += ` | Task: ${provider.task}`;
}

i'd remove all this

r.push(providerLine);
}

r.push('');
}

// Link is reliable - based on model name which is required
r.push(`**Link:** [https://hf.co/${model.name}](https://hf.co/${model.name})`);

Expand Down