whoiskatrin / sql-translator

SQL Translator is a tool for converting natural language queries into SQL code using artificial intelligence. This project is 100% free and open source.
https://www.sqltranslate.app/
MIT License
4.19k stars 358 forks source link

Error while translating Human language into SQL #57

Open mohit-choithwani opened 10 months ago

mohit-choithwani commented 10 months ago

Thanks for the awesome repository! I've followed all the steps, and I've successfully loaded the page on localhost. However, when attempting to convert human language into SQL, I encountered the following error. sql-error

NattyXO commented 10 months ago

Implemented Improvements waiting for Merge

Here's a snippet of the enhanced error handling and logging within the translateToSQL function:

const translateToSQL = async (query, apiKey, tableSchema = "") => {
  // ... (existing code)

  const response = await fetch("https://api.openai.com/v1/completions", {
    // ... (existing fetch options)
  });

  const data = await response.json();
  if (!response.ok) {
    console.error("API Error:", response.status, data);
    // Specific error details are now logged for better debugging
    throw new Error(data.error || "Error translating to SQL. Further details logged in the console.");
  }

  return data.choices[0].text.trim();
};

export default translateToSQL;

These enhancements have significantly improved the error handling and validation aspects of the translateToSQL function, ensuring a more robust and reliable translation process.