-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add sql completions powered by LLM (#1514)
* feat: add sql completions powered by LLM * fix linter * fix linter * address comment
- Loading branch information
Showing
16 changed files
with
251 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
querybook/server/lib/ai_assistant/prompts/sql_complete_prompt.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from langchain.prompts import PromptTemplate | ||
|
||
prompt_template = """You are an expert in the {dialect} SQL dialect, skilled in providing precise SQL code completions. | ||
Your task is to complete the SQL query based on the given context. | ||
<Prefix><FILL_ME><Suffix> | ||
===Table Schemas | ||
{table_schemas} | ||
===Response Guidelines: | ||
1. Analyze the partial query and table schemas to understand the context and determine the query's goal. | ||
2. Identify the relevant tables and columns necessary for the query. | ||
3. Replace <FILL_ME> with appropriate SQL code, or leave it empty if no completion is needed. | ||
4. Make sure the completion does not overlap with the prefix or suffix. | ||
5. Respond in JSON format | ||
===Response Format: | ||
{{ | ||
"completion": "the SQL code to replace <FILL_ME>, if any" | ||
}} | ||
===Example | ||
Input: | ||
sele<FILL_ME> from some_table | ||
Reasoning: | ||
The prefix "sele" suggests that the query is likely a SELECT statement. The table schemas indicate the available columns. The completion should be a list of columns to select from the table "some_table". | ||
As it already has a partial query, the completion should be starting from "ct" to complete the word "select", and then followed by the columns to select. | ||
Output: | ||
{{ | ||
"completion": "ct *" | ||
}} | ||
===Input | ||
{prefix}<FILL_ME>{suffix} | ||
""" | ||
|
||
|
||
SQL_AUTOCOMPLETE_PROMPT = PromptTemplate.from_template(prompt_template) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
querybook/webapp/hooks/queryEditor/extensions/useCopilotExtension.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.