llama-stack-mirror/llama_stack/ui/app/logs/chat-completions/page.tsx
ehhuang 56e5ddb39f
feat(ui): add views for Responses (#2293)
# What does this PR do?
* Add responses list and detail views
* Refactored components to be shared as much as possible between chat
completions and responses

## Test Plan
<img width="2014" alt="image"
src="https://github.com/user-attachments/assets/6dee12ea-8876-4351-a6eb-2338058466ef"
/>
<img width="2021" alt="image"
src="https://github.com/user-attachments/assets/6c7c71b8-25b7-4199-9c57-6960be5580c8"
/>

added tests
2025-05-28 09:51:22 -07:00

51 lines
1.5 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
import { ChatCompletion } from "@/lib/types";
import { ChatCompletionsTable } from "@/components/chat-completions/chat-completions-table";
import { client } from "@/lib/client";
export default function ChatCompletionsPage() {
const [completions, setCompletions] = useState<ChatCompletion[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [error, setError] = useState<Error | null>(null);
useEffect(() => {
const fetchCompletions = async () => {
setIsLoading(true);
setError(null);
try {
const response = await client.chat.completions.list();
const data = Array.isArray(response)
? response
: (response as { data: ChatCompletion[] }).data;
if (Array.isArray(data)) {
setCompletions(data);
} else {
console.error("Unexpected response structure:", response);
setError(new Error("Unexpected response structure"));
setCompletions([]);
}
} catch (err) {
console.error("Error fetching chat completions:", err);
setError(
err instanceof Error ? err : new Error("Failed to fetch completions"),
);
setCompletions([]);
} finally {
setIsLoading(false);
}
};
fetchCompletions();
}, []);
return (
<ChatCompletionsTable
data={completions}
isLoading={isLoading}
error={error}
/>
);
}