File size: 1,223 Bytes
15a5288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
  }
}