Skip to content

Commit

Permalink
fix: play: make settings optional. Don't capture stderr for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
codito committed Jan 22, 2024
1 parent f90e7d7 commit 4bbc070
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions arey/platform/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from rich.console import Console
from rich.theme import Theme
from wurlitzer import pipes

theme = Theme(
{
Expand Down Expand Up @@ -51,7 +50,13 @@ def __exit__(self, exc_type, exc_value, traceback):
def capture_stderr() -> Generator[StringIO, None, None]:
"""Capture stderr for both python and c-functions."""
stderr = io.StringIO()
with redirect_stderr(stderr) as err, pipes(
stdout=0, stderr=stderr, encoding="utf-8"
):
yield err
try:
from wurlitzer import pipes

with redirect_stderr(stderr) as err, pipes(
stdout=0, stderr=stderr, encoding="utf-8"
):
yield err
except Exception:
# Not supported on Windows. Disable stderr capture.
yield stderr
6 changes: 3 additions & 3 deletions arey/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from arey.platform.assets import get_asset_path
from arey.platform.llama import LlamaBaseModel
from arey.platform.console import capture_stderr
from typing import Dict, Optional, Iterator
from typing import Dict, Optional, Iterator, cast


config = get_config()
Expand Down Expand Up @@ -72,8 +72,8 @@ def get_play_file(file_path: str) -> PlayFile:
play_file = frontmatter.load(f)

# FIXME validate settings
model_config = config.models[play_file.metadata["model"]]
model_settings = play_file.metadata["settings"]
model_config = config.models[cast(str, play_file.metadata["model"])]
model_settings: dict = cast(dict, play_file.metadata.get("settings", {}))
return PlayFile(
file_path=play_file_path,
model_config=model_config,
Expand Down

0 comments on commit 4bbc070

Please sign in to comment.