MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / handleSubmit

Function handleSubmit

examples/nextjs/components/pipe-run-pipes-as-tools.tsx:12–43  ·  view source on GitHub ↗
(e: any)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected