Learning how to leverage secrets and images on Tensorlake Serverless.
workflow.py
, we write three functions:
scrape_website
will leverage https://jina.ai/reader/ to parse websites into text.summarize_text
will leverage OpenAI’s chatgpt to summarize the text outputted from scrape_website
.extract_structured_data
will leverage OpenAI’s chatgpt to extract structured data defined as a Python class from the text outputted from scrape_website
.website-summarizer
executes the scrape_website
function, and then executes both the summarize_text
and extract_structured_data
in parallel with the output of the scraper.
pip install openai
to install the OpenAI SDK.
Additionally, the OpenAI SDK requires the OPENAI_API_KEY
environment variable:
python workflow.py
will execute the workflow locally and print the outputs. There are two print statements
for this graph: one for the text summarization text and one for the structured extraction.
tensorlake_function
requires when running on the Tensorlake Cloud.
tensorlake_function
decorator, we also moved imports within each function.This allows creating smaller per-function images without needing to have all the dependencies in all images therefore reducing cold-start when big dependencies are needed like AI models.OPENAI_API_KEY
environment variable containing a sensitive value.
Tensorlake Serverless provides the concept of secrets that are injected at runtime into functions depending on them.
Secrets are encrypted and only decrypted to be injected into functions.
Create the tensorlake secret using the Tensorlake CLI:
summarize_text
and extract_structured_data
functions.
scrape_website
, so
the input to the graph is the url
parameter.
The result of calling a graph is an Invocation
. Since data applications can take a long time to complete,
calling outputs
on an invocation will wait for the invocation to be complete.
In either case, the result of the individual functions can be retrieved using the invocation id, and the name of the function.