enzostvs HF Staff commited on
Commit
e23c4a4
·
1 Parent(s): 4607b59
app/api/ask/route.ts CHANGED
@@ -102,7 +102,7 @@ export async function POST(request: NextRequest) {
102
  let rewrittenPrompt = prompt;
103
 
104
  if (enhancedSettings.isActive) {
105
- rewrittenPrompt = await rewritePrompt(prompt, enhancedSettings, { token, billTo }, selectedModel.value, selectedProvider);
106
  }
107
 
108
  try {
 
102
  let rewrittenPrompt = prompt;
103
 
104
  if (enhancedSettings.isActive) {
105
+ rewrittenPrompt = await rewritePrompt(prompt, enhancedSettings, { token, billTo }, selectedModel.value, selectedProvider.provider);
106
  }
107
 
108
  try {
components/editor/ask-ai/index.tsx CHANGED
@@ -1,14 +1,15 @@
1
- import { useMemo, useState } from "react";
2
  import classNames from "classnames";
3
  import {
4
  ArrowUp,
 
5
  CircleStop,
6
  Pause,
7
  Plus,
8
  Square,
9
  StopCircle,
10
  } from "lucide-react";
11
- import { useLocalStorage } from "react-use";
12
  import { toast } from "sonner";
13
 
14
  import { useAi } from "@/hooks/useAi";
@@ -61,6 +62,7 @@ export const AskAi = ({
61
  const { openProModal } = useProModal();
62
  const [openProvider, setOpenProvider] = useState(false);
63
  const [providerError, setProviderError] = useState("");
 
64
 
65
  const [enhancedSettings, setEnhancedSettings, removeEnhancedSettings] =
66
  useLocalStorage<EnhancedSettings>("deepsite-enhancedSettings", {
@@ -117,9 +119,9 @@ export const AskAi = ({
117
 
118
  if (result?.success) {
119
  setPrompt("");
120
- if (selectedModel?.isThinker) {
121
- setModel(MODELS[0].value);
122
- }
123
  }
124
  }
125
  };
@@ -147,9 +149,52 @@ export const AskAi = ({
147
  }
148
  };
149
 
 
 
 
 
 
 
150
  return (
151
  <div className="p-3 w-full">
152
  <div className="relative bg-neutral-800 border border-neutral-700 rounded-2xl ring-[4px] focus-within:ring-neutral-500/30 focus-within:border-neutral-600 ring-transparent z-20 w-full group">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  <SelectedFiles
154
  files={selectedFiles}
155
  isAiWorking={isAiWorking}
 
1
+ import { useMemo, useRef, useState } from "react";
2
  import classNames from "classnames";
3
  import {
4
  ArrowUp,
5
+ ChevronDown,
6
  CircleStop,
7
  Pause,
8
  Plus,
9
  Square,
10
  StopCircle,
11
  } from "lucide-react";
12
+ import { useLocalStorage, useUpdateEffect } from "react-use";
13
  import { toast } from "sonner";
14
 
15
  import { useAi } from "@/hooks/useAi";
 
62
  const { openProModal } = useProModal();
63
  const [openProvider, setOpenProvider] = useState(false);
64
  const [providerError, setProviderError] = useState("");
65
+ const refThink = useRef<HTMLDivElement>(null);
66
 
67
  const [enhancedSettings, setEnhancedSettings, removeEnhancedSettings] =
68
  useLocalStorage<EnhancedSettings>("deepsite-enhancedSettings", {
 
119
 
120
  if (result?.success) {
121
  setPrompt("");
122
+ // if (selectedModel?.isThinker) {
123
+ // setModel(MODELS[0].value);
124
+ // }
125
  }
126
  }
127
  };
 
149
  }
150
  };
151
 
152
+ useUpdateEffect(() => {
153
+ if (refThink.current) {
154
+ refThink.current.scrollTop = refThink.current.scrollHeight;
155
+ }
156
+ }, [think]);
157
+
158
  return (
159
  <div className="p-3 w-full">
160
  <div className="relative bg-neutral-800 border border-neutral-700 rounded-2xl ring-[4px] focus-within:ring-neutral-500/30 focus-within:border-neutral-600 ring-transparent z-20 w-full group">
161
+ {think && (
162
+ <div className="w-full border-b border-neutral-700 relative overflow-hidden">
163
+ <header
164
+ className="flex items-center justify-between px-5 py-2.5 group hover:bg-neutral-600/20 transition-colors duration-200 cursor-pointer"
165
+ onClick={() => {
166
+ setOpenThink(!openThink);
167
+ }}
168
+ >
169
+ <p className="text-sm font-medium text-neutral-300 group-hover:text-neutral-200 transition-colors duration-200">
170
+ {isThinking ? "DeepSite is thinking..." : "DeepSite's plan"}
171
+ </p>
172
+ <ChevronDown
173
+ className={classNames(
174
+ "size-4 text-neutral-400 group-hover:text-neutral-300 transition-all duration-200",
175
+ {
176
+ "rotate-180": openThink,
177
+ }
178
+ )}
179
+ />
180
+ </header>
181
+ <main
182
+ ref={refThink}
183
+ className={classNames(
184
+ "overflow-y-auto transition-all duration-200 ease-in-out",
185
+ {
186
+ "max-h-[0px]": !openThink,
187
+ "min-h-[250px] max-h-[250px] border-t border-neutral-700":
188
+ openThink,
189
+ }
190
+ )}
191
+ >
192
+ <p className="text-[13px] text-neutral-400 whitespace-pre-line px-5 pb-4 pt-3">
193
+ {think}
194
+ </p>
195
+ </main>
196
+ </div>
197
+ )}
198
  <SelectedFiles
199
  files={selectedFiles}
200
  isAiWorking={isAiWorking}
hooks/useAi.ts CHANGED
@@ -93,11 +93,18 @@ export const useAi = (onScrollToBottom?: () => void, livePreviewRef?: React.RefO
93
 
94
  const { data: model } = useQuery({
95
  queryKey: ["ai.model"],
96
- queryFn: async () => storageModel ?? MODELS[0].value,
 
 
 
 
 
 
 
97
  refetchOnWindowFocus: false,
98
  refetchOnReconnect: false,
99
  refetchOnMount: false,
100
- initialData: storageModel ?? MODELS[0].value
101
  });
102
  const setModel = (newModel: string) => {
103
  setStorageModel(newModel);
@@ -220,16 +227,16 @@ export const useAi = (onScrollToBottom?: () => void, livePreviewRef?: React.RefO
220
  }
221
  }
222
 
223
- if (selectedModel?.isThinker) {
224
- const thinkMatch = contentResponse.match(/<think>[\s\S]*/)?.[0];
225
- if (thinkMatch && !contentResponse?.includes("</think>")) {
226
- handleThink?.(thinkMatch.replace("<think>", "").trim());
227
- }
228
- }
229
-
230
- if (contentResponse.includes("</think>")) {
231
- onFinishThink?.();
232
- }
233
 
234
  formatPages(contentResponse);
235
 
 
93
 
94
  const { data: model } = useQuery({
95
  queryKey: ["ai.model"],
96
+ queryFn: async () => {
97
+ // check if the model exist in the MODELS array
98
+ const selectedModel = MODELS.find(m => m.value === storageModel || m.label === storageModel);
99
+ if (selectedModel) {
100
+ return selectedModel.value;
101
+ }
102
+ return MODELS[0].value;
103
+ },
104
  refetchOnWindowFocus: false,
105
  refetchOnReconnect: false,
106
  refetchOnMount: false,
107
+ initialData: undefined,
108
  });
109
  const setModel = (newModel: string) => {
110
  setStorageModel(newModel);
 
227
  }
228
  }
229
 
230
+ // if (selectedModel?.isThinker) {
231
+ // const thinkMatch = contentResponse.match(/<think>[\s\S]*/)?.[0];
232
+ // if (thinkMatch && !contentResponse?.includes("</think>")) {
233
+ // handleThink?.(thinkMatch.replace("<think>", "").trim());
234
+ // }
235
+ // }
236
+
237
+ // if (contentResponse.includes("</think>")) {
238
+ // onFinishThink?.();
239
+ // }
240
 
241
  formatPages(contentResponse);
242
 
hooks/useEditor.ts CHANGED
@@ -1,18 +1,18 @@
1
  import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
2
  import { useMemo } from "react";
3
- import { useLocalStorage, useUpdateEffect } from "react-use";
4
  import { toast } from "sonner";
5
  import { useRouter } from "next/navigation";
6
 
7
  import { defaultHTML } from "@/lib/consts";
8
- import { Commit, HtmlHistory, Page, Project } from "@/types";
9
  import { api } from "@/lib/api";
10
  import { isTheSameHtml } from "@/lib/compare-html-diff";
11
 
12
  export const useEditor = (namespace?: string, repoId?: string) => {
13
  const client = useQueryClient();
14
  const router = useRouter();
15
- const [pagesStorage,, removePagesStorage] = useLocalStorage<Page[]>("pages");
16
 
17
  const { data: project, isFetching: isLoadingProject } = useQuery({
18
  queryKey: ["editor.project"],
 
1
  import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
2
  import { useMemo } from "react";
3
+ import { useUpdateEffect } from "react-use";
4
  import { toast } from "sonner";
5
  import { useRouter } from "next/navigation";
6
 
7
  import { defaultHTML } from "@/lib/consts";
8
+ import { Commit, Page, Project } from "@/types";
9
  import { api } from "@/lib/api";
10
  import { isTheSameHtml } from "@/lib/compare-html-diff";
11
 
12
  export const useEditor = (namespace?: string, repoId?: string) => {
13
  const client = useQueryClient();
14
  const router = useRouter();
15
+ // const [pagesStorage,, removePagesStorage] = useLocalStorage<Page[]>("pages");
16
 
17
  const { data: project, isFetching: isLoadingProject } = useQuery({
18
  queryKey: ["editor.project"],
lib/providers.ts CHANGED
@@ -43,20 +43,20 @@ export const MODELS = [
43
  providers: ["fireworks-ai", "nebius", "sambanova", "novita", "hyperbolic"],
44
  autoProvider: "novita",
45
  },
46
- {
47
- value: "deepseek-ai/DeepSeek-R1-0528",
48
- label: "DeepSeek R1 0528",
49
- providers: [
50
- "fireworks-ai",
51
- "novita",
52
- "hyperbolic",
53
- "nebius",
54
- "together",
55
- "sambanova",
56
- ],
57
- autoProvider: "novita",
58
- isThinker: true,
59
- },
60
  {
61
  value: "Qwen/Qwen3-Coder-480B-A35B-Instruct",
62
  label: "Qwen3 Coder 480B A35B Instruct",
 
43
  providers: ["fireworks-ai", "nebius", "sambanova", "novita", "hyperbolic"],
44
  autoProvider: "novita",
45
  },
46
+ // {
47
+ // value: "deepseek-ai/DeepSeek-R1-0528",
48
+ // label: "DeepSeek R1 0528",
49
+ // providers: [
50
+ // "fireworks-ai",
51
+ // "novita",
52
+ // "hyperbolic",
53
+ // "nebius",
54
+ // "together",
55
+ // "sambanova",
56
+ // ],
57
+ // autoProvider: "novita",
58
+ // isThinker: true,
59
+ // },
60
  {
61
  value: "Qwen/Qwen3-Coder-480B-A35B-Instruct",
62
  label: "Qwen3 Coder 480B A35B Instruct",