Spaces:
Running
Running
import { BaseProviderFetcher } from "./base"; | |
import { ProviderEntry, SambaNovaModel } from "./types"; | |
export class SambaNovaFetcher extends BaseProviderFetcher { | |
name = "sambanova"; | |
constructor(apiKey?: string) { | |
super("https://api.sambanova.ai", apiKey, { | |
requestsPerMinute: 60, // Conservative default | |
}); | |
} | |
async fetchModels(): Promise<ProviderEntry[]> { | |
try { | |
const response = await this.fetchWithRetry<{ data: SambaNovaModel[] }>( | |
`${this.baseUrl}/v1/models` | |
); | |
return response.data.map((model) => this.mapModelToProviderEntry(model)); | |
} catch (error) { | |
console.error(`Failed to fetch SambaNova models: ${error}`); | |
return []; | |
} | |
} | |
private mapModelToProviderEntry(model: SambaNovaModel): ProviderEntry { | |
const entry: ProviderEntry = { | |
provider: this.name, | |
context_length: model.context_length, | |
max_completion_tokens: model.max_completion_tokens, | |
pricing: this.normalizePricing( | |
model.pricing.prompt, | |
model.pricing.completion, | |
"per_token" | |
), | |
owned_by: model.owned_by, | |
}; | |
// Store the model ID for matching | |
(entry as any).id = model.id; | |
return entry; | |
} | |
} | |