Spaces:
Running
Running
import { BaseProviderFetcher } from './base'; | |
import { ProviderEntry, TogetherModel } from './types'; | |
export class TogetherFetcher extends BaseProviderFetcher { | |
name = 'together'; | |
constructor(apiKey?: string) { | |
super('https://api.together.ai', apiKey, { | |
requestsPerMinute: 600 // Together rate limit from spec | |
}); | |
} | |
async fetchModels(): Promise<ProviderEntry[]> { | |
try { | |
const response = await this.fetchWithRetry<TogetherModel[]>( | |
`${this.baseUrl}/v1/models` | |
); | |
return response.map(model => this.mapModelToProviderEntry(model)); | |
} catch (error) { | |
console.error(`Failed to fetch Together models: ${error}`); | |
return []; | |
} | |
} | |
private mapModelToProviderEntry(model: TogetherModel): ProviderEntry { | |
const entry: ProviderEntry = { | |
provider: this.name, | |
context_length: model.context_length, | |
pricing: this.normalizePricing( | |
model.pricing.input, | |
model.pricing.output, | |
'per_million' | |
), | |
owned_by: model.organization, | |
model_type: model.type | |
}; | |
// Parse supported parameters from config if available | |
if (model.config) { | |
const configParams = this.parseConfigParameters(model.config); | |
Object.assign(entry, configParams); | |
} | |
return entry; | |
} | |
private parseConfigParameters(config: TogetherModel['config']): Partial<ProviderEntry> { | |
const result: Partial<ProviderEntry> = {}; | |
// Check for stop sequences support | |
if (config.stop && config.stop.length > 0) { | |
result.supports_stop_sequences = true; | |
} | |
return result; | |
} | |
} |