-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add api, distributed setup #135
base: main
Are you sure you want to change the base?
Changes from 3 commits
97455fc
a85bd64
03b8d6a
b228fb0
9daa336
5ed6825
6f92642
7f27826
94f0a69
2e2a159
a78a7d6
9064f3a
e4f1525
1fa16d7
6a07b6c
1133e40
882960f
7c84f6d
4a64fbb
0be7110
6eac3fa
fd3f47e
71e9fd6
fe7b0d2
3c1ed4b
59b960f
30658be
99ec47b
ceeadd2
c47a107
e7c7710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12.2 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
try: | ||
from importlib.metadata import version | ||
except ImportError: | ||
from importlib_metadata import version | ||
from importlib.metadata import version, PackageNotFoundError | ||
|
||
__version__ = version("ell") | ||
try: | ||
__version__ = version("ell") | ||
except PackageNotFoundError: | ||
__version__ = "unknown" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from functools import lru_cache | ||
import json | ||
import os | ||
from typing import Optional | ||
from pydantic import BaseModel | ||
|
@@ -10,31 +11,36 @@ | |
|
||
# todo. maybe we default storage dir and other things in the future to a well-known location | ||
# like ~/.ell or something | ||
@lru_cache | ||
@lru_cache(maxsize=1) | ||
def ell_home() -> str: | ||
return os.path.join(os.path.expanduser("~"), ".ell") | ||
|
||
|
||
class Config(BaseModel): | ||
pg_connection_string: Optional[str] = None | ||
storage_dir: Optional[str] = None | ||
|
||
@classmethod | ||
def create( | ||
cls, | ||
storage_dir: Optional[str] = None, | ||
pg_connection_string: Optional[str] = None, | ||
) -> 'Config': | ||
pg_connection_string = pg_connection_string or os.getenv("ELL_PG_CONNECTION_STRING") | ||
storage_dir = storage_dir or os.getenv("ELL_STORAGE_DIR") | ||
|
||
mqtt_connection_string: Optional[str] = None | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
def model_post_init(self, __context): | ||
# Storage | ||
self.pg_connection_string = self.pg_connection_string or os.getenv( | ||
"ELL_PG_CONNECTION_STRING") | ||
self.storage_dir = self.storage_dir or os.getenv("ELL_STORAGE_DIR") | ||
# Enforce that we use either sqlite or postgres, but not both | ||
if pg_connection_string is not None and storage_dir is not None: | ||
if self.pg_connection_string is not None and self.storage_dir is not None: | ||
raise ValueError("Cannot use both sqlite and postgres") | ||
|
||
# For now, fall back to sqlite if no PostgreSQL connection string is provided | ||
if pg_connection_string is None and storage_dir is None: | ||
if self.pg_connection_string is None and self.storage_dir is None: | ||
# This intends to honor the default we had set in the CLI | ||
storage_dir = os.getcwd() | ||
# todo. better default? | ||
self.storage_dir = os.getcwd() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m ending up with SQLite dbs in various places. Maybe we standardize on ell home as a default? |
||
|
||
# Pubsub | ||
self.mqtt_connection_string = self.mqtt_connection_string or os.getenv("ELL_MQTT_CONNECTION_STRING") | ||
|
||
logger.info(f"Resolved config: {json.dumps(self.model_dump(), indent=2)}") | ||
|
||
return cls(pg_connection_string=pg_connection_string, storage_dir=storage_dir) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let me know if you want to restore this. Broadcast was replicated in the new “pub sub” interfaces. connection moved to the ws handler. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
from colorama import Fore, Style, init | ||
|
||
def setup_logging(level: int = logging.INFO): | ||
alex-dixon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Initialize colorama for cross-platform colored output | ||
init(autoreset=True) | ||
|
||
# Create a custom formatter | ||
class ColoredFormatter(logging.Formatter): | ||
FORMATS = { | ||
logging.DEBUG: Fore.CYAN + "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s" + Style.RESET_ALL, | ||
logging.INFO: Fore.GREEN + "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s" + Style.RESET_ALL, | ||
logging.WARNING: Fore.YELLOW + "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s" + Style.RESET_ALL, | ||
logging.ERROR: Fore.RED + "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s" + Style.RESET_ALL, | ||
logging.CRITICAL: Fore.RED + Style.BRIGHT + "[%(asctime)s] %(levelname)-8s %(name)s: %(message)s" + Style.RESET_ALL | ||
} | ||
|
||
def format(self, record): | ||
log_fmt = self.FORMATS.get(record.levelno) | ||
formatter = logging.Formatter(log_fmt, datefmt="%Y-%m-%d %H:%M:%S") | ||
return formatter.format(record) | ||
|
||
# Create and configure the logger | ||
logger = logging.getLogger("ell") | ||
logger.setLevel(level) | ||
|
||
# Create console handler and set formatter | ||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(ColoredFormatter()) | ||
|
||
# Add the handler to the logger | ||
logger.addHandler(console_handler) | ||
|
||
return logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should let us do Config() instead of Config.create() and have the same functionality