mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-29 00:34:47 +08:00
feat: add client-side of deep thinking
This commit is contained in:
@@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
import { MagicWandIcon } from "@radix-ui/react-icons";
|
import { MagicWandIcon } from "@radix-ui/react-icons";
|
||||||
import { AnimatePresence, motion } from "framer-motion";
|
import { AnimatePresence, motion } from "framer-motion";
|
||||||
import { ArrowUp, X } from "lucide-react";
|
import { ArrowUp, Lightbulb, X } from "lucide-react";
|
||||||
import { useCallback, useRef, useState } from "react";
|
import { useCallback, useMemo, useRef, useState } from "react";
|
||||||
|
|
||||||
import { Detective } from "~/components/deer-flow/icons/detective";
|
import { Detective } from "~/components/deer-flow/icons/detective";
|
||||||
import MessageInput, {
|
import MessageInput, {
|
||||||
@@ -15,8 +15,10 @@ import { Tooltip } from "~/components/deer-flow/tooltip";
|
|||||||
import { BorderBeam } from "~/components/magicui/border-beam";
|
import { BorderBeam } from "~/components/magicui/border-beam";
|
||||||
import { Button } from "~/components/ui/button";
|
import { Button } from "~/components/ui/button";
|
||||||
import { enhancePrompt } from "~/core/api";
|
import { enhancePrompt } from "~/core/api";
|
||||||
|
import { getConfig } from "~/core/api/config";
|
||||||
import type { Option, Resource } from "~/core/messages";
|
import type { Option, Resource } from "~/core/messages";
|
||||||
import {
|
import {
|
||||||
|
setEnableDeepThinking,
|
||||||
setEnableBackgroundInvestigation,
|
setEnableBackgroundInvestigation,
|
||||||
useSettingsStore,
|
useSettingsStore,
|
||||||
} from "~/core/store";
|
} from "~/core/store";
|
||||||
@@ -44,9 +46,13 @@ export function InputBox({
|
|||||||
onCancel?: () => void;
|
onCancel?: () => void;
|
||||||
onRemoveFeedback?: () => void;
|
onRemoveFeedback?: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
const enableDeepThinking = useSettingsStore(
|
||||||
|
(state) => state.general.enableDeepThinking,
|
||||||
|
);
|
||||||
const backgroundInvestigation = useSettingsStore(
|
const backgroundInvestigation = useSettingsStore(
|
||||||
(state) => state.general.enableBackgroundInvestigation,
|
(state) => state.general.enableBackgroundInvestigation,
|
||||||
);
|
);
|
||||||
|
const reasoningModel = useMemo(() => getConfig().models.reasoning?.[0], []);
|
||||||
const reportStyle = useSettingsStore((state) => state.general.reportStyle);
|
const reportStyle = useSettingsStore((state) => state.general.reportStyle);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const inputRef = useRef<MessageInputRef>(null);
|
const inputRef = useRef<MessageInputRef>(null);
|
||||||
@@ -203,6 +209,36 @@ export function InputBox({
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex items-center px-4 py-2">
|
<div className="flex items-center px-4 py-2">
|
||||||
<div className="flex grow gap-2">
|
<div className="flex grow gap-2">
|
||||||
|
{reasoningModel && (
|
||||||
|
<Tooltip
|
||||||
|
className="max-w-60"
|
||||||
|
title={
|
||||||
|
<div>
|
||||||
|
<h3 className="mb-2 font-bold">
|
||||||
|
Deep Thinking Mode: {enableDeepThinking ? "On" : "Off"}
|
||||||
|
</h3>
|
||||||
|
<p>
|
||||||
|
When enabled, DeerFlow will use reasoning model (
|
||||||
|
{reasoningModel}) to generate more thoughtful plans.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
className={cn(
|
||||||
|
"rounded-2xl",
|
||||||
|
enableDeepThinking && "!border-brand !text-brand",
|
||||||
|
)}
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
setEnableDeepThinking(!enableDeepThinking);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Lightbulb /> Deep Thinking
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
|
||||||
<Tooltip
|
<Tooltip
|
||||||
className="max-w-60"
|
className="max-w-60"
|
||||||
title={
|
title={
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ const generalFormSchema = z.object({
|
|||||||
}),
|
}),
|
||||||
// Others
|
// Others
|
||||||
enableBackgroundInvestigation: z.boolean(),
|
enableBackgroundInvestigation: z.boolean(),
|
||||||
|
enableDeepThinking: z.boolean(),
|
||||||
reportStyle: z.enum(["academic", "popular_science", "news", "social_media"]),
|
reportStyle: z.enum(["academic", "popular_science", "news", "social_media"]),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export async function* chatStream(
|
|||||||
max_step_num: number;
|
max_step_num: number;
|
||||||
max_search_results?: number;
|
max_search_results?: number;
|
||||||
interrupt_feedback?: string;
|
interrupt_feedback?: string;
|
||||||
|
enable_deep_thinking?: boolean;
|
||||||
enable_background_investigation: boolean;
|
enable_background_investigation: boolean;
|
||||||
report_style?: "academic" | "popular_science" | "news" | "social_media";
|
report_style?: "academic" | "popular_science" | "news" | "social_media";
|
||||||
mcp_settings?: {
|
mcp_settings?: {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const SETTINGS_KEY = "deerflow.settings";
|
|||||||
const DEFAULT_SETTINGS: SettingsState = {
|
const DEFAULT_SETTINGS: SettingsState = {
|
||||||
general: {
|
general: {
|
||||||
autoAcceptedPlan: false,
|
autoAcceptedPlan: false,
|
||||||
|
enableDeepThinking: false,
|
||||||
enableBackgroundInvestigation: false,
|
enableBackgroundInvestigation: false,
|
||||||
maxPlanIterations: 1,
|
maxPlanIterations: 1,
|
||||||
maxStepNum: 3,
|
maxStepNum: 3,
|
||||||
@@ -24,6 +25,7 @@ const DEFAULT_SETTINGS: SettingsState = {
|
|||||||
export type SettingsState = {
|
export type SettingsState = {
|
||||||
general: {
|
general: {
|
||||||
autoAcceptedPlan: boolean;
|
autoAcceptedPlan: boolean;
|
||||||
|
enableDeepThinking: boolean;
|
||||||
enableBackgroundInvestigation: boolean;
|
enableBackgroundInvestigation: boolean;
|
||||||
maxPlanIterations: number;
|
maxPlanIterations: number;
|
||||||
maxStepNum: number;
|
maxStepNum: number;
|
||||||
@@ -127,7 +129,9 @@ export const getChatStreamSettings = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function setReportStyle(value: "academic" | "popular_science" | "news" | "social_media") {
|
export function setReportStyle(
|
||||||
|
value: "academic" | "popular_science" | "news" | "social_media",
|
||||||
|
) {
|
||||||
useSettingsStore.setState((state) => ({
|
useSettingsStore.setState((state) => ({
|
||||||
general: {
|
general: {
|
||||||
...state.general,
|
...state.general,
|
||||||
@@ -137,6 +141,16 @@ export function setReportStyle(value: "academic" | "popular_science" | "news" |
|
|||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setEnableDeepThinking(value: boolean) {
|
||||||
|
useSettingsStore.setState((state) => ({
|
||||||
|
general: {
|
||||||
|
...state.general,
|
||||||
|
enableDeepThinking: value,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
export function setEnableBackgroundInvestigation(value: boolean) {
|
export function setEnableBackgroundInvestigation(value: boolean) {
|
||||||
useSettingsStore.setState((state) => ({
|
useSettingsStore.setState((state) => ({
|
||||||
general: {
|
general: {
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ export async function sendMessage(
|
|||||||
interrupt_feedback: interruptFeedback,
|
interrupt_feedback: interruptFeedback,
|
||||||
resources,
|
resources,
|
||||||
auto_accepted_plan: settings.autoAcceptedPlan,
|
auto_accepted_plan: settings.autoAcceptedPlan,
|
||||||
|
enable_deep_thinking: settings.enableDeepThinking ?? false,
|
||||||
enable_background_investigation:
|
enable_background_investigation:
|
||||||
settings.enableBackgroundInvestigation ?? true,
|
settings.enableBackgroundInvestigation ?? true,
|
||||||
max_plan_iterations: settings.maxPlanIterations,
|
max_plan_iterations: settings.maxPlanIterations,
|
||||||
|
|||||||
Reference in New Issue
Block a user