Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
20 changes: 11 additions & 9 deletions apps/gateway/src/chat-json.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import {
logMode,
} from "@/chat-helpers.e2e.js";

import {
type ModelDefinition,
models,
type ProviderModelMapping,
} from "@llmgateway/models";
import type { ProviderModelMapping } from "@llmgateway/models";

describe("e2e", getConcurrentTestOptions(), () => {
beforeAll(beforeAllHook);
Expand All @@ -28,8 +24,10 @@ describe("e2e", getConcurrentTestOptions(), () => {

test.each(
testModels.filter((m) => {
const modelDef = models.find((mo) => m.originalModel === mo.id);
return (modelDef as ModelDefinition)?.jsonOutput === true;
// Check if any provider for this model supports jsonOutput
return m.providers.some(
(provider) => (provider as ProviderModelMapping).jsonOutput === true,
);
}),
)("JSON output $model", getTestOptions(), async ({ model }) => {
const res = await app.request("/v1/chat/completions", {
Expand Down Expand Up @@ -73,8 +71,12 @@ describe("e2e", getConcurrentTestOptions(), () => {

test.each(
testModels.filter((m) => {
const modelDef = models.find((mo) => m.originalModel === mo.id);
if ((modelDef as ModelDefinition)?.jsonOutput !== true) {
// Check if any provider for this model supports jsonOutput
if (
!m.providers.some(
(provider) => (provider as ProviderModelMapping).jsonOutput === true,
)
) {
return false;
}
// Check if the specific provider(s) for this test case support jsonOutputSchema
Expand Down
18 changes: 15 additions & 3 deletions apps/gateway/src/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ chat.openapi(completions, async (c) => {
maxOutput: 4096,
streaming: true,
vision: false,
jsonOutput: true,
},
],
jsonOutput: true,
};
} else {
modelInfo =
Expand All @@ -559,7 +559,19 @@ chat.openapi(completions, async (c) => {
response_format?.type === "json_object" ||
response_format?.type === "json_schema"
) {
if (!(modelInfo as ModelDefinition).jsonOutput) {
// Filter providers by requestedProvider if specified
const providersToCheck = requestedProvider
? modelInfo.providers.filter(
(p) => (p as ProviderModelMapping).providerId === requestedProvider,
)
: modelInfo.providers;

// Check if the provider(s) support JSON output
const supportsJsonOutput = providersToCheck.some(
(provider) => (provider as ProviderModelMapping).jsonOutput === true,
);

if (!supportsJsonOutput) {
throw new HTTPException(400, {
message: `Model ${requestedModel} does not support JSON output mode`,
});
Expand All @@ -569,7 +581,7 @@ chat.openapi(completions, async (c) => {
if (response_format?.type === "json_schema") {
// For non-auto/custom models, check if the provider supports json_schema
if (requestedModel !== "auto" && requestedModel !== "custom") {
const supportsJsonSchema = modelInfo.providers.some(
const supportsJsonSchema = providersToCheck.some(
(provider) =>
(provider as ProviderModelMapping).jsonOutputSchema === true,
);
Expand Down
5 changes: 4 additions & 1 deletion apps/gateway/src/models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ modelsApi.openapi(listModels, async (c) => {
// Get supported parameters from model definitions with fallback to defaults
supported_parameters: getSupportedParametersFromModel(model),
// Add model-level capabilities
json_output: model.jsonOutput || false,
json_output:
model.providers.some(
(p) => (p as ProviderModelMapping).jsonOutput === true,
) || false,
free: model.free || false,
deprecated_at: model.deprecatedAt?.toISOString(),
deactivated_at: model.deactivatedAt?.toISOString(),
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/src/lib/model-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function getModelCapabilities(model: ModelDefinition): string[] {
if (provider?.reasoning) {
capabilities.push("Reasoning");
}
if (model.jsonOutput) {
if (provider?.jsonOutput) {
capabilities.push("JSON Output");
}

Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/components/api-keys/multi-model-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function MultiModelSelector({
return {
id: typedModel.id,
name: typedModel.name,
jsonOutput: typedModel.jsonOutput ?? false,
jsonOutput: typedModel.providers.some((p) => p.jsonOutput) ?? false,
stability: typedModel.stability,
providers: modelProviders,
};
Expand Down
7 changes: 5 additions & 2 deletions apps/ui/src/components/models/all-models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ export function AllModels({ children }: { children: React.ReactNode }) {
) {
return false;
}
if (filters.capabilities.jsonOutput && !model.jsonOutput) {
if (
filters.capabilities.jsonOutput &&
!model.providerDetails.some((p) => p.provider.jsonOutput)
) {
return false;
}
if (
Expand Down Expand Up @@ -515,7 +518,7 @@ export function AllModels({ children }: { children: React.ReactNode }) {
color: "text-orange-500",
});
}
if (model?.jsonOutput) {
if (provider.jsonOutput) {
capabilities.push({
icon: Braces,
label: "JSON Output",
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/components/models/model-comparison.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ function collectModelDetail(modelId?: ModelId): ModelDetail | undefined {
model,
providers: providersWithInfo,
stability: pickMostUnstableStability(model),
jsonOutput: Boolean(model.jsonOutput),
jsonOutput: model.providers.some((p) => p.jsonOutput),
aggregated,
};
}
Expand Down
92 changes: 90 additions & 2 deletions apps/ui/src/components/models/provider-card.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
"use client";

import { Copy, Check, AlertTriangle } from "lucide-react";
import {
Copy,
Check,
AlertTriangle,
Zap,
Eye,
Wrench,
MessageSquare,
Braces,
} from "lucide-react";
import { useState } from "react";

import { Badge } from "@/lib/components/badge";
import { Button } from "@/lib/components/button";
import { Card, CardContent } from "@/lib/components/card";
import { getProviderIcon } from "@/lib/components/providers-icons";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/lib/components/tooltip";
import { formatContextSize } from "@/lib/utils";

import type {
Expand Down Expand Up @@ -128,7 +143,7 @@ export function ProviderCard({
</div>
</div>

<div className="grid grid-cols-3 gap-4 text-sm">
<div className="grid grid-cols-3 gap-4 text-sm mb-4">
<div>
<div className="text-muted-foreground mb-1">Context</div>
<div className="font-mono">
Expand Down Expand Up @@ -214,6 +229,79 @@ export function ProviderCard({
</div>
</div>
</div>

<div className="border-t pt-4">
<div className="text-muted-foreground text-sm mb-2">Capabilities</div>
<TooltipProvider delayDuration={300}>
<div className="flex flex-wrap gap-2">
{provider.streaming && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-1.5 px-2 py-1 rounded-md bg-blue-50 dark:bg-blue-950/30 text-blue-700 dark:text-blue-300 text-xs">
<Zap className="h-3.5 w-3.5" />
<span>Streaming</span>
</div>
</TooltipTrigger>
<TooltipContent>
<p>Supports streaming responses</p>
</TooltipContent>
</Tooltip>
)}
{provider.vision && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-1.5 px-2 py-1 rounded-md bg-green-50 dark:bg-green-950/30 text-green-700 dark:text-green-300 text-xs">
<Eye className="h-3.5 w-3.5" />
<span>Vision</span>
</div>
</TooltipTrigger>
<TooltipContent>
<p>Supports vision and image inputs</p>
</TooltipContent>
</Tooltip>
)}
{provider.tools && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-1.5 px-2 py-1 rounded-md bg-purple-50 dark:bg-purple-950/30 text-purple-700 dark:text-purple-300 text-xs">
<Wrench className="h-3.5 w-3.5" />
<span>Tools</span>
</div>
</TooltipTrigger>
<TooltipContent>
<p>Supports function calling and tools</p>
</TooltipContent>
</Tooltip>
)}
{provider.reasoning && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-1.5 px-2 py-1 rounded-md bg-orange-50 dark:bg-orange-950/30 text-orange-700 dark:text-orange-300 text-xs">
<MessageSquare className="h-3.5 w-3.5" />
<span>Reasoning</span>
</div>
</TooltipTrigger>
<TooltipContent>
<p>Supports extended reasoning</p>
</TooltipContent>
</Tooltip>
)}
{provider.jsonOutput && (
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-1.5 px-2 py-1 rounded-md bg-cyan-50 dark:bg-cyan-950/30 text-cyan-700 dark:text-cyan-300 text-xs">
<Braces className="h-3.5 w-3.5" />
<span>JSON Output</span>
</div>
</TooltipTrigger>
<TooltipContent>
<p>Supports structured JSON output</p>
</TooltipContent>
</Tooltip>
)}
</div>
</TooltipProvider>
</div>
</CardContent>
</Card>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/lib/model-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function getModelCapabilities(model: ModelDefinition): string[] {
if (provider?.reasoning) {
capabilities.push("Reasoning");
}
if (model.jsonOutput) {
if (provider?.jsonOutput) {
capabilities.push("JSON Output");
}

Expand Down
10 changes: 0 additions & 10 deletions apps/worker/src/services/sync-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export async function syncProvidersAndModels() {
description: providerDef.description,
streaming: providerDef.streaming,
cancellation: providerDef.cancellation,
jsonOutput:
"jsonOutput" in providerDef ? providerDef.jsonOutput || null : null,
color: providerDef.color,
website: providerDef.website,
announcement: providerDef.announcement,
Expand All @@ -41,10 +39,6 @@ export async function syncProvidersAndModels() {
description: providerDef.description,
streaming: providerDef.streaming,
cancellation: providerDef.cancellation,
jsonOutput:
"jsonOutput" in providerDef
? providerDef.jsonOutput || null
: null,
color: providerDef.color,
website: providerDef.website,
announcement: providerDef.announcement,
Expand All @@ -62,8 +56,6 @@ export async function syncProvidersAndModels() {
id: modelDef.id,
name: modelDef.name || null,
family: modelDef.family,
jsonOutput:
"jsonOutput" in modelDef ? modelDef.jsonOutput || null : null,
free: "free" in modelDef ? modelDef.free || null : null,
deprecatedAt: modelDef.deprecatedAt || null,
deactivatedAt: modelDef.deactivatedAt || null,
Expand All @@ -75,8 +67,6 @@ export async function syncProvidersAndModels() {
set: {
name: modelDef.name || null,
family: modelDef.family,
jsonOutput:
"jsonOutput" in modelDef ? modelDef.jsonOutput || null : null,
free: "free" in modelDef ? modelDef.free || null : null,
deprecatedAt: modelDef.deprecatedAt || null,
deactivatedAt: modelDef.deactivatedAt || null,
Expand Down
1 change: 1 addition & 0 deletions packages/db/migrations/1761342595_glorious_flatman.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "model" DROP COLUMN "json_output";
1 change: 1 addition & 0 deletions packages/db/migrations/1761349187_petite_warbird.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "provider" DROP COLUMN "json_output";
Loading