Skip to content
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
6 changes: 5 additions & 1 deletion src/api/providers/BaseOpenAIProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,11 @@ export class BaseOpenAIProvider
* @protected
*/
protected jsonToModel(m: unknown): InferenceApiModel {
return m as InferenceApiModel;
const model = m as InferenceApiModel;
return {
...model,
name: model.name || model.id,
};
}

/**
Expand Down
16 changes: 1 addition & 15 deletions src/api/providers/GroqProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,7 @@ export class GroqProvider extends CloudOpenAIProvider {
return new GroqProvider(baseUrl, apiKey);
}

/**
* Converts a raw Grok model response object into a standardized InferenceApiModel.
*
* This method transforms the Grok-specific model response format into the common
* {@link InferenceApiModel} interface used across all providers. The model name
* is formatted as "{owned_by}: {id}" for better user readability and organization
* context.
*
* @param m - The raw model object received from the Grok API.
* @returns A standardized InferenceApiModel object with id, name, and created fields.
*
* @internal
* @override
* @inheritdoc
*/
/** @inheritdoc */
protected jsonToModel(m: unknown): InferenceApiModel {
const model = m as GroqModel;

Expand Down
69 changes: 69 additions & 0 deletions src/api/providers/NvidiaNimProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { InferenceApiModel } from '../../types';
import { CloudOpenAIProvider } from './BaseOpenAIProvider';

/**
* Represents a model available on the NVIDIA NIM API.
*
* This interface mirrors the structure of models returned by NVIDIA's OpenAI-compatible API endpoint.
*/
interface NvidiaModel {
id: string;
object: string;
created: number;
owned_by: string;
root: string;
parent: string;
max_model_len: number;
permission: Permission[];
}
export interface Permission {
id: string;
object: string;
created: number;
allow_create_engine: boolean;
allow_sampling: boolean;
allow_logprobs: boolean;
allow_search_indices: boolean;
allow_view: boolean;
allow_fine_tuning: boolean;
organization: string;
group: string;
is_blocking: boolean;
}

/**
* NVIDIA NIM provider implementation for the OpenAI-compatible API.
*
* Extends {@link CloudOpenAIProvider} to handle NVIDIA's model format and API endpoints.
* Automatically converts NVIDIA model responses into the standard {@link InferenceApiModel} format.
*
* @see https://docs.nvidia.com/nim/large-language-models/latest/api-reference.html
*
* @example
* const nvidiaProvider = NvidiaProvider.new('https://integrate.api.nvidia.com', 'your-api-key');();
*/
export class NvidiaNimProvider extends CloudOpenAIProvider {
/**
* Creates a new instance of the NVIDIA provider.
*
* @param baseUrl - Optional base URL for the NVIDIA API endpoint.
* Defaults to the standard NVIDIA OpenAI-compatible endpoint if not provided.
* @param apiKey - API key for authentication with NVIDIA's service.
* Must be provided unless using a different auth mechanism.
* @returns A new configured `NvidiaProvider` instance.
*/
static new(baseUrl?: string, apiKey: string = ''): NvidiaNimProvider {
return new NvidiaNimProvider(baseUrl, apiKey);
}

/** @inheritdoc */
protected jsonToModel(m: unknown): InferenceApiModel {
const model = m as NvidiaModel;

return {
id: model.id,
name: model.id,
created: model.created,
};
}
}
11 changes: 1 addition & 10 deletions src/api/providers/OpenRouterProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,7 @@ export class OpenRouterProvider extends CloudOpenAIProvider {
return true;
}

/**
* Converts raw OpenRouter API model data into the standardized `InferenceApiModel` format.
*
* This method safely extracts and maps model metadata from the OpenRouter response schema
* to the application's internal model representation.
*
* @param m - Raw model data received from OpenRouter API (unknown type for safety)
* @returns A normalized `InferenceApiModel` object with id, name, created, description, and modalities
* @throws Will throw if `m` is not a valid OpenRouterModel or required fields are missing
*/
/** @inheritdoc */
protected jsonToModel(m: unknown): InferenceApiModel {
const model = m as OpenRouterModel;
return {
Expand Down
4 changes: 4 additions & 0 deletions src/api/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GoogleProvider } from './GoogleProvider';
import { GroqProvider } from './GroqProvider';
import { LlamaCppProvider } from './LlamaCppProvider';
import { MistralProvider } from './MistralProvider';
import { NvidiaNimProvider } from './NvidiaNimProvider';
import { OpenRouterProvider } from './OpenRouterProvider';

const PROVIDER_CACHE = new Map<string, InferenceProvider>();
Expand Down Expand Up @@ -40,6 +41,9 @@ export function getInferenceProvider(
case 'mistral':
provider = MistralProvider.new(baseUrl, apiKey);
break;
case 'nvidia':
provider = NvidiaNimProvider.new(baseUrl, apiKey);
break;
default:
provider = BaseOpenAIProvider.new(baseUrl, apiKey);
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/inference-providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
},
"nvidia": {
"baseUrl": "https://integrate.api.nvidia.com",
"name": "Nvidia",
"name": "Nvidia NIM",
"icon": "assets/providers/nvidia.svg",
"allowCustomBaseUrl": false,
"isKeyRequired": true
Expand Down
Loading