Skip to content

Commit 31761e7

Browse files
authored
Merge pull request #11 from replicate/add-script-to-list-provider-mappings
add script to list provider mappings
2 parents 1411409 + a03eb45 commit 31761e7

File tree

5 files changed

+101
-11
lines changed

5 files changed

+101
-11
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,52 @@ But if you need to run the sync manually, here's how:
6262
npm install
6363
npm start
6464
```
65+
66+
## Listing Provider Mappings
67+
68+
This repo includes scripts to list available providers and their model mappings.
69+
70+
### List Available Providers
71+
72+
To see all available inference providers:
73+
74+
```bash
75+
npm run list-providers
76+
```
77+
78+
This will output a JSON array of provider IDs, like:
79+
```json
80+
[
81+
"cerebras",
82+
"cohere",
83+
"fal-ai",
84+
"fireworks",
85+
"hyperbolic",
86+
"hf-inference",
87+
"nebius",
88+
"novita",
89+
"replicate",
90+
"sambanova",
91+
"together"
92+
]
93+
```
94+
95+
### List Provider Mappings
96+
97+
To see the model mappings for a specific provider:
98+
99+
```bash
100+
npm run list-provider-mappings -- <provider-id>
101+
```
102+
103+
For example, to see Replicate's mappings:
104+
```bash
105+
npm run list-provider-mappings -- replicate
106+
```
107+
108+
This will output a JSON object containing all model mappings for the specified provider, organized by task type.
109+
110+
Note: You'll need to set the `HF_TOKEN` environment variable to use these scripts:
111+
```bash
112+
export HF_TOKEN=<your-huggingface-token>
113+
```

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"start": "tsx src/index.ts"
7+
"start": "tsx src/index.ts",
8+
"list-providers": "tsx script/list-providers.ts",
9+
"list-provider-mappings": "tsx script/list-provider-mappings.ts"
810
},
911
"dependencies": {
12+
"@huggingface/inference": "^2.6.4",
1013
"typescript": "^5.4.2"
1114
},
1215
"devDependencies": {

script/list-provider-mappings.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import HFInferenceProviderClient from '../src/hf.js';
2+
3+
const provider = process.argv[2];
4+
5+
if (!provider) {
6+
console.error('Please provide a provider ID as an argument');
7+
console.error('Usage: npm run list-provider-mappings -- <provider-id>');
8+
process.exit(1);
9+
}
10+
11+
const hf = new HFInferenceProviderClient();
12+
13+
const listProviderMappings = async () => {
14+
console.log(`\nFetching mappings for provider: ${provider}`);
15+
try {
16+
const mappings = await hf.getMappingsByProvider(provider);
17+
console.log(JSON.stringify(mappings, null, 2));
18+
} catch (error) {
19+
console.error(`Error fetching mappings for ${provider}:`, error);
20+
process.exit(1);
21+
}
22+
};
23+
24+
await listProviderMappings();

script/list-providers.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const providers = [
2+
'cerebras',
3+
'cohere',
4+
'fal-ai',
5+
'fireworks',
6+
'hyperbolic',
7+
'hf-inference',
8+
'nebius',
9+
'novita',
10+
'replicate',
11+
'sambanova',
12+
'together'
13+
] as const;
14+
15+
console.log(JSON.stringify(providers, null, 2));

src/hf.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,17 @@ class HFInferenceProviderClient {
117117

118118
async listMappingIds(): Promise<string[]> {
119119
const mappings = await this.listMappingItems();
120-
121-
const ids = [];
122-
123-
for (const [_taskType, models] of Object.entries(mappings)) {
124-
for (const [modelId, _model] of Object.entries(models)) {
125-
ids.push(modelId);
126-
}
127-
}
128-
129-
return ids;
120+
return Object.values(mappings).flatMap(taskMappings =>
121+
Object.keys(taskMappings)
122+
);
130123
}
131124

125+
async getMappingsByProvider(provider: string): Promise<Record<string, Record<string, MappingItem>>> {
126+
const url = `${this.baseUrl}/api/partners/${provider}/models`;
127+
return this.request<Record<string, Record<string, MappingItem>>>(url, {
128+
method: 'GET'
129+
});
130+
}
132131
}
133132

134133
export default HFInferenceProviderClient;

0 commit comments

Comments
 (0)