Food Industry Lebanon AI
Food-safety guidance based on selected Lebanese and international
food-safety documents.
const FOODSAFE_API = "https://colin-pontiac-houston-pill.trycloudflare.com/ask";
async function askFoodSafetyAI() {
const question = document.getElementById("fs-question").value.trim();
const language = document.getElementById("fs-language").value;
const country = document.getElementById("fs-country").value;
const business = document.getElementById("fs-business").value;
const status = document.getElementById("fs-status");
const answerBox = document.getElementById("fs-answer");
const sourcesBox = document.getElementById("fs-sources");
const button = document.getElementById("fs-button");
if (!question) {
status.innerHTML = "Please enter a question.";
return; }
button.disabled = true;
status.innerHTML = "Searching food-safety documents and preparing answer...";
answerBox.style.display = "none";
sourcesBox.innerHTML = "";
try {
const response = await fetch( FOODSAFE_API, { method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ question: question, language: language, country: country, business_type: business }) } );
if (!response.ok) {
throw new Error( "Server returned error " + response.status ); }
const data = await response.json();
status.innerHTML = "";
answerBox.textContent = data.answer;
answerBox.style.display = "block";
if (data.sources && data.sources.length > 0) {
let html = "Sources retrieved
- ";
- " + source.document + " — page " + source.page + "
data.sources.forEach(source => {
html += "
";
});
html += "
";
sourcesBox.innerHTML = html; }
} catch (error) {
status.innerHTML =
"AI service unavailable.
" +
"Please try again later.";
console.error(error);
} finally {
button.disabled = false;
} }