Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

[Fix] Prompt Management - UI, allow seeing model, prompt id for Prompt (#16932)

Ishaan Jaffc9ac1949ee1b
diff --git a/litellm/proxy/prompts/prompt_endpoints.py b/litellm/proxy/prompts/prompt_endpoints.py
index d912a416120..8c336281051 100644
--- a/litellm/proxy/prompts/prompt_endpoints.py
+++ b/litellm/proxy/prompts/prompt_endpoints.py
@@ -296,13 +296,20 @@ async def list_prompts(
if key_metadata is not None:
prompts = cast(Optional[List[str]], key_metadata.get("prompts", None))
if prompts is not None:
- return ListPromptsResponse(
- prompts=[
- IN_MEMORY_PROMPT_REGISTRY.IN_MEMORY_PROMPTS[prompt]
- for prompt in prompts
- if prompt in IN_MEMORY_PROMPT_REGISTRY.IN_MEMORY_PROMPTS
- ]
- )
+ prompt_list = []
+ for prompt_id in prompts:
+ if prompt_id in IN_MEMORY_PROMPT_REGISTRY.IN_MEMORY_PROMPTS:
+ original_prompt = IN_MEMORY_PROMPT_REGISTRY.IN_MEMORY_PROMPTS[prompt_id]
+ # Create a copy with base prompt_id (without version suffix)
+ prompt_copy = PromptSpec(
+ prompt_id=get_base_prompt_id(prompt_id=original_prompt.prompt_id),
+ litellm_params=original_prompt.litellm_params,
+ prompt_info=original_prompt.prompt_info,
+ created_at=original_prompt.created_at,
+ updated_at=original_prompt.updated_at,
+ )
+ prompt_list.append(prompt_copy)
+ return ListPromptsResponse(prompts=prompt_list)
# check if user is proxy admin - show all prompts
if user_api_key_dict.user_role is not None and (
user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN
@@ -311,7 +318,18 @@ async def list_prompts(
# Get all prompts and filter to show only the latest version of each
all_prompts = list(IN_MEMORY_PROMPT_REGISTRY.IN_MEMORY_PROMPTS.values())
latest_prompts = get_latest_prompt_versions(prompts=all_prompts)
- return ListPromptsResponse(prompts=latest_prompts)
+ # Create copies with base prompt_id (without version suffix) for display
+ prompts_for_display = []
+ for original_prompt in latest_prompts:
+ prompt_copy = PromptSpec(
+ prompt_id=get_base_prompt_id(prompt_id=original_prompt.prompt_id),
+ litellm_params=original_prompt.litellm_params,
+ prompt_info=original_prompt.prompt_info,
+ created_at=original_prompt.created_at,
+ updated_at=original_prompt.updated_at,
+ )
+ prompts_for_display.append(prompt_copy)
+ return ListPromptsResponse(prompts=prompts_for_display)
else:
return ListPromptsResponse(prompts=[])
@@ -457,7 +475,17 @@ async def get_prompt_info(
detail=f"You are not authorized to access this prompt. Your role - {user_api_key_dict.user_role}, Your key's prompts - {prompts}",
)
+ # Try to get prompt directly first
prompt_spec = IN_MEMORY_PROMPT_REGISTRY.get_prompt_by_id(prompt_id)
+
+ # If not found, try to find the latest version
+ if prompt_spec is None:
+ latest_prompt_id = get_latest_version_prompt_id(
+ prompt_id=prompt_id,
+ all_prompt_ids=IN_MEMORY_PROMPT_REGISTRY.IN_MEMORY_PROMPTS
+ )
+ prompt_spec = IN_MEMORY_PROMPT_REGISTRY.get_prompt_by_id(latest_prompt_id)
+
if prompt_spec is None:
raise HTTPException(status_code=400, detail=f"Prompt {prompt_id} not found")
@@ -743,8 +771,19 @@ async def delete_prompt(
)
try:
- # Check if prompt exists
+ # Try to get prompt directly first
existing_prompt = IN_MEMORY_PROMPT_REGISTRY.get_prompt_by_id(prompt_id)
+
+ # If not found, try to find the latest version
+ if existing_prompt is None:
+ latest_prompt_id = get_latest_version_prompt_id(
+ prompt_id=prompt_id,
+ all_prompt_ids=IN_MEMORY_PROMPT_REGISTRY.IN_MEMORY_PROMPTS
+ )
+ existing_prompt = IN_MEMORY_PROMPT_REGISTRY.get_prompt_by_id(latest_prompt_id)
+ # Use the resolved prompt_id for deletion
+ prompt_id = latest_prompt_id
+
if existing_prompt is None:
raise HTTPException(
status_code=404, detail=f"Prompt with ID {prompt_id} not found"
diff --git a/ui/litellm-dashboard/src/components/prompts/prompt_table.tsx b/ui/litellm-dashboard/src/components/prompts/prompt_table.tsx
index e127511e193..ee2f2baa193 100644
--- a/ui/litellm-dashboard/src/components/prompts/prompt_table.tsx
+++ b/ui/litellm-dashboard/src/components/prompts/prompt_table.tsx
@@ -1,8 +1,9 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow, Button } from "@tremor/react";
import { SwitchVerticalIcon, ChevronUpIcon, ChevronDownIcon, TrashIcon } from "@heroicons/react/outline";
import { Tooltip } from "antd";
-import { PromptSpec } from "@/components/networking";
+import { CopyOutlined } from "@ant-design/icons";
+import { PromptSpec, modelHubCall } from "@/components/networking";
import {
ColumnDef,
flexRender,
@@ -11,6 +12,8 @@ import {
SortingState,
useReactTable,
} from "@tanstack/react-table";
+import { getProviderLogoAndName } from "@/components/provider_info_helpers";
+import { extractModel, getProviderFromModelHub } from "./prompt_utils";
interface PromptTableProps {
promptsList: PromptSpec[];
@@ -21,6 +24,12 @@ interface PromptTableProps {
isAdmin: boolean;
}
+interface ModelGroupInfo {
+ model_group: string;
+ providers: string[];
+ [key: string]: any;
+}
+
const PromptTable: React.FC<PromptTableProps> = ({
promptsList,
isLoading,
@@ -30,6 +39,28 @@ const PromptTable: React.FC<PromptTableProps> = ({
isAdmin,
}) => {
const [sorting, setSorting] = useState<SortingState>([{ id: "created_at", desc: true }]);
+ const [modelHubData, setModelHubData] = useState<Map<string, ModelGroupInfo>>(new Map());
+
+ useEffect(() => {
+ const fetchModelHubData = async () => {
+ if (!accessToken) return;
+
+ try {
+ const response = await modelHubCall(accessToken);
+ if (response?.data) {
+ const modelMap = new Map<string, ModelGroupInfo>();
+ response.data.forEach((model: ModelGroupInfo) => {
+ modelMap.set(model.model_group, model);
+ });
+ setModelHubData(modelMap);
+ }
+ } catch (error) {
+ console.error("Error fetching model hub data:", error);
+ }
+ };
+
+ fetchModelHubData();
+ }, [accessToken]);
// Format date helper function
const formatDate = (dateString?: string) => {
@@ -38,22 +69,96 @@ const PromptTable: React.FC<PromptTableProps> = ({
return date.toLocaleString();
};
+ const copyToClipboard = (text: string) => {
+ navigator.clipboard.writeText(text);
+ };
+
const columns: ColumnDef<PromptSpec>[] = [
{
header: "Prompt ID",
accessorKey: "prompt_id",
- cell: (info: any) => (
- <Tooltip title={String(info.getValue() || "")}>
- <Button
- size="xs"
- variant="light"
- className="font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate max-w-[200px]"
- onClick={() => info.getValue() && onPromptClick?.(info.getValue())}
- >
- {info.getValue() ? `${String(info.getValue()).slice(0, 7)}...` : ""}
- </Button>
- </Tooltip>
- ),
+ cell: (info: any) => {
+ const fullId = String(info.getValue() || "");
+ const displayId = fullId.length > 25 ? `${fullId.slice(0, 25)}...` : fullId;
+ return (
+ <div className="flex items-center gap-2">
+ <Tooltip title={fullId}>
+ <Button
+ size="xs"
+ variant="light"
+ className="font-mono text-blue-500 bg-blue-50 hover:bg-blue-100 text-xs font-normal px-2 py-0.5 text-left overflow-hidden truncate min-w-[220px] justify-start"
+ onClick={() => info.getValue() && onPromptClick?.(info.getValue())}
+ >
+ {displayId}
+ </Button>
+ </Tooltip>
+ <Tooltip title="Copy prompt ID">
+ <CopyOutlined
+ onClick={(e) => {
+ e.stopPropagation();
+ copyToClipboard(fullId);
+ }}
+ className="cursor-pointer text-gray-500 hover:text-blue-500 text-xs"
+ />
+ </Tooltip>
+ </div>
+ );
+ },
+ },
+ {
+ header: "Model",
+ accessorKey: "model",
+ cell: ({ row }) => {
+ const prompt = row.original;
+ const model = extractModel(prompt);
+
+ if (!model) {
+ return <span className="text-xs text-gray-400">-</span>;
+ }
+
+ const provider = getProviderFromModelHub(model, modelHubData);
+ const { logo } = getProviderLogoAndName(provider || "");
+
+ return (
+ <Tooltip title={model}>
+ <div className="flex items-center space-x-2">
+ {/* Provider Icon */}
+ <div className="flex-shrink-0">
+ {provider && logo ? (
+ <img
+ src={logo}
+ alt={`${provider} logo`}
+ className="w-4 h-4"
+ onError={(e) => {
+ const target = e.currentTarget as HTMLImageElement;
+ const parent = target.parentElement;
+ if (!parent || !parent.contains(target)) {
+ return;
+ }
+
+ try {
+ const fallbackDiv = document.createElement('div');
+ fallbackDiv.className = 'w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs';
+ fallbackDiv.textContent = provider?.charAt(0) || '-';
+ parent.replaceChild(fallbackDiv, target);
+ } catch (error) {
+ console.error('Failed to replace provider logo fallback:', error);
+ }
+ }}
+ />
+ ) : (
+ <div className="w-4 h-4 rounded-full bg-gray-200 flex items-center justify-center text-xs">
+ -
+ </div>
+ )}
+ </div>
+
+ {/* Model Name */}
+ <span className="max-w-[15ch] truncate block">{model}</span>
+ </div>
+ </Tooltip>
+ );
+ },
},
{
header: "Created At",
diff --git a/ui/litellm-dashboard/src/components/prompts/prompt_utils.tsx b/ui/litellm-dashboard/src/components/prompts/prompt_utils.tsx
new file mode 100644
index 00000000000..1776e6c103a
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/prompts/prompt_utils.tsx
@@ -0,0 +1,56 @@
+import { PromptSpec } from "@/components/networking";
+
+interface ModelGroupInfo {
+ model_group: string;
+ providers: string[];
+ [key: string]: any;
+}
+
+/**
+ * Extract model from prompt litellm_params
+ */
+export const extractModel = (prompt: PromptSpec): string | null => {
+ try {
+ const params = prompt.litellm_params as any;
+
+ // Try to extract from dotprompt_content
+ if (params?.dotprompt_content) {
+ const match = params.dotprompt_content.match(/model:\s*([^\n]+)/);
+ if (match) return match[1].trim();
+ }
+
+ // Try to extract from prompt_data
+ if (params?.prompt_data?.model) {
+ return params.prompt_data.model;
+ }
+
+ // Try to extract model from litellm_params directly
+ if (params?.model) {
+ return params.model;
+ }
+
+ return null;
+ } catch (error) {
+ console.error("Error extracting model:", error);
+ return null;
+ }
+};
+
+/**
+ * Get provider from model hub data
+ */
+export const getProviderFromModelHub = (
+ modelName: string | null,
+ modelHubData: Map<string, ModelGroupInfo>
+): string | null => {
+ if (!modelName) return null;
+
+ const modelInfo = modelHubData.get(modelName);
+ if (modelInfo && modelInfo.providers && modelInfo.providers.length > 0) {
+ // Return the first provider from the list
+ return modelInfo.providers[0];
+ }
+
+ return null;
+};
+