Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while translating Human language into SQL #57

Open
mohit-choithwani opened this issue Dec 7, 2023 · 1 comment
Open

Error while translating Human language into SQL #57

mohit-choithwani opened this issue Dec 7, 2023 · 1 comment

Comments

@mohit-choithwani
Copy link

mohit-choithwani commented Dec 7, 2023

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
Copy link
Contributor

NattyXO commented Dec 25, 2023

Implemented Improvements waiting for Merge

  • Enhanced Error Logging: I've updated the error handling mechanism within the translateToSQL function to log more specific details about errors. Now, instead of logging [object Object], the code logs the entire error object or specific properties of the response object. This enhancement allows for a clearer understanding of the nature of any encountered errors.

  • API Response Inspection: I've included checks to inspect the response object or its properties received from the API call. This practice helps identify specific error messages or codes within the response, offering valuable insights into what might have caused the issue during translation.

  • Validated Inputs: To ensure the robustness of the translation process, I've implemented input validation checks for the query and apiKey parameters within the translateToSQL function. These checks verify that the necessary information is correctly provided, reducing the likelihood of unexpected behavior due to invalid or missing inputs.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants