Skip to content

Resolve mapping IDs automatically to new HF endpoint #24

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

Merged
merged 1 commit into from
Aug 15, 2025
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
28 changes: 28 additions & 0 deletions src/hf.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
interface ModelMappingItem {
_id?: string;
task: string;
hfModel: string;
providerModel: string;
status?: 'live' | 'staging';
}

interface TagFilterMappingItem {
_id?: string;
task: string;
providerModel: string;
status?: 'live' | 'staging';
Expand Down Expand Up @@ -122,6 +124,32 @@ class HFInferenceProviderClient {
);
}

async getMappingIdByHfModel(hfModel: string): Promise<string | undefined> {
const mappings = await this.listMappingItems();
for (const taskMappings of Object.values(mappings)) {
const mapping = taskMappings[hfModel];
if (mapping && mapping._id) {
return mapping._id;
}
}
return undefined;
}

async createHfModelToMappingIdMap(): Promise<Map<string, string>> {
const mappings = await this.listMappingItems();
const map = new Map<string, string>();

for (const taskMappings of Object.values(mappings)) {
for (const [hfModel, mapping] of Object.entries(taskMappings)) {
if (mapping._id) {
map.set(hfModel, mapping._id);
}
}
}

return map;
}

async getMappingsByProvider(provider: string): Promise<Record<string, Record<string, MappingItem>>> {
const url = `${this.baseUrl}/api/partners/${provider}/models`;
return this.request<Record<string, Record<string, MappingItem>>>(url, {
Expand Down
23 changes: 19 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ if (unsupportedModels.length > 0) {

// Use only supported models for mapping operations
const existingHFModelIds = await hf.listMappingIds();
// Create a lookup map for efficient mapping ID retrieval during status updates
const hfModelToMappingIdMap = await hf.createHfModelToMappingIdMap();

console.log("\n\nExisting HF model IDs:");
console.log(existingHFModelIds);
Expand All @@ -102,10 +104,23 @@ if (existingMappings.length > 0) {
console.log(`\n\nUpdating statuses for ${existingMappings.length} existing mappings:`);
for (const model of existingMappings) {
console.log(`${model.hfModel} - ${model.status}`);
await hf.updateMappingItemStatus({
hfModel: model.hfModel,
status: model.status,
});
const mappingId = hfModelToMappingIdMap.get(model.hfModel);
if (mappingId) {
try {
await hf.updateMappingItemStatus({
mappingId: mappingId,
status: model.status,
});
} catch (error) {
if (error instanceof Error && error.message.includes('does not support task')) {
console.log(`Skipping ${model.hfModel}: ${model.task} task not supported for status updates`);
} else {
throw error;
}
}
} else {
console.error(`Could not find mapping ID for ${model.hfModel}`);
}
}
} else {
console.log("\n\nNo existing mappings to update.");
Expand Down