fix: getting_started notebook

This commit is contained in:
Hardik Shah 2025-03-26 09:19:04 -07:00
parent bdfe7fee92
commit 3213d2d197
4 changed files with 594 additions and 1497 deletions

File diff suppressed because one or more lines are too long

View file

@ -43,7 +43,7 @@ class StackRun(Subcommand):
self.parser.add_argument( self.parser.add_argument(
"--image-name", "--image-name",
type=str, type=str,
default=os.environ.get("CONDA_DEFAULT_ENV"), default=None,
help="Name of the image to run. Defaults to the current conda environment", help="Name of the image to run. Defaults to the current conda environment",
) )
self.parser.add_argument( self.parser.add_argument(

View file

@ -13,6 +13,7 @@ LLAMA_CHECKPOINT_DIR=${LLAMA_CHECKPOINT_DIR:-}
LLAMA_STACK_DIR=${LLAMA_STACK_DIR:-} LLAMA_STACK_DIR=${LLAMA_STACK_DIR:-}
TEST_PYPI_VERSION=${TEST_PYPI_VERSION:-} TEST_PYPI_VERSION=${TEST_PYPI_VERSION:-}
PYPI_VERSION=${PYPI_VERSION:-} PYPI_VERSION=${PYPI_VERSION:-}
VIRTUAL_ENV=${VIRTUAL_ENV:-}
set -euo pipefail set -euo pipefail
@ -69,22 +70,25 @@ while [[ $# -gt 0 ]]; do
;; ;;
esac esac
done done
PYTHON_BINARY="python" PYTHON_BINARY="python"
case "$env_type" in case "$env_type" in
"venv") "venv")
# Activate virtual environment if [ -n "$VIRTUAL_ENV" && "$VIRTUAL_ENV" == "$env_path_or_name" ]; then
if [ ! -d "$env_path_or_name" ]; then echo -e "${GREEN}Virtual environment already activated${NC}" >&2
echo -e "${RED}Error: Virtual environment not found at $env_path_or_name${NC}" >&2 else
exit 1 # Activate virtual environment
fi if [ ! -d "$env_path_or_name" ]; then
echo -e "${RED}Error: Virtual environment not found at $env_path_or_name${NC}" >&2
exit 1
fi
if [ ! -f "$env_path_or_name/bin/activate" ]; then if [ ! -f "$env_path_or_name/bin/activate" ]; then
echo -e "${RED}Error: Virtual environment activate binary not found at $env_path_or_name/bin/activate" >&2 echo -e "${RED}Error: Virtual environment activate binary not found at $env_path_or_name/bin/activate" >&2
exit 1 exit 1
fi fi
source "$env_path_or_name/bin/activate" source "$env_path_or_name/bin/activate"
fi
;; ;;
"conda") "conda")
if ! is_command_available conda; then if ! is_command_available conda; then

View file

@ -18,15 +18,19 @@ def preserve_contexts_async_generator(
This is needed because we start a new asyncio event loop for each streaming request, This is needed because we start a new asyncio event loop for each streaming request,
and we need to preserve the context across the event loop boundary. and we need to preserve the context across the event loop boundary.
""" """
# Capture initial context values
initial_context_values = {context_var.name: context_var.get() for context_var in context_vars}
async def wrapper() -> AsyncGenerator[T, None]: async def wrapper() -> AsyncGenerator[T, None]:
while True: while True:
try: try:
item = await gen.__anext__() # Restore context values before any await
context_values = {context_var.name: context_var.get() for context_var in context_vars}
yield item
for context_var in context_vars: for context_var in context_vars:
_ = context_var.set(context_values[context_var.name]) context_var.set(initial_context_values[context_var.name])
item = await gen.__anext__()
yield item
except StopAsyncIteration: except StopAsyncIteration:
break break