(feat:search bar) initiating seach bar

This commit is contained in:
ManishMadan2882
2024-11-14 04:52:15 +05:30
parent 541a6417b7
commit 9409e4498f
8 changed files with 257 additions and 15 deletions

View File

@@ -0,0 +1,34 @@
import { Result } from "@/types";
async function getSearchResults(question: string, apiKey:string, apiHost:string): Promise<Result[]> {
const payload = {
question,
api_key:apiKey
};
try {
const response = await fetch(`${apiHost}/api/search`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`Error: ${response.status}`);
}
const data: Result[] = await response.json();
return data;
} catch (error) {
console.error("Failed to fetch documents:", error);
throw error;
}
}
export {
getSearchResults
}