'use client'; import { useState } from 'react'; export default function GitHubUpload() { const [repo, setRepo] = useState(''); const [branch, setBranch] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(null); const [aiResponse, setAiResponse] = useState(null); const [aiLoading, setAiLoading] = useState(false); const handleUpload = async () => { setLoading(true); setError(null); setSuccess(null); setAiResponse(null); const response = await fetch('/api/github-upload', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ repo, branch }), }); const result = await response.json(); setLoading(false); if (response.ok) { setSuccess(result.message); } else { setError(result.error); } }; const getAiHelp = async () => { if (!error) return; setAiLoading(true); setAiResponse(null); const response = await fetch('/api/text-generation', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ prompt: `I encountered the following error while trying to upload to GitHub: "${error}". Please help me understand and resolve this issue.`, model: 'alias-fast', // Or any other suitable model }), }); if (!response.body) { setAiLoading(false); return; } const reader = response.body.getReader(); const decoder = new TextDecoder(); let done = false; let fullResponse = ''; while (!done) { const { value, done: readerDone } = await reader.read(); done = readerDone; const chunkValue = decoder.decode(value); fullResponse += chunkValue; setAiResponse(fullResponse); } setAiLoading(false); }; return (

Upload to GitHub

setRepo(e.target.value)} />
setBranch(e.target.value)} />
{error && (

Upload failed:

{error}

)} {aiResponse && (

AI Assistant says:

{aiResponse}

)} {success && (

{success}

)}
); }