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

Function handleSubmit

examples/astro/src/components/pipe-run.tsx:10–38  ·  view source on GitHub ↗
(e: any)

Source from the content-addressed store, hash-verified

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">

Callers 1

ChatAdvancedExampleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected