Install the SDK.
Install and run the Server.
Write code.
#app-node.py
from flask import Flask, request, jsonify
from resonate.storage.resonate_server import RemoteServer
from resonate.Resonate import Resonate
from resonate.context import Context
# Initialize Resonate Scheduler
const resonate = new Resonate(RemoteServer(url="http://localhost:8001"));
# Define your workflow
def downloadAndSummarize(ctx: Context, url: str):
content = yield ctx.lfc(url)
summary = yield ctx.lfc(content)
return summary
def download(ctx: Context, url: str):
return f"This is the downloaded content."
def summarize(ctx: Context, content: str):
return f"This is the summary."
# Register the downloadAndSummarize function with the Resonate scheduler
resonate.register(
name="downloadAndSummarize",
func=downloadAndSummarize,
)
# Define a route handler for the /summarize endpoint
@app.route("/summarize", methods=["POST"])
def summarize_route_handler():
try:
data = request.get_json()
if "url" not in data:
return jsonify({"error": "URL not provided"}), 400
url = data["url"]
promise = resonate.run(
f"downloadAndSummarize-{url}", downloadAndSummarize, url=url
)
return jsonify({"summary": promise.result()})
except Exception as e:
return jsonify({"error": str(e)}), 500
def main():
app.run(host="127.0.0.1", port=5000)
print("Serving HTTP on port 5000...")
if __name__ == "__main__":
main()
Continue building an AI summarization agent with the quickstart tutorial.