mirror of
https://git.mirrors.martin98.com/https://github.com/bytedance/deer-flow
synced 2025-08-20 01:59:12 +08:00
fix: add error handling for podcast generation (#59)
Co-authored-by: Jiang Feng <jiangfeng.11@bytedance.com>
This commit is contained in:
parent
77a7f8f8ab
commit
b845b1ca01
@ -328,7 +328,7 @@ function PlanCard({
|
||||
<Card className={cn("w-full", className)}>
|
||||
<CardHeader>
|
||||
<CardTitle>
|
||||
<Markdown animated>
|
||||
<Markdown animate>
|
||||
{`### ${
|
||||
plan.title !== undefined && plan.title !== ""
|
||||
? plan.title
|
||||
@ -404,6 +404,9 @@ function PodcastCard({
|
||||
const isGenerating = useMemo(() => {
|
||||
return message.isStreaming;
|
||||
}, [message.isStreaming]);
|
||||
const hasError = useMemo(() => {
|
||||
return data?.error !== undefined;
|
||||
}, [data]);
|
||||
const [isPlaying, setIsPlaying] = useState(false);
|
||||
return (
|
||||
<Card className={cn("w-[508px]", className)}>
|
||||
@ -411,15 +414,21 @@ function PodcastCard({
|
||||
<div className="text-muted-foreground flex items-center justify-between text-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
{isGenerating ? <LoadingOutlined /> : <Headphones size={16} />}
|
||||
<RainbowText animated={isGenerating}>
|
||||
{isGenerating
|
||||
? "Generating podcast..."
|
||||
: isPlaying
|
||||
? "Now playing podcast..."
|
||||
: "Podcast"}
|
||||
</RainbowText>
|
||||
{!hasError ? (
|
||||
<RainbowText animated={isGenerating}>
|
||||
{isGenerating
|
||||
? "Generating podcast..."
|
||||
: isPlaying
|
||||
? "Now playing podcast..."
|
||||
: "Podcast"}
|
||||
</RainbowText>
|
||||
) : (
|
||||
<div className="text-red-500">
|
||||
Error when generating podcast. Please try again.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{!isGenerating && (
|
||||
{!hasError && !isGenerating && (
|
||||
<div className="flex">
|
||||
<Tooltip title="Download podcast">
|
||||
<Button variant="ghost" size="icon" asChild>
|
||||
@ -441,13 +450,17 @@ function PodcastCard({
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<audio
|
||||
className="w-full"
|
||||
src={audioUrl}
|
||||
controls
|
||||
onPlay={() => setIsPlaying(true)}
|
||||
onPause={() => setIsPlaying(false)}
|
||||
/>
|
||||
{audioUrl ? (
|
||||
<audio
|
||||
className="w-full"
|
||||
src={audioUrl}
|
||||
controls
|
||||
onPlay={() => setIsPlaying(true)}
|
||||
onPause={() => setIsPlaying(false)}
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full"></div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
@ -294,7 +294,27 @@ export async function listenToPodcast(researchId: string) {
|
||||
};
|
||||
appendMessage(podcastMessage);
|
||||
// Generating podcast...
|
||||
const audioUrl = await generatePodcast(reportMessage.content);
|
||||
let audioUrl: string | undefined;
|
||||
try {
|
||||
audioUrl = await generatePodcast(reportMessage.content);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
useStore.setState((state) => ({
|
||||
messages: new Map(useStore.getState().messages).set(
|
||||
podCastMessageId,
|
||||
{
|
||||
...state.messages.get(podCastMessageId)!,
|
||||
content: JSON.stringify({
|
||||
...podcastObject,
|
||||
error: e instanceof Error ? e.message : "Unknown error",
|
||||
}),
|
||||
isStreaming: false,
|
||||
},
|
||||
),
|
||||
}));
|
||||
toast("An error occurred while generating podcast. Please try again.");
|
||||
return;
|
||||
}
|
||||
useStore.setState((state) => ({
|
||||
messages: new Map(useStore.getState().messages).set(podCastMessageId, {
|
||||
...state.messages.get(podCastMessageId)!,
|
||||
|
Loading…
x
Reference in New Issue
Block a user