feat: add client-side of deep thinking

This commit is contained in:
Henry Li
2025-06-11 19:48:46 +08:00
parent 2ffacd9294
commit 3e364c1afe
5 changed files with 56 additions and 3 deletions

View File

@@ -3,8 +3,8 @@
import { MagicWandIcon } from "@radix-ui/react-icons";
import { AnimatePresence, motion } from "framer-motion";
import { ArrowUp, X } from "lucide-react";
import { useCallback, useRef, useState } from "react";
import { ArrowUp, Lightbulb, X } from "lucide-react";
import { useCallback, useMemo, useRef, useState } from "react";
import { Detective } from "~/components/deer-flow/icons/detective";
import MessageInput, {
@@ -15,8 +15,10 @@ import { Tooltip } from "~/components/deer-flow/tooltip";
import { BorderBeam } from "~/components/magicui/border-beam";
import { Button } from "~/components/ui/button";
import { enhancePrompt } from "~/core/api";
import { getConfig } from "~/core/api/config";
import type { Option, Resource } from "~/core/messages";
import {
setEnableDeepThinking,
setEnableBackgroundInvestigation,
useSettingsStore,
} from "~/core/store";
@@ -44,9 +46,13 @@ export function InputBox({
onCancel?: () => void;
onRemoveFeedback?: () => void;
}) {
const enableDeepThinking = useSettingsStore(
(state) => state.general.enableDeepThinking,
);
const backgroundInvestigation = useSettingsStore(
(state) => state.general.enableBackgroundInvestigation,
);
const reasoningModel = useMemo(() => getConfig().models.reasoning?.[0], []);
const reportStyle = useSettingsStore((state) => state.general.reportStyle);
const containerRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<MessageInputRef>(null);
@@ -203,6 +209,36 @@ export function InputBox({
</div>
<div className="flex items-center px-4 py-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
className="max-w-60"
title={

View File

@@ -36,6 +36,7 @@ const generalFormSchema = z.object({
}),
// Others
enableBackgroundInvestigation: z.boolean(),
enableDeepThinking: z.boolean(),
reportStyle: z.enum(["academic", "popular_science", "news", "social_media"]),
});

View File

@@ -22,6 +22,7 @@ export async function* chatStream(
max_step_num: number;
max_search_results?: number;
interrupt_feedback?: string;
enable_deep_thinking?: boolean;
enable_background_investigation: boolean;
report_style?: "academic" | "popular_science" | "news" | "social_media";
mcp_settings?: {

View File

@@ -10,6 +10,7 @@ const SETTINGS_KEY = "deerflow.settings";
const DEFAULT_SETTINGS: SettingsState = {
general: {
autoAcceptedPlan: false,
enableDeepThinking: false,
enableBackgroundInvestigation: false,
maxPlanIterations: 1,
maxStepNum: 3,
@@ -24,6 +25,7 @@ const DEFAULT_SETTINGS: SettingsState = {
export type SettingsState = {
general: {
autoAcceptedPlan: boolean;
enableDeepThinking: boolean;
enableBackgroundInvestigation: boolean;
maxPlanIterations: 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) => ({
general: {
...state.general,
@@ -137,6 +141,16 @@ export function setReportStyle(value: "academic" | "popular_science" | "news" |
saveSettings();
}
export function setEnableDeepThinking(value: boolean) {
useSettingsStore.setState((state) => ({
general: {
...state.general,
enableDeepThinking: value,
},
}));
saveSettings();
}
export function setEnableBackgroundInvestigation(value: boolean) {
useSettingsStore.setState((state) => ({
general: {

View File

@@ -104,6 +104,7 @@ export async function sendMessage(
interrupt_feedback: interruptFeedback,
resources,
auto_accepted_plan: settings.autoAcceptedPlan,
enable_deep_thinking: settings.enableDeepThinking ?? false,
enable_background_investigation:
settings.enableBackgroundInvestigation ?? true,
max_plan_iterations: settings.maxPlanIterations,