Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	fix kimi
Browse files
    	
        app/api/ask-ai/route.ts
    CHANGED
    
    | @@ -223,7 +223,8 @@ export async function PUT(request: NextRequest) { | |
| 223 | 
             
              const userToken = request.cookies.get(MY_TOKEN_KEY())?.value;
         | 
| 224 |  | 
| 225 | 
             
              const body = await request.json();
         | 
| 226 | 
            -
              const { prompt, html, previousPrompt, provider, selectedElementHtml } = | 
|  | |
| 227 |  | 
| 228 | 
             
              if (!prompt || !html) {
         | 
| 229 | 
             
                return NextResponse.json(
         | 
| @@ -232,7 +233,15 @@ export async function PUT(request: NextRequest) { | |
| 232 | 
             
                );
         | 
| 233 | 
             
              }
         | 
| 234 |  | 
| 235 | 
            -
              const selectedModel = MODELS | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 236 |  | 
| 237 | 
             
              let token = userToken;
         | 
| 238 | 
             
              let billTo: string | null = null;
         | 
|  | |
| 223 | 
             
              const userToken = request.cookies.get(MY_TOKEN_KEY())?.value;
         | 
| 224 |  | 
| 225 | 
             
              const body = await request.json();
         | 
| 226 | 
            +
              const { prompt, html, previousPrompt, provider, selectedElementHtml, model } =
         | 
| 227 | 
            +
                body;
         | 
| 228 |  | 
| 229 | 
             
              if (!prompt || !html) {
         | 
| 230 | 
             
                return NextResponse.json(
         | 
|  | |
| 233 | 
             
                );
         | 
| 234 | 
             
              }
         | 
| 235 |  | 
| 236 | 
            +
              const selectedModel = MODELS.find(
         | 
| 237 | 
            +
                (m) => m.value === model || m.label === model
         | 
| 238 | 
            +
              );
         | 
| 239 | 
            +
              if (!selectedModel) {
         | 
| 240 | 
            +
                return NextResponse.json(
         | 
| 241 | 
            +
                  { ok: false, error: "Invalid model selected" },
         | 
| 242 | 
            +
                  { status: 400 }
         | 
| 243 | 
            +
                );
         | 
| 244 | 
            +
              }
         | 
| 245 |  | 
| 246 | 
             
              let token = userToken;
         | 
| 247 | 
             
              let billTo: string | null = null;
         | 
    	
        components/editor/ask-ai/index.tsx
    CHANGED
    
    | @@ -67,6 +67,10 @@ export function AskAI({ | |
| 67 | 
             
              const [controller, setController] = useState<AbortController | null>(null);
         | 
| 68 | 
             
              const [isFollowUp, setIsFollowUp] = useState(true);
         | 
| 69 |  | 
|  | |
|  | |
|  | |
|  | |
| 70 | 
             
              const callAi = async (redesignMarkdown?: string) => {
         | 
| 71 | 
             
                if (isAiWorking) return;
         | 
| 72 | 
             
                if (!redesignMarkdown && !prompt.trim()) return;
         | 
| @@ -178,7 +182,9 @@ export function AskAI({ | |
| 178 | 
             
                          setPrompt("");
         | 
| 179 | 
             
                          setisAiWorking(false);
         | 
| 180 | 
             
                          setHasAsked(true);
         | 
| 181 | 
            -
                           | 
|  | |
|  | |
| 182 | 
             
                          if (audio.current) audio.current.play();
         | 
| 183 |  | 
| 184 | 
             
                          // Now we have the complete HTML including </html>, so set it to be sure
         | 
| @@ -444,7 +450,7 @@ export function AskAI({ | |
| 444 | 
             
                            id="diff-patch-checkbox"
         | 
| 445 | 
             
                            checked={isFollowUp}
         | 
| 446 | 
             
                            onCheckedChange={(e) => {
         | 
| 447 | 
            -
                              if (e === true && !isSameHtml) {
         | 
| 448 | 
             
                                setModel(MODELS[0].value);
         | 
| 449 | 
             
                              }
         | 
| 450 | 
             
                              setIsFollowUp(e === true);
         | 
|  | |
| 67 | 
             
              const [controller, setController] = useState<AbortController | null>(null);
         | 
| 68 | 
             
              const [isFollowUp, setIsFollowUp] = useState(true);
         | 
| 69 |  | 
| 70 | 
            +
              const selectedModel = useMemo(() => {
         | 
| 71 | 
            +
                return MODELS.find((m: { value: string }) => m.value === model);
         | 
| 72 | 
            +
              }, [model]);
         | 
| 73 | 
            +
             | 
| 74 | 
             
              const callAi = async (redesignMarkdown?: string) => {
         | 
| 75 | 
             
                if (isAiWorking) return;
         | 
| 76 | 
             
                if (!redesignMarkdown && !prompt.trim()) return;
         | 
|  | |
| 182 | 
             
                          setPrompt("");
         | 
| 183 | 
             
                          setisAiWorking(false);
         | 
| 184 | 
             
                          setHasAsked(true);
         | 
| 185 | 
            +
                          if (selectedModel?.isThinker) {
         | 
| 186 | 
            +
                            setModel(MODELS[0].value);
         | 
| 187 | 
            +
                          }
         | 
| 188 | 
             
                          if (audio.current) audio.current.play();
         | 
| 189 |  | 
| 190 | 
             
                          // Now we have the complete HTML including </html>, so set it to be sure
         | 
|  | |
| 450 | 
             
                            id="diff-patch-checkbox"
         | 
| 451 | 
             
                            checked={isFollowUp}
         | 
| 452 | 
             
                            onCheckedChange={(e) => {
         | 
| 453 | 
            +
                              if (e === true && !isSameHtml && selectedModel?.isThinker) {
         | 
| 454 | 
             
                                setModel(MODELS[0].value);
         | 
| 455 | 
             
                              }
         | 
| 456 | 
             
                              setIsFollowUp(e === true);
         | 
