Skip to content

Commit

Permalink
Moves over h_async to hamiton.async_driver
Browse files Browse the repository at this point in the history
Its time we support this.

Decisions:
1. Did not want to keep it in hamilton.driver, that's getting too
   bloated and there's name collision
2. Moved over docs to point to the right place (as much as I could)
3. Left it backwards compatible with a warning to update the import
  • Loading branch information
elijahbenizzy committed Jun 26, 2024
1 parent c330c85 commit 9ebd205
Show file tree
Hide file tree
Showing 15 changed files with 515 additions and 540 deletions.
5 changes: 0 additions & 5 deletions .ci/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ if [[ ${TASK} != "pre-commit" ]]; then
-r requirements-test.txt
fi

if [[ ${TASK} == "async" ]]; then
pip install \
-r plugin_tests/h_async/requirements-test.txt
fi

if [[ ${TASK} == "pyspark" ]]; then
if [[ ${OPERATING_SYSTEM} == "Linux" ]]; then
sudo apt-get install \
Expand Down
24 changes: 0 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,3 @@ workflows:
name: integrations-py312
python-version: '3.12'
task: integrations
- test:
requires:
- check_for_changes
name: asyncio-py39
python-version: '3.9'
task: async
- test:
requires:
- check_for_changes
name: asyncio-py310
python-version: '3.10'
task: async
- test:
requires:
- check_for_changes
name: asyncio-py311
python-version: '3.11'
task: async
- test:
requires:
- check_for_changes
name: asyncio-py312
python-version: '3.12'
task: async
4 changes: 2 additions & 2 deletions docs/code-comparisons/langchain_snippets/hamilton_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ async def joke_response(
import hamilton_async

from hamilton import base
from hamilton.experimental import h_async
from hamilton import async_driver

dr = h_async.AsyncDriver(
dr = async_driver.AsyncDriver(
{},
hamilton_async,
result_builder=base.DictResult()
Expand Down
12 changes: 4 additions & 8 deletions examples/async/fastapi_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from aiohttp import client_exceptions
from hamilton_sdk import adapters

from hamilton.experimental import h_async
from hamilton import async_driver

logger = logging.getLogger(__name__)

# can instantiate a driver once for the life of the app:
dr_with_tracking: h_async.AsyncDriver = None
dr_without_tracking: h_async.AsyncDriver = None
dr_with_tracking: async_driver.AsyncDriver = None
dr_without_tracking: async_driver.AsyncDriver = None


async def _tracking_server_running():
Expand All @@ -36,7 +36,7 @@ async def lifespan(app: fastapi.FastAPI):
"""
global dr_with_tracking
global dr_without_tracking
builder = h_async.Builder().with_modules(async_module)
builder = async_driver.Builder().with_modules(async_module)
is_server_running = await _tracking_server_running()
dr_without_tracking = await builder.build()
dr_with_tracking = (
Expand Down Expand Up @@ -66,8 +66,6 @@ async def lifespan(app: fastapi.FastAPI):
async def call_without_tracker(request: fastapi.Request) -> dict:
"""Handler for pipeline call -- this does not track in the Hamilton UI"""
input_data = {"request": request}
# Can instantiate a driver within a request as well:
# dr = h_async.AsyncDriver({}, async_module, result_builder=base.DictResult())
result = await dr_without_tracking.execute(["pipeline"], inputs=input_data)
# dr.visualize_execution(["pipeline"], "./pipeline.dot", {"format": "png"}, inputs=input_data)
return result
Expand All @@ -77,8 +75,6 @@ async def call_without_tracker(request: fastapi.Request) -> dict:
async def call_with_tracker(request: fastapi.Request) -> dict:
"""Handler for pipeline call -- this does track in the Hamilton UI."""
input_data = {"request": request}
# Can instantiate a driver within a request as well:
# dr = h_async.AsyncDriver({}, async_module, result_builder=base.DictResult())
if dr_with_tracking is None:
raise ValueError(
"Tracking driver not initialized -- you must have the tracking server running at app startup to use this endpoint."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import pandas as pd
import pydantic

from hamilton import base
from hamilton.experimental import h_async
from hamilton import async_driver, base

app = fastapi.FastAPI()

Expand Down Expand Up @@ -56,7 +55,7 @@ def fake_model_predict(df: pd.DataFrame) -> pd.Series:

# We instantiate an async driver once for the life of the app. We use the AsyncDriver here because under the hood
# FastAPI is async. If you were using Flask, you could use the regular Hamilton driver without issue.
dr = h_async.AsyncDriver(
dr = async_driver.AsyncDriver(
{}, # no config/invariant inputs in this example.
features, # the module that contains the common feature definitions.
result_builder=base.SimplePythonDataFrameGraphAdapter(),
Expand Down
Loading

0 comments on commit 9ebd205

Please sign in to comment.