(e: any)
| 8 | const [loading, setLoading] = useState(false); |
| 9 | |
| 10 | const handleSubmit = async (e: any) => { |
| 11 | e.preventDefault(); |
| 12 | if (!prompt.trim()) return; |
| 13 | |
| 14 | setLoading(true); |
| 15 | try { |
| 16 | const response = await fetch('/api/langbase/pipes/run', { |
| 17 | method: 'POST', |
| 18 | headers: {'Content-Type': 'application/json'}, |
| 19 | // Send prompt as an LLM message. |
| 20 | body: JSON.stringify({ |
| 21 | messages: [{role: 'user', content: prompt}], |
| 22 | }), |
| 23 | }); |
| 24 | |
| 25 | if (!response.ok) { |
| 26 | throw new Error('Network response was not ok'); |
| 27 | } |
| 28 | |
| 29 | // Parse the JSON response. |
| 30 | const data = await response.json(); |
| 31 | setCompletion(data.completion); |
| 32 | } catch (error) { |
| 33 | console.error('Error:', error); |
| 34 | setCompletion('An error occurred while generating the completion.'); |
| 35 | } finally { |
| 36 | setLoading(false); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | return ( |
| 41 | <div className="bg-neutral-200 rounded-md p-2 flex flex-col gap-2 w-full"> |
no outgoing calls
no test coverage detected