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

Function handleSubmit

examples/remix/app/components/pipe-run-with-tool.tsx:12–40  ·  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('/api/langbase/pipes/run-tool', {
19 method: 'POST',
20 headers: { 'Content-Type': 'application/json' },
21 // Send prompt as an LLM message.
22 body: JSON.stringify({
23 messages: [{ role: 'user', content: prompt }],
24 }),
25 });
26
27 if (!response.ok) {
28 throw new Error('Network response was not ok');
29 }
30
31 // Parse the JSON response.
32 const data = await response.json();
33 setCompletion(data.completion);
34 } catch (error) {
35 console.error('Error:', error);
36 setCompletion('An error occurred while generating the completion.');
37 } finally {
38 setLoading(false);
39 }
40 };
41
42 return (
43 <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