Skip to content

Working NLQ demo - #24

Merged
Ulthran merged 1 commit into
mainfrom
codex/plan-implementation-for-natural-language-query-feature
Aug 6, 2025
Merged

Working NLQ demo#24
Ulthran merged 1 commit into
mainfrom
codex/plan-implementation-for-natural-language-query-feature

Conversation

@Ulthran

@Ulthran Ulthran commented Aug 6, 2025

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings August 6, 2025 02:17
@Ulthran
Ulthran merged commit a7e3ed4 into main Aug 6, 2025
1 of 6 checks passed
@Ulthran
Ulthran deleted the codex/plan-implementation-for-natural-language-query-feature branch August 6, 2025 02:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a Natural Language Query (NLQ) feature that allows users to convert natural language questions into SQL queries using LangChain and GPT-4o. The implementation adds a new form interface for natural language input and integrates AI-powered SQL generation capabilities.

  • Replaces simple pattern-matching NLQ with AI-powered query generation using LangChain and OpenAI
  • Adds a new natural language query form to the query interface with help tooltips
  • Implements both fresh query generation and query modification functionality

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
app/templates/query.html Adds natural language query form with help tooltip and adjusts layout styling
app/static/query_editor.js Adds debug console logging and enables line wrapping in the code editor
app/nl_query.py Complete rewrite to use LangChain/OpenAI for AI-powered SQL generation with structured output
app/app.py Updates API endpoint to handle both fresh query generation and query modification scenarios

Comment thread app/templates/query.html
<form class="d-flex flex-column w-100" method="POST" action="{{ url_for('query') }}">
<label class="p-2">Custom Query</label>
<input type="hidden" id="query-input" name="query" value="{{ query }}">
<div id="query-editor" class="w-100 border" style="height: 300px; max-width: 300;"></div>

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The max-width CSS property is missing a unit (px, %, em, etc.). It should be 'max-width: 300px;' or another appropriate unit.

Suggested change
<div id="query-editor" class="w-100 border" style="height: 300px; max-width: 300;"></div>
<div id="query-editor" class="w-100 border" style="height: 300px; max-width: 300px;"></div>

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +11
console.log("Keywords:", keywords);
console.log("Tables:", tables);

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug console.log statements should be removed from production code as they can clutter the browser console and potentially expose sensitive information.

Suggested change
console.log("Keywords:", keywords);
console.log("Tables:", tables);

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +11
console.log("Keywords:", keywords);
console.log("Tables:", tables);

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug console.log statements should be removed from production code as they can clutter the browser console and potentially expose sensitive information.

Suggested change
console.log("Keywords:", keywords);
console.log("Tables:", tables);

Copilot uses AI. Check for mistakes.
Comment thread app/nl_query.py

def generate_sql_modification(question: str, starting_query: str) -> str:
graph_builder = StateGraph(State)
graph_builder.add_node("modify_query", write_query)

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The modify_query node is incorrectly calling write_query function instead of modify_query function. This should be modify_query to properly handle query modifications.

Suggested change
graph_builder.add_node("modify_query", write_query)
graph_builder.add_node("modify_query", modify_query)

Copilot uses AI. Check for mistakes.
Comment thread app/nl_query.py
sql = _to_sql(question)
result = session.execute(text(sql)).fetchall()
return {"sql": sql, "result": [dict(row._mapping) for row in result]}
llm = ChatOpenAI(

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OpenAI API key should be configured through environment variables or secure configuration rather than relying on default authentication. Consider explicitly setting the api_key parameter or ensuring OPENAI_API_KEY environment variable is properly configured.

Copilot uses AI. Check for mistakes.
Comment thread app/app.py
Comment on lines +233 to +239
return generate_sql(question), 200
except Exception as e:
print(f"Error creating NL query: {e}")
return {"error": "Query generation failed"}, 500
else:
try:
return generate_sql_modification(question, starting_query), 200

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API returns inconsistent response formats. When successful, it returns just the SQL string, but on error it returns a dictionary with an 'error' key. Consider wrapping the successful response in a consistent format like {'query': generate_sql(question)}.

Copilot uses AI. Check for mistakes.
Comment thread app/app.py
Comment on lines +233 to +239
return generate_sql(question), 200
except Exception as e:
print(f"Error creating NL query: {e}")
return {"error": "Query generation failed"}, 500
else:
try:
return generate_sql_modification(question, starting_query), 200

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API returns inconsistent response formats. When successful, it returns just the SQL string, but on error it returns a dictionary with an 'error' key. Consider wrapping the successful response in a consistent format like {'query': generate_sql_modification(question, starting_query)}.

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

2 participants