PreQL NLP
Natural language interface for generating PreQL query objects.
PreQL is easier for a large language model to interact with as it requires only extract relevant concepts from a text, classifying them as metrics or dimensions, and mapping them to what is available in a model.
This makes it more testable and less prone to hallucination than generating SQL directly.
Requires setting the following environment variables
- OPENAI_API_KEY
- OPENAI_MODEL
Recommended to use "gpt-3.5-turbo" or higher as the model.
Examples
Basic BQ example
from trilogy_public_models import models
from preql import Executor, Dialects
from preql_nlp import build_query
# define the model we want to parse
environment = models["bigquery.stack_overflow"]
# set up preql executor
# default bigquery executor requires local default credentials configured
executor = Dialects.BIGQUERY.default_executor(environment= environment)
# build a query off text and the selected model
processed_query = build_query(
"How many questions are asked per year?",
environment,
)
# make sure we got reasonable outputs
for concept in processed_query.output_columns:
print(concept.name)
# and run that to get our answer
results = executor.execute_query(processed_query)
for row in results:
print(row)
Don't Expecct Perfection
Results are non-determistic and may not always be accurate.
# generated from prompt: What is Taylor Swift's birthday? How many questions were asked on that day in 2020?
SELECT
question.count,
answer.creation_date.year,
question.creation_date.year,
question.creation_date,
WHERE
question.creation_date.year = 1989
ORDER BY
question.count desc,
question.count desc
LIMIT 100;
Setting Up Your Environment
Recommend that you work in a virtual environment with requirements from both requirements.txt and requirements-test.txt installed. The latter is necessary to run tests (surprise).
Pypreql-nlp is python 3.10+
Metadata
Release files for pypreql-nlp 0.0.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pypreql_nlp-0.0.18.tar.gz | 28.2 kB | Without provenance | Details for pypreql_nlp-0.0.18.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypreql_nlp-0.0.18-py3-none-any.whl | Python 3 | none | any | Details for pypreql_nlp-0.0.18-py3-none-any.whl |
Total release size: 60.2 kB
Release files / pypreql_nlp-0.0.18.tar.gz
| Download URL | pypreql_nlp-0.0.18.tar.gz |
|---|---|
| Size | 28.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05c0041dbbf0b4c62efef30dda701416b8d3a5c05c819245f09b785cc3bb7104
|
|
BLAKE2b-256 checksum How to use checksums |
e1697a98166d9ef51bad7c0f13b7acabd96e39b96504f8d02ea06554e7b40a7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / pypreql_nlp-0.0.18-py3-none-any.whl
| Download URL | pypreql_nlp-0.0.18-py3-none-any.whl |
|---|---|
| Size | 32.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
107eda0f5f816d0242684e1e0206524dec1e5124f899f23a52a3239f164725d7
|
|
BLAKE2b-256 checksum How to use checksums |
01e30f2302e178ad312e8081a6481dc17c0751a7be66ee73102035bed1c00d23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Security for pypreql-nlp 0.0.18
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.