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

Function handleSubmit

examples/nextjs/components/pipe-run.tsx:12–44  ·  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', {
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 const res = await response.json();
29 throw new Error(res.error.error.message);
30 }
31
32 // Parse the JSON response.
33 const data = await response.json();
34 setCompletion(data.completion);
35 } catch (error: any) {
36 if (error.message) setCompletion(error.message);
37 else
38 setCompletion(
39 'An error occurred while generating the completion.',
40 );
41 } finally {
42 setLoading(false);
43 }
44 };
45
46 return (
47 <div className="bg-neutral-200 rounded-md p-2 flex flex-col gap-2 w-full">

Callers 1

ChatAdvancedFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected