Skip to content

Commit d5398e4

Browse files
committed
added backup webservice
Signed-off-by: Arya Pratap Singh <notaryasingh@gmail.com>
1 parent 8a1a587 commit d5398e4

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

frontend-interface/app/page.tsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ const DSASolutionInterface = () => {
6666

6767
setLoading(true);
6868
try {
69-
const response = await fetch("https://learn-coding-with-copilotkit.onrender.com/copilotkit", {
69+
70+
71+
72+
const response = await fetch("https://novel-tasia-arya007-ab53373f.koyeb.app/copilotkit", {
7073
method: "POST",
7174
headers: {
7275
"Content-Type": "application/json",
@@ -94,14 +97,55 @@ const DSASolutionInterface = () => {
9497
setSolution({
9598
code: cleanCode,
9699
explanation: data.explanation || "",
97-
visualization: cleanVisualization,
100+
visualization: cleanVisualization,https://novel-tasia-arya007-ab53373f.koyeb.app/copilotkit
98101
});
99102

100103
setTimeComplexity(data.time_complexity || "O(1)");
101104
setSpaceComplexity(data.space_complexity || "O(1)");
102105
setEditorCode(cleanCode);
103106
} catch (error) {
104-
console.error("Error:", error);
107+
108+
try {
109+
110+
const response = await fetch("https://learn-coding-with-copilotkit.onrender.com/copilotkit", {
111+
method: "POST",
112+
headers: {
113+
"Content-Type": "application/json",
114+
Accept: "application/json",
115+
},
116+
credentials: "include",
117+
body: JSON.stringify({
118+
question,
119+
testCases: testCases.map((tc) => tc.input),
120+
}),
121+
});
122+
123+
if (!response.ok) {
124+
throw new Error(`HTTP error! status: ${response.status}`);
125+
}
126+
127+
const data = await response.json();
128+
129+
const cleanCode = (data.code || "").replace(/```python\n?|\n?```/g, "");
130+
const cleanVisualization = (data.visualization || "").replace(
131+
/```mermaid\n?|\n?```/g,
132+
""
133+
);
134+
135+
setSolution({
136+
code: cleanCode,
137+
explanation: data.explanation || "",
138+
visualization: cleanVisualization,
139+
});
140+
141+
setTimeComplexity(data.time_complexity || "O(1)");
142+
setSpaceComplexity(data.space_complexity || "O(1)");
143+
setEditorCode(cleanCode);
144+
}
145+
catch (error) {
146+
console.error(error);
147+
}
148+
105149
} finally {
106150
setLoading(false);
107151
}

0 commit comments

Comments
 (0)