-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db-tabulator: rename js preprocess to postprocess for clarity
- Loading branch information
1 parent
387156f
commit 236071d
Showing
4 changed files
with
81 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h2>AutoSQL</h2> | ||
<form action="/autosql/generate" method="POST"> | ||
<div> | ||
<label for="query-english"> | ||
Enter your query in English to get the corresponding SQL: | ||
</label> | ||
<br> | ||
<br> | ||
</div> | ||
<textarea id="query-english" name="prompt" rows="4" cols="100"></textarea> | ||
<br> | ||
<br> | ||
<div> | ||
<button type="submit" class="sd-button">Generate SQL</button> | ||
</div> | ||
</form> |
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,17 @@ | ||
<div style="max-width: 800px"> | ||
<p>The generated SQL query is given below. Mistakes are possible. Use with caution.</p> | ||
<br> | ||
|
||
<pre>{{sql}}</pre> | ||
|
||
<a href="https://quarry.wmcloud.org/" target="_blank"> | ||
<button> | ||
Test it in Quarry | ||
</button> | ||
</a> | ||
|
||
{{#if warnOnField}} | ||
<br> | ||
<p>NOTE: The above SQL may need adjustments for schema normalization, as the AI does not know that <code>{{warnOnField}}</code> field is no longer available. The field needs to be replaced with use of <code>link_target</code> table. See <a href="https://phabricator.wikimedia.org/T300222">phab:T300222</a>.</p> | ||
{{/if}} | ||
</div> |
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,46 @@ | ||
import * as express from "express"; | ||
import 'express-async-errors'; | ||
import OpenAI from "openai"; | ||
import {AuthManager, log} from "../../botbase"; | ||
|
||
const router = express.Router(); | ||
|
||
const client = new OpenAI({ | ||
apiKey: AuthManager.get('openai').key | ||
}); | ||
|
||
router.get('/', async function (req, res) { | ||
return res.render('db-tabulator/autosql/landing') | ||
}); | ||
|
||
router.post('/generate', async function (req, res, next) { | ||
if (!req.body.prompt) { | ||
return res.status(400).render('webservice/views/oneline', { | ||
text: 'Bad request: required parameter "prompt" missing' | ||
}) | ||
} | ||
const response = await client.chat.completions.create({ | ||
messages: [{ | ||
role: 'user', | ||
content: | ||
'Using MediaWiki\'s db schema outlined at https://www.mediawiki.org/wiki/Manual:Database_layout, write an SQL query to perform the below-mentioned. Respond only with the SQL query.\n\n' + | ||
req.body.prompt | ||
}], | ||
model: 'gpt-3.5-turbo', | ||
}) | ||
const sql = response.choices[0].message.content | ||
const logEntry = { | ||
prompt: req.query.prompt, | ||
response: sql | ||
|
||
} | ||
return res.render('db-tabulator/autosql/result', { | ||
sql: sql, | ||
warnOnField: | ||
sql.includes('pl_title') ? 'pl_title' : | ||
sql.includes('tl_title') ? 'tl_title' : | ||
null | ||
}) | ||
}); | ||
|
||
export default router; |
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