Skip to content

Commit

Permalink
Update cross-thread persistence doc (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Oct 6, 2024
1 parent 303fe60 commit 696c8b2
Show file tree
Hide file tree
Showing 5 changed files with 506 additions and 574 deletions.
24 changes: 18 additions & 6 deletions _scripts/run_notebook.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
from pathlib import Path
import subprocess
from typing import Optional
import re
Expand Down Expand Up @@ -52,7 +53,9 @@ def extract_code_blocks(content: str, title: Optional[str] = None):
return res


def extract_ts_code(file_path: str, title: str | None = None, strip_env: bool = True) -> str:
def extract_ts_code(
file_path: str, title: str | None = None, strip_env: bool = True
) -> str:
def replace_env_vars(match):
env_var = match.group(1)
env_value = os.environ.get(env_var, "")
Expand All @@ -70,16 +73,25 @@ def replace_env_vars(match):
ts_content = "\n".join(
[line for line in ts_content.split("\n") if not line.startswith("#")]
)

if strip_env:
ts_content = re.sub(r'process\.env\.([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*".*?"', replace_env_vars, ts_content)

ts_content = re.sub(
r'process\.env\.([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*".*?"',
replace_env_vars,
ts_content,
)

return ts_content


def get_tsconfig_options(tsconfig_path: str) -> list:
with open(tsconfig_path, "r", encoding="utf-8") as tsconfig_file:
tsconfig = json.load(tsconfig_file)
with Path(tsconfig_path).absolute().open("r", encoding="utf-8") as tsconfig_file:
txt = tsconfig_file.read()
try:
tsconfig = json.loads(txt.strip())
except Exception:
print(f"Failed to json load:\n\n{txt}")
raise
compiler_options = tsconfig.get("compilerOptions", {})
options = []
for key, value in compiler_options.items():
Expand Down
4 changes: 2 additions & 2 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ nav:
- Create branches for parallel execution: "how-tos/branching.ipynb"
- Create map-reduce branches for parallel execution: "how-tos/map-reduce.ipynb"
- Persistence:
- Add persistence ("memory") to your graph: "how-tos/persistence.ipynb"
- Add thread-level persistence: how-tos/persistence.ipynb
- Add cross-thread persistence: how-tos/cross-thread-persistence.ipynb
- View and update past graph state: "how-tos/time-travel.ipynb"
- Manage conversation history: "how-tos/manage-conversation-history.ipynb"
- How to delete messages: "how-tos/delete-messages.ipynb"
- Add summary of the conversation history: "how-tos/add-summary-conversation-history.ipynb"
- Share state between threads: "how-tos/shared-state.ipynb"
- Human-in-the-loop:
- Add breakpoints: "how-tos/breakpoints.ipynb"
- Add dynamic breakpoints: "how-tos/dynamic_breakpoints.ipynb"
Expand Down
Loading

0 comments on commit 696c8b2

Please sign in to comment.