You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2023/04/04 10:36:29 UTC
[superset] 02/03: WIP
This is an automated email from the ASF dual-hosted git repository.
diegopucci pushed a commit to branch feat/sqllab-natural-language
in repository https://gitbox.apache.org/repos/asf/superset.git
commit ac7bb02b52f382c8f71b6f3b544c30f3e36eca0f
Author: geido <di...@gmail.com>
AuthorDate: Fri Feb 24 16:09:13 2023 +0100
WIP
---
.../src/SqlLab/components/SqlEditor/index.jsx | 19 +++++++------------
.../components/nativeFilters/FilterBar/Vertical.tsx | 8 ++++----
superset/sqllab/api.py | 5 +++--
3 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx b/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx
index d517b4e939..b1f8c0532c 100644
--- a/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx
+++ b/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx
@@ -651,7 +651,7 @@ const SqlEditor = ({
const [NLPLoading, setNLPLoading] = useState(false);
const handleNLPGeneration = async () => {
setNLPLoading(true);
- let tablesContext = "# Given the following table/s definition\n\n";
+ let tablesContext = "";
for(let t = 0; t < tables.length; t += 1) {
const table = tables[t];
if (table?.columns?.length) {
@@ -664,12 +664,7 @@ const SqlEditor = ({
tablesContext += `\n\n`;
}
}
- tablesContext += `# Create one valid SQL SELECT statement with the following constraints\n`;
- tablesContext += `# For example: SELECT column FROM table;\n`;
- tablesContext += `# Do NOT generate more tha one SELECT statement\n`;
- tablesContext += `# Do NOT generate any text other than one valid SELECT statement\n`;
- tablesContext += `# Do ONLY use SELECT\n`;
- tablesContext += `# Respond with a SQL statement to select ${NLPQuery} from the given tables ->`;
+ tablesContext += `# Create a SQLite query to: ${NLPQuery}`;
const postPayload = {
prompt: tablesContext,
}
@@ -680,8 +675,8 @@ const SqlEditor = ({
parseMethod: 'json-bigint',
})
.then(({ json }) => {
- setNLPResult(json.result);
- setEditorType('sql')
+ setEditorType('sql');
+ setNLPResult(json.result.trim());
setNLPLoading(false);
})
.catch(() => {
@@ -690,7 +685,7 @@ const SqlEditor = ({
console.log(tablesContext);
}
- const renderNLPMenu = (
+ const renderNLPMenu = useMemo(() => (
<Menu
mode="horizontal"
defaultSelectedKeys={[editorType]}
@@ -715,7 +710,7 @@ const SqlEditor = ({
Natural language
</Menu.Item>
</Menu>
- );
+ ), [NLPLoading, editorType]);
const renderNLPBottomBar = (
tables.length > 0 ? <Button
@@ -740,7 +735,7 @@ const SqlEditor = ({
disabled={NLPLoading}
rows={6}
onChange={e => setNLPQuery(e.target.value)}
- placeholder="Get all fruits from the tree..."
+ placeholder="Select all names from table"
/>
) : (
<Result
diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Vertical.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Vertical.tsx
index 2a6b717836..3b209dfcff 100644
--- a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Vertical.tsx
+++ b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Vertical.tsx
@@ -244,12 +244,12 @@ const VerticalFilterBar: React.FC<VerticalBarProps> = ({
{filterValues.length === 0 ? (
<FilterBarEmptyStateContainer>
<EmptyStateSmall
- title={t('No filters are currently added')}
+ title={t('No global filters are currently added')}
image="filter.svg"
description={
canEdit &&
t(
- 'Click the button above to add a filter to the dashboard',
+ 'Click on "+Add/Edit Filters" button to create new dashboard filters',
)
}
/>
@@ -286,12 +286,12 @@ const VerticalFilterBar: React.FC<VerticalBarProps> = ({
{filterValues.length === 0 ? (
<FilterBarEmptyStateContainer>
<EmptyStateSmall
- title={t('No filters are currently added')}
+ title={t('No global filters are currently added')}
image="filter.svg"
description={
canEdit &&
t(
- 'Click the button above to add a filter to the dashboard',
+ 'Click on "+Add/Edit Filters" button to create new dashboard filters',
)
}
/>
diff --git a/superset/sqllab/api.py b/superset/sqllab/api.py
index dd659d753c..2179cec159 100644
--- a/superset/sqllab/api.py
+++ b/superset/sqllab/api.py
@@ -127,10 +127,11 @@ class SqlLabRestApi(BaseSupersetApi):
openai.api_key = "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"
requestPrompt = request.json
completion = openai.Completion.create(
- engine="code-davinci-002",
+ engine="text-davinci-003",
prompt=requestPrompt['prompt'],
max_tokens=100,
- temperature=0
+ temperature=0.1,
+ stop="END"
)
choice = {**completion.choices[0]}
payload = {