From 76541acfcefe9f24374ae9c1fae7a582c4a8c146 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Fri, 15 Aug 2025 11:24:27 +0200 Subject: [PATCH] Applied ruff format to the Python files --- 01-hello/src/entry.py | 5 +++-- 02-binding/src/entry.py | 9 +++++---- 04-langchain/src/worker.py | 13 ++++++++----- 05-query-d1/src/entry.py | 13 +++++++------ 06-vendoring/src/worker.py | 6 +++--- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/01-hello/src/entry.py b/01-hello/src/entry.py index 7837417..1938022 100644 --- a/01-hello/src/entry.py +++ b/01-hello/src/entry.py @@ -1,5 +1,6 @@ from workers import WorkerEntrypoint, Response + class Default(WorkerEntrypoint): - async def fetch(self, request, env): - return Response("Hello world!") + async def fetch(self, request, env): + return Response("Hello world!") diff --git a/02-binding/src/entry.py b/02-binding/src/entry.py index 5218af0..e41ad63 100644 --- a/02-binding/src/entry.py +++ b/02-binding/src/entry.py @@ -1,7 +1,8 @@ from workers import WorkerEntrypoint, Response + class Default(WorkerEntrypoint): - async def fetch(selfrequest, env): - await env.FOO.put("bar", "baz") - bar = await env.FOO.get("bar") - return Response(bar) # returns "baz" + async def fetch(selfrequest, env): + await env.FOO.put("bar", "baz") + bar = await env.FOO.get("bar") + return Response(bar) # returns "baz" diff --git a/04-langchain/src/worker.py b/04-langchain/src/worker.py index 3a029db..ea6d95a 100644 --- a/04-langchain/src/worker.py +++ b/04-langchain/src/worker.py @@ -2,11 +2,14 @@ from langchain_core.prompts import PromptTemplate from langchain_openai import OpenAI + @handler async def on_fetch(request, env): - prompt = PromptTemplate.from_template("Complete the following sentence: I am a {profession} and ") - llm = OpenAI(api_key=env.API_KEY) - chain = prompt | llm + prompt = PromptTemplate.from_template( + "Complete the following sentence: I am a {profession} and " + ) + llm = OpenAI(api_key=env.API_KEY) + chain = prompt | llm - res = await chain.ainvoke({"profession": "electrician"}) - return Response(res.split(".")[0].strip()) + res = await chain.ainvoke({"profession": "electrician"}) + return Response(res.split(".")[0].strip()) diff --git a/05-query-d1/src/entry.py b/05-query-d1/src/entry.py index 2bc355e..e2987b2 100644 --- a/05-query-d1/src/entry.py +++ b/05-query-d1/src/entry.py @@ -1,15 +1,16 @@ from workers import WorkerEntrypoint, Response + class Default(WorkerEntrypoint): - async def fetch(self, request, env): - query = """ + async def fetch(self, request, env): + query = """ SELECT quote, author FROM qtable ORDER BY RANDOM() LIMIT 1; """ - results = await env.DB.prepare(query).all() - data = results.results[0] + results = await env.DB.prepare(query).all() + data = results.results[0] - # Return a JSON response - return Response.json(data) + # Return a JSON response + return Response.json(data) diff --git a/06-vendoring/src/worker.py b/06-vendoring/src/worker.py index 75420d9..2293d84 100644 --- a/06-vendoring/src/worker.py +++ b/06-vendoring/src/worker.py @@ -7,10 +7,10 @@ class Default(WorkerEntrypoint): - async def fetch(self, request, env): - import asgi + async def fetch(self, request, env): + import asgi - return await asgi.fetch(app, request, env) + return await asgi.fetch(app, request, env) app = FastAPI()