NLP interface for pypreql.
Project description
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, default_engine, Dialect
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 = Dialect.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)
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+
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pypreql_nlp-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dd90276447a9ccee4b54ea7995a42ad9b40d48f57f52e4861b6926ccdff1c43 |
|
MD5 | 9873e71bd4d323d834f4b97daf61b54c |
|
BLAKE2b-256 | 8dff34a77592d457d6ca4038fc2cc6c9fbfe13d473aaa4ff1418ea8d2952e182 |