mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-05 07:02:13 +08:00
feat: support to adjust writing style (#290)
* feat: implment backend for adjust report style * feat: add web part * fix test cases * fix: fix typing --------- Co-authored-by: Henry Li <henry1943@163.com>
This commit is contained in:
@@ -8,6 +8,7 @@ from typing import Any, Optional
|
||||
from langchain_core.runnables import RunnableConfig
|
||||
|
||||
from src.rag.retriever import Resource
|
||||
from src.config.report_style import ReportStyle
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
@@ -21,6 +22,7 @@ class Configuration:
|
||||
max_step_num: int = 3 # Maximum number of steps in a plan
|
||||
max_search_results: int = 3 # Maximum number of search results
|
||||
mcp_settings: dict = None # MCP settings, including dynamic loaded tools
|
||||
report_style: str = ReportStyle.ACADEMIC.value # Report style
|
||||
|
||||
@classmethod
|
||||
def from_runnable_config(
|
||||
|
||||
8
src/config/report_style.py
Normal file
8
src/config/report_style.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import enum
|
||||
|
||||
|
||||
class ReportStyle(enum.Enum):
|
||||
ACADEMIC = "academic"
|
||||
POPULAR_SCIENCE = "popular_science"
|
||||
NEWS = "news"
|
||||
SOCIAL_MEDIA = "social_media"
|
||||
@@ -248,9 +248,10 @@ def coordinator_node(
|
||||
)
|
||||
|
||||
|
||||
def reporter_node(state: State):
|
||||
def reporter_node(state: State, config: RunnableConfig):
|
||||
"""Reporter node that write a final report."""
|
||||
logger.info("Reporter write final report")
|
||||
configurable = Configuration.from_runnable_config(config)
|
||||
current_plan = state.get("current_plan")
|
||||
input_ = {
|
||||
"messages": [
|
||||
@@ -260,7 +261,7 @@ def reporter_node(state: State):
|
||||
],
|
||||
"locale": state.get("locale", "en-US"),
|
||||
}
|
||||
invoke_messages = apply_prompt_template("reporter", input_)
|
||||
invoke_messages = apply_prompt_template("reporter", input_, configurable)
|
||||
observations = state.get("observations", [])
|
||||
|
||||
# Add a reminder about the new report format, citation style, and table usage
|
||||
|
||||
@@ -2,7 +2,21 @@
|
||||
CURRENT_TIME: {{ CURRENT_TIME }}
|
||||
---
|
||||
|
||||
You are a professional reporter responsible for writing clear, comprehensive reports based ONLY on provided information and verifiable facts.
|
||||
{% if report_style == "academic" %}
|
||||
You are a distinguished academic researcher and scholarly writer. Your report must embody the highest standards of academic rigor and intellectual discourse. Write with the precision of a peer-reviewed journal article, employing sophisticated analytical frameworks, comprehensive literature synthesis, and methodological transparency. Your language should be formal, technical, and authoritative, utilizing discipline-specific terminology with exactitude. Structure arguments logically with clear thesis statements, supporting evidence, and nuanced conclusions. Maintain complete objectivity, acknowledge limitations, and present balanced perspectives on controversial topics. The report should demonstrate deep scholarly engagement and contribute meaningfully to academic knowledge.
|
||||
{% elif report_style == "popular_science" %}
|
||||
You are an award-winning science communicator and storyteller. Your mission is to transform complex scientific concepts into captivating narratives that spark curiosity and wonder in everyday readers. Write with the enthusiasm of a passionate educator, using vivid analogies, relatable examples, and compelling storytelling techniques. Your tone should be warm, approachable, and infectious in its excitement about discovery. Break down technical jargon into accessible language without sacrificing accuracy. Use metaphors, real-world comparisons, and human interest angles to make abstract concepts tangible. Think like a National Geographic writer or a TED Talk presenter - engaging, enlightening, and inspiring.
|
||||
{% elif report_style == "news" %}
|
||||
You are an NBC News correspondent and investigative journalist with decades of experience in breaking news and in-depth reporting. Your report must exemplify the gold standard of American broadcast journalism: authoritative, meticulously researched, and delivered with the gravitas and credibility that NBC News is known for. Write with the precision of a network news anchor, employing the classic inverted pyramid structure while weaving compelling human narratives. Your language should be clear, authoritative, and accessible to prime-time television audiences. Maintain NBC's tradition of balanced reporting, thorough fact-checking, and ethical journalism. Think like Lester Holt or Andrea Mitchell - delivering complex stories with clarity, context, and unwavering integrity.
|
||||
{% elif report_style == "social_media" %}
|
||||
{% if locale == "zh-CN" %}
|
||||
You are a popular 小红书 (Xiaohongshu) content creator specializing in lifestyle and knowledge sharing. Your report should embody the authentic, personal, and engaging style that resonates with 小红书 users. Write with genuine enthusiasm and a "姐妹们" (sisters) tone, as if sharing exciting discoveries with close friends. Use abundant emojis, create "种草" (grass-planting/recommendation) moments, and structure content for easy mobile consumption. Your writing should feel like a personal diary entry mixed with expert insights - warm, relatable, and irresistibly shareable. Think like a top 小红书 blogger who effortlessly combines personal experience with valuable information, making readers feel like they've discovered a hidden gem.
|
||||
{% else %}
|
||||
You are a viral Twitter content creator and digital influencer specializing in breaking down complex topics into engaging, shareable threads. Your report should be optimized for maximum engagement and viral potential across social media platforms. Write with energy, authenticity, and a conversational tone that resonates with global online communities. Use strategic hashtags, create quotable moments, and structure content for easy consumption and sharing. Think like a successful Twitter thought leader who can make any topic accessible, engaging, and discussion-worthy while maintaining credibility and accuracy.
|
||||
{% endif %}
|
||||
{% else %}
|
||||
You are a professional reporter responsible for writing clear, comprehensive reports based ONLY on provided information and verifiable facts. Your report should adopt a professional tone.
|
||||
{% endif %}
|
||||
|
||||
# Role
|
||||
|
||||
@@ -43,10 +57,40 @@ Structure your report in the following format:
|
||||
- **Including images from the previous steps in the report is very helpful.**
|
||||
|
||||
5. **Survey Note** (for more comprehensive reports)
|
||||
{% if report_style == "academic" %}
|
||||
- **Literature Review & Theoretical Framework**: Comprehensive analysis of existing research and theoretical foundations
|
||||
- **Methodology & Data Analysis**: Detailed examination of research methods and analytical approaches
|
||||
- **Critical Discussion**: In-depth evaluation of findings with consideration of limitations and implications
|
||||
- **Future Research Directions**: Identification of gaps and recommendations for further investigation
|
||||
{% elif report_style == "popular_science" %}
|
||||
- **The Bigger Picture**: How this research fits into the broader scientific landscape
|
||||
- **Real-World Applications**: Practical implications and potential future developments
|
||||
- **Behind the Scenes**: Interesting details about the research process and challenges faced
|
||||
- **What's Next**: Exciting possibilities and upcoming developments in the field
|
||||
{% elif report_style == "news" %}
|
||||
- **NBC News Analysis**: In-depth examination of the story's broader implications and significance
|
||||
- **Impact Assessment**: How these developments affect different communities, industries, and stakeholders
|
||||
- **Expert Perspectives**: Insights from credible sources, analysts, and subject matter experts
|
||||
- **Timeline & Context**: Chronological background and historical context essential for understanding
|
||||
- **What's Next**: Expected developments, upcoming milestones, and stories to watch
|
||||
{% elif report_style == "social_media" %}
|
||||
{% if locale == "zh-CN" %}
|
||||
- **【种草时刻】**: 最值得关注的亮点和必须了解的核心信息
|
||||
- **【数据震撼】**: 用小红书风格展示重要统计数据和发现
|
||||
- **【姐妹们的看法】**: 社区热议话题和大家的真实反馈
|
||||
- **【行动指南】**: 实用建议和读者可以立即行动的清单
|
||||
{% else %}
|
||||
- **Thread Highlights**: Key takeaways formatted for maximum shareability
|
||||
- **Data That Matters**: Important statistics and findings presented for viral potential
|
||||
- **Community Pulse**: Trending discussions and reactions from the online community
|
||||
- **Action Steps**: Practical advice and immediate next steps for readers
|
||||
{% endif %}
|
||||
{% else %}
|
||||
- A more detailed, academic-style analysis.
|
||||
- Include comprehensive sections covering all aspects of the topic.
|
||||
- Can include comparative analysis, tables, and detailed feature breakdowns.
|
||||
- This section is optional for shorter reports.
|
||||
{% endif %}
|
||||
|
||||
6. **Key Citations**
|
||||
- List all references at the end in link reference format.
|
||||
@@ -56,7 +100,64 @@ Structure your report in the following format:
|
||||
# Writing Guidelines
|
||||
|
||||
1. Writing style:
|
||||
- Use professional tone.
|
||||
{% if report_style == "academic" %}
|
||||
**Academic Excellence Standards:**
|
||||
- Employ sophisticated, formal academic discourse with discipline-specific terminology
|
||||
- Construct complex, nuanced arguments with clear thesis statements and logical progression
|
||||
- Use third-person perspective and passive voice where appropriate for objectivity
|
||||
- Include methodological considerations and acknowledge research limitations
|
||||
- Reference theoretical frameworks and cite relevant scholarly work patterns
|
||||
- Maintain intellectual rigor with precise, unambiguous language
|
||||
- Avoid contractions, colloquialisms, and informal expressions entirely
|
||||
- Use hedging language appropriately ("suggests," "indicates," "appears to")
|
||||
{% elif report_style == "popular_science" %}
|
||||
**Science Communication Excellence:**
|
||||
- Write with infectious enthusiasm and genuine curiosity about discoveries
|
||||
- Transform technical jargon into vivid, relatable analogies and metaphors
|
||||
- Use active voice and engaging narrative techniques to tell scientific stories
|
||||
- Include "wow factor" moments and surprising revelations to maintain interest
|
||||
- Employ conversational tone while maintaining scientific accuracy
|
||||
- Use rhetorical questions to engage readers and guide their thinking
|
||||
- Include human elements: researcher personalities, discovery stories, real-world impacts
|
||||
- Balance accessibility with intellectual respect for your audience
|
||||
{% elif report_style == "news" %}
|
||||
**NBC News Editorial Standards:**
|
||||
- Open with a compelling lede that captures the essence of the story in 25-35 words
|
||||
- Use the classic inverted pyramid: most newsworthy information first, supporting details follow
|
||||
- Write in clear, conversational broadcast style that sounds natural when read aloud
|
||||
- Employ active voice and strong, precise verbs that convey action and urgency
|
||||
- Attribute every claim to specific, credible sources using NBC's attribution standards
|
||||
- Use present tense for ongoing situations, past tense for completed events
|
||||
- Maintain NBC's commitment to balanced reporting with multiple perspectives
|
||||
- Include essential context and background without overwhelming the main story
|
||||
- Verify information through at least two independent sources when possible
|
||||
- Clearly label speculation, analysis, and ongoing investigations
|
||||
- Use transitional phrases that guide readers smoothly through the narrative
|
||||
{% elif report_style == "social_media" %}
|
||||
{% if locale == "zh-CN" %}
|
||||
**小红书风格写作标准:**
|
||||
- 用"姐妹们!"、"宝子们!"等亲切称呼开头,营造闺蜜聊天氛围
|
||||
- 大量使用emoji表情符号增强表达力和视觉吸引力 ✨<><E29CA8>
|
||||
- 采用"种草"语言:"真的绝了!"、"必须安利给大家!"、"不看后悔系列!"
|
||||
- 使用小红书特色标题格式:"【干货分享】"、"【亲测有效】"、"【避雷指南】"
|
||||
- 穿插个人感受和体验:"我当时看到这个数据真的震惊了!"
|
||||
- 用数字和符号增强视觉效果:①②③、✅❌、🔥💡⭐
|
||||
- 创造"金句"和可截图分享的内容段落
|
||||
- 结尾用互动性语言:"你们觉得呢?"、"评论区聊聊!"、"记得点赞收藏哦!"
|
||||
{% else %}
|
||||
**Twitter/X Engagement Standards:**
|
||||
- Open with attention-grabbing hooks that stop the scroll
|
||||
- Use thread-style formatting with numbered points (1/n, 2/n, etc.)
|
||||
- Incorporate strategic hashtags for discoverability and trending topics
|
||||
- Write quotable, tweetable snippets that beg to be shared
|
||||
- Use conversational, authentic voice with personality and wit
|
||||
- Include relevant emojis to enhance meaning and visual appeal 🧵📊💡
|
||||
- Create "thread-worthy" content with clear progression and payoff
|
||||
- End with engagement prompts: "What do you think?", "Retweet if you agree"
|
||||
{% endif %}
|
||||
{% else %}
|
||||
- Use a professional tone.
|
||||
{% endif %}
|
||||
- Be concise and precise.
|
||||
- Avoid speculation.
|
||||
- Support claims with evidence.
|
||||
@@ -77,6 +178,62 @@ Structure your report in the following format:
|
||||
- Use horizontal rules (---) to separate major sections.
|
||||
- Track the sources of information but keep the main text clean and readable.
|
||||
|
||||
{% if report_style == "academic" %}
|
||||
**Academic Formatting Specifications:**
|
||||
- Use formal section headings with clear hierarchical structure (## Introduction, ### Methodology, #### Subsection)
|
||||
- Employ numbered lists for methodological steps and logical sequences
|
||||
- Use block quotes for important definitions or key theoretical concepts
|
||||
- Include detailed tables with comprehensive headers and statistical data
|
||||
- Use footnote-style formatting for additional context or clarifications
|
||||
- Maintain consistent academic citation patterns throughout
|
||||
- Use `code blocks` for technical specifications, formulas, or data samples
|
||||
{% elif report_style == "popular_science" %}
|
||||
**Science Communication Formatting:**
|
||||
- Use engaging, descriptive headings that spark curiosity ("The Surprising Discovery That Changed Everything")
|
||||
- Employ creative formatting like callout boxes for "Did You Know?" facts
|
||||
- Use bullet points for easy-to-digest key findings
|
||||
- Include visual breaks with strategic use of bold text for emphasis
|
||||
- Format analogies and metaphors prominently to aid understanding
|
||||
- Use numbered lists for step-by-step explanations of complex processes
|
||||
- Highlight surprising statistics or findings with special formatting
|
||||
{% elif report_style == "news" %}
|
||||
**NBC News Formatting Standards:**
|
||||
- Craft headlines that are informative yet compelling, following NBC's style guide
|
||||
- Use NBC-style datelines and bylines for professional credibility
|
||||
- Structure paragraphs for broadcast readability (1-2 sentences for digital, 2-3 for print)
|
||||
- Employ strategic subheadings that advance the story narrative
|
||||
- Format direct quotes with proper attribution and context
|
||||
- Use bullet points sparingly, primarily for breaking news updates or key facts
|
||||
- Include "BREAKING" or "DEVELOPING" labels for ongoing stories
|
||||
- Format source attribution clearly: "according to NBC News," "sources tell NBC News"
|
||||
- Use italics for emphasis on key terms or breaking developments
|
||||
- Structure the story with clear sections: Lede, Context, Analysis, Looking Ahead
|
||||
{% elif report_style == "social_media" %}
|
||||
{% if locale == "zh-CN" %}
|
||||
**小红书格式优化标准:**
|
||||
- 使用吸睛标题配合emoji:"🔥【重磅】这个发现太震撼了!"
|
||||
- 关键数据用醒目格式突出:「 重点数据 」或 ⭐ 核心发现 ⭐
|
||||
- 适度使用大写强调:真的YYDS!、绝绝子!
|
||||
- 用emoji作为分点符号:✨、🌟、<F09F8C9F>、<EFBFBD>、💯
|
||||
- 创建话题标签区域:#科技前沿 #必看干货 #涨知识了
|
||||
- 设置"划重点"总结区域,方便快速阅读
|
||||
- 利用换行和空白营造手机阅读友好的版式
|
||||
- 制作"金句卡片"格式,便于截图分享
|
||||
- 使用分割线和特殊符号:「」『』【】━━━━━━
|
||||
{% else %}
|
||||
**Twitter/X Formatting Standards:**
|
||||
- Use compelling headlines with strategic emoji placement 🧵⚡️🔥
|
||||
- Format key insights as standalone, quotable tweet blocks
|
||||
- Employ thread numbering for multi-part content (1/12, 2/12, etc.)
|
||||
- Use bullet points with emoji bullets for visual appeal
|
||||
- Include strategic hashtags at the end: #TechNews #Innovation #MustRead
|
||||
- Create "TL;DR" summaries for quick consumption
|
||||
- Use line breaks and white space for mobile readability
|
||||
- Format "quotable moments" with clear visual separation
|
||||
- Include call-to-action elements: "🔄 RT to share" "💬 What's your take?"
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
# Data Integrity
|
||||
|
||||
- Only use information explicitly provided in the input.
|
||||
|
||||
@@ -14,6 +14,7 @@ from fastapi.responses import Response, StreamingResponse
|
||||
from langchain_core.messages import AIMessageChunk, ToolMessage, BaseMessage
|
||||
from langgraph.types import Command
|
||||
|
||||
from src.config.report_style import ReportStyle
|
||||
from src.config.tools import SELECTED_RAG_PROVIDER
|
||||
from src.graph.builder import build_graph_with_memory
|
||||
from src.podcast.graph.builder import build_graph as build_podcast_graph
|
||||
@@ -77,6 +78,7 @@ async def chat_stream(request: ChatRequest):
|
||||
request.interrupt_feedback,
|
||||
request.mcp_settings,
|
||||
request.enable_background_investigation,
|
||||
request.report_style,
|
||||
),
|
||||
media_type="text/event-stream",
|
||||
)
|
||||
@@ -92,7 +94,8 @@ async def _astream_workflow_generator(
|
||||
auto_accepted_plan: bool,
|
||||
interrupt_feedback: str,
|
||||
mcp_settings: dict,
|
||||
enable_background_investigation,
|
||||
enable_background_investigation: bool,
|
||||
report_style: ReportStyle,
|
||||
):
|
||||
input_ = {
|
||||
"messages": messages,
|
||||
@@ -118,6 +121,7 @@ async def _astream_workflow_generator(
|
||||
"max_step_num": max_step_num,
|
||||
"max_search_results": max_search_results,
|
||||
"mcp_settings": mcp_settings,
|
||||
"report_style": report_style.value,
|
||||
},
|
||||
stream_mode=["messages", "updates"],
|
||||
subgraphs=True,
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import List, Optional, Union
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from src.rag.retriever import Resource
|
||||
from src.config.report_style import ReportStyle
|
||||
|
||||
|
||||
class ContentItem(BaseModel):
|
||||
@@ -58,6 +59,9 @@ class ChatRequest(BaseModel):
|
||||
enable_background_investigation: Optional[bool] = Field(
|
||||
True, description="Whether to get background investigation before plan"
|
||||
)
|
||||
report_style: Optional[ReportStyle] = Field(
|
||||
ReportStyle.ACADEMIC, description="The style of the report"
|
||||
)
|
||||
|
||||
|
||||
class TTSRequest(BaseModel):
|
||||
|
||||
@@ -106,3 +106,40 @@ def test_current_time_format():
|
||||
assert any(
|
||||
line.strip().startswith("CURRENT_TIME:") for line in system_content.split("\n")
|
||||
)
|
||||
|
||||
|
||||
def test_apply_prompt_template_reporter():
|
||||
"""Test reporter template rendering with different styles and locale"""
|
||||
|
||||
test_state_news = {
|
||||
"messages": [],
|
||||
"task": "test reporter task",
|
||||
"workspace_context": "test reporter context",
|
||||
"report_style": "news",
|
||||
"locale": "en-US",
|
||||
}
|
||||
messages_news = apply_prompt_template("reporter", test_state_news)
|
||||
system_content_news = messages_news[0]["content"]
|
||||
assert "NBC News" in system_content_news
|
||||
|
||||
test_state_social_media_en = {
|
||||
"messages": [],
|
||||
"task": "test reporter task",
|
||||
"workspace_context": "test reporter context",
|
||||
"report_style": "social_media",
|
||||
"locale": "en-US",
|
||||
}
|
||||
messages_default = apply_prompt_template("reporter", test_state_social_media_en)
|
||||
system_content_default = messages_default[0]["content"]
|
||||
assert "Twitter/X" in system_content_default
|
||||
|
||||
test_state_social_media_cn = {
|
||||
"messages": [],
|
||||
"task": "test reporter task",
|
||||
"workspace_context": "test reporter context",
|
||||
"report_style": "social_media",
|
||||
"locale": "zh-CN",
|
||||
}
|
||||
messages_cn = apply_prompt_template("reporter", test_state_social_media_cn)
|
||||
system_content_cn = messages_cn[0]["content"]
|
||||
assert "小红书" in system_content_cn
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Detective } from "~/components/deer-flow/icons/detective";
|
||||
import MessageInput, {
|
||||
type MessageInputRef,
|
||||
} from "~/components/deer-flow/message-input";
|
||||
import { ReportStyleDialog } from "~/components/deer-flow/report-style-dialog";
|
||||
import { Tooltip } from "~/components/deer-flow/tooltip";
|
||||
import { Button } from "~/components/ui/button";
|
||||
import type { Option, Resource } from "~/core/messages";
|
||||
@@ -104,7 +105,7 @@ export function InputBox({
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center px-4 py-2">
|
||||
<div className="flex grow">
|
||||
<div className="flex grow gap-2">
|
||||
<Tooltip
|
||||
className="max-w-60"
|
||||
title={
|
||||
@@ -133,6 +134,7 @@ export function InputBox({
|
||||
<Detective /> Investigation
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<ReportStyleDialog />
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
<Tooltip title={responding ? "Stop" : "Send"}>
|
||||
|
||||
@@ -25,7 +25,6 @@ import type { Tab } from "./types";
|
||||
|
||||
const generalFormSchema = z.object({
|
||||
autoAcceptedPlan: z.boolean(),
|
||||
enableBackgroundInvestigation: z.boolean(),
|
||||
maxPlanIterations: z.number().min(1, {
|
||||
message: "Max plan iterations must be at least 1.",
|
||||
}),
|
||||
@@ -35,6 +34,9 @@ const generalFormSchema = z.object({
|
||||
maxSearchResults: z.number().min(1, {
|
||||
message: "Max search results must be at least 1.",
|
||||
}),
|
||||
// Others
|
||||
enableBackgroundInvestigation: z.boolean(),
|
||||
reportStyle: z.enum(["academic", "popular_science", "news", "social_media"]),
|
||||
});
|
||||
|
||||
export const GeneralTab: Tab = ({
|
||||
|
||||
45
web/src/components/deer-flow/icons/report-style.tsx
Normal file
45
web/src/components/deer-flow/icons/report-style.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
export function ReportStyle({ className }: { className?: string }) {
|
||||
return (
|
||||
<svg
|
||||
className={className}
|
||||
version="1.1"
|
||||
width="800px"
|
||||
height="800px"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
>
|
||||
<g fill="currentcolor">
|
||||
<path
|
||||
d="M4 4C4 3.44772 4.44772 3 5 3H19C19.5523 3 20 3.44772 20 4V20C20 20.5523 19.5523 21 19 21H5C4.44772 21 4 20.5523 4 20V4Z"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
fill="none"
|
||||
/>
|
||||
<path
|
||||
d="M8 7H16"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
/>
|
||||
<path
|
||||
d="M8 11H16"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
/>
|
||||
<path
|
||||
d="M8 15H12"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
/>
|
||||
<circle
|
||||
cx="16"
|
||||
cy="15"
|
||||
r="2"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
128
web/src/components/deer-flow/report-style-dialog.tsx
Normal file
128
web/src/components/deer-flow/report-style-dialog.tsx
Normal file
@@ -0,0 +1,128 @@
|
||||
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { useState } from "react";
|
||||
import { Check, FileText, Newspaper, Users, GraduationCap } from "lucide-react";
|
||||
|
||||
import { Button } from "~/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "~/components/ui/dialog";
|
||||
import { setReportStyle, useSettingsStore } from "~/core/store";
|
||||
import { cn } from "~/lib/utils";
|
||||
|
||||
import { Tooltip } from "./tooltip";
|
||||
|
||||
const REPORT_STYLES = [
|
||||
{
|
||||
value: "academic" as const,
|
||||
label: "Academic",
|
||||
description: "Formal, objective, and analytical with precise terminology",
|
||||
icon: GraduationCap,
|
||||
},
|
||||
{
|
||||
value: "popular_science" as const,
|
||||
label: "Popular Science",
|
||||
description: "Engaging and accessible for general audience",
|
||||
icon: FileText,
|
||||
},
|
||||
{
|
||||
value: "news" as const,
|
||||
label: "News",
|
||||
description: "Factual, concise, and impartial journalistic style",
|
||||
icon: Newspaper,
|
||||
},
|
||||
{
|
||||
value: "social_media" as const,
|
||||
label: "Social Media",
|
||||
description: "Concise, attention-grabbing, and shareable",
|
||||
icon: Users,
|
||||
},
|
||||
];
|
||||
|
||||
export function ReportStyleDialog() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const currentStyle = useSettingsStore((state) => state.general.reportStyle);
|
||||
|
||||
const handleStyleChange = (
|
||||
style: "academic" | "popular_science" | "news" | "social_media",
|
||||
) => {
|
||||
setReportStyle(style);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const currentStyleConfig =
|
||||
REPORT_STYLES.find((style) => style.value === currentStyle) ||
|
||||
REPORT_STYLES[0]!;
|
||||
const CurrentIcon = currentStyleConfig.icon;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<Tooltip
|
||||
className="max-w-60"
|
||||
title={
|
||||
<div>
|
||||
<h3 className="mb-2 font-bold">
|
||||
Writing Style: {currentStyleConfig.label}
|
||||
</h3>
|
||||
<p>
|
||||
Choose the writing style for your research reports. Different
|
||||
styles are optimized for different audiences and purposes.
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
className="!border-brand !text-brand rounded-2xl"
|
||||
variant="outline"
|
||||
>
|
||||
<CurrentIcon className="h-4 w-4" /> {currentStyleConfig.label}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
</Tooltip>
|
||||
<DialogContent className="sm:max-w-[500px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Choose Writing Style</DialogTitle>
|
||||
<DialogDescription>
|
||||
Select the writing style for your research reports. Each style is
|
||||
optimized for different audiences and purposes.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-3 py-4">
|
||||
{REPORT_STYLES.map((style) => {
|
||||
const Icon = style.icon;
|
||||
const isSelected = currentStyle === style.value;
|
||||
|
||||
return (
|
||||
<button
|
||||
key={style.value}
|
||||
className={cn(
|
||||
"hover:bg-accent flex items-start gap-3 rounded-lg border p-4 text-left transition-colors",
|
||||
isSelected && "border-primary bg-accent",
|
||||
)}
|
||||
onClick={() => handleStyleChange(style.value)}
|
||||
>
|
||||
<Icon className="mt-0.5 h-5 w-5 shrink-0" />
|
||||
<div className="flex-1 space-y-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<h4 className="font-medium">{style.label}</h4>
|
||||
{isSelected && <Check className="text-primary h-4 w-4" />}
|
||||
</div>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{style.description}
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -23,6 +23,7 @@ export async function* chatStream(
|
||||
max_search_results?: number;
|
||||
interrupt_feedback?: string;
|
||||
enable_background_investigation: boolean;
|
||||
report_style?: "academic" | "popular_science" | "news" | "social_media";
|
||||
mcp_settings?: {
|
||||
servers: Record<
|
||||
string,
|
||||
|
||||
@@ -14,6 +14,7 @@ const DEFAULT_SETTINGS: SettingsState = {
|
||||
maxPlanIterations: 1,
|
||||
maxStepNum: 3,
|
||||
maxSearchResults: 3,
|
||||
reportStyle: "academic",
|
||||
},
|
||||
mcp: {
|
||||
servers: [],
|
||||
@@ -27,6 +28,7 @@ export type SettingsState = {
|
||||
maxPlanIterations: number;
|
||||
maxStepNum: number;
|
||||
maxSearchResults: number;
|
||||
reportStyle: "academic" | "popular_science" | "news" | "social_media";
|
||||
};
|
||||
mcp: {
|
||||
servers: MCPServerMetadata[];
|
||||
@@ -125,6 +127,16 @@ export const getChatStreamSettings = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export function setReportStyle(value: "academic" | "popular_science" | "news" | "social_media") {
|
||||
useSettingsStore.setState((state) => ({
|
||||
general: {
|
||||
...state.general,
|
||||
reportStyle: value,
|
||||
},
|
||||
}));
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
export function setEnableBackgroundInvestigation(value: boolean) {
|
||||
useSettingsStore.setState((state) => ({
|
||||
general: {
|
||||
|
||||
@@ -109,6 +109,7 @@ export async function sendMessage(
|
||||
max_plan_iterations: settings.maxPlanIterations,
|
||||
max_step_num: settings.maxStepNum,
|
||||
max_search_results: settings.maxSearchResults,
|
||||
report_style: settings.reportStyle,
|
||||
mcp_settings: settings.mcpSettings,
|
||||
},
|
||||
options,
|
||||
|
||||
Reference in New Issue
Block a user