Skip to content

Commit

Permalink
fix: update install scripts to use quotes for zsh compatibility (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPolymath authored Dec 16, 2024
1 parent ddc52ec commit 6dc1de4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 38 deletions.
14 changes: 7 additions & 7 deletions docs/src/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Installing ell

.. code-block:: bash
pip install -U ell-ai[all]
pip install -U "ell-ai[all]"
This installs ``ell``, ``ell-studio``, versioning and tracing with SQLite, and the default provider clients.

Expand Down Expand Up @@ -39,7 +39,7 @@ Adds the Anthropic client.

.. code-block:: bash
pip install -U ell-ai[anthropic]
pip install -U "ell-ai[anthropic]"
``groq``
Expand All @@ -48,7 +48,7 @@ Adds the Groq client.

.. code-block:: bash
pip install -U ell-ai[groq]
pip install -U "ell-ai[groq]"
``studio``
Expand All @@ -57,7 +57,7 @@ Adds ``ell-studio``.

.. code-block:: bash
pip install -U ell-ai[studio]
pip install -U "ell-ai[studio]"
``sqlite``
Expand All @@ -66,7 +66,7 @@ SQLite storage for versioning and tracing.

.. code-block:: bash
pip install -U ell-ai[sqlite]
pip install -U "ell-ai[sqlite]"
``postgres``
Expand All @@ -77,7 +77,7 @@ Include this option if you'd like to use ``ell-studio`` with Postgres.

.. code-block:: bash
pip install -U ell-ai[postgres]
pip install -U "ell-ai[postgres]"
Combining options
~~~~~~~~~~~~~~~~~
Expand All @@ -88,7 +88,7 @@ Example: Install ``ell`` with ``ell-studio``, Postgres, and the Anthropic client

.. code-block:: bash
pip install -U ell-ai[studio, postgres, anthropic]
pip install -U "ell-ai[studio, postgres, anthropic]"
API Key Setup
Expand Down
68 changes: 39 additions & 29 deletions src/ell/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,82 +16,82 @@

_config_logger = logging.getLogger(__name__)


@dataclass(frozen=True)
class _Model:
name: str
default_client: Optional[Union[openai.Client, Any]] = None
#XXX: Deprecation in 0.1.0
#XXX: We will depreciate this when streaming is implemented.
# XXX: Deprecation in 0.1.0
# XXX: We will depreciate this when streaming is implemented.
# Currently we stream by default for the verbose renderer,
# but in the future we will not support streaming by default
# but in the future we will not support streaming by default
# and stream=True must be passed which will then make API providers the
# single source of truth for whether or not a model supports an api parameter.
# This makes our implementation extremely light, only requiring us to provide
# a list of model names in registration.
supports_streaming : Optional[bool] = field(default=None)

supports_streaming: Optional[bool] = field(default=None)


class Config(BaseModel):
"""Configuration class for ELL."""

model_config = ConfigDict(
arbitrary_types_allowed=True,
protected_namespaces=('protect_', ) # Override protected namespaces
)

registry: Dict[str, _Model] = Field(
default_factory=dict,
default_factory=dict,
description="A dictionary mapping model names to their configurations."
)
verbose: bool = Field(
default=False,
default=False,
description="If True, enables verbose logging."
)
wrapped_logging: bool = Field(
default=True,
default=True,
description="If True, enables wrapped logging for better readability."
)
override_wrapped_logging_width: Optional[int] = Field(
default=None,
default=None,
description="If set, overrides the default width for wrapped logging."
)
store: Optional[Store] = Field(
default=None,
default=None,
description="An optional Store instance for persistence."
)
autocommit: bool = Field(
default=False,
default=False,
description="If True, enables automatic committing of changes to the store."
)
lazy_versioning: bool = Field(
default=True,
default=True,
description="If True, enables lazy versioning for improved performance."
)
default_api_params: Dict[str, Any] = Field(
default_factory=dict,
default_factory=dict,
description="Default parameters for language models."
)
default_client: Optional[openai.Client] = Field(
default=None,
default=None,
description="The default OpenAI client used when a specific model client is not found."
)
autocommit_model: str = Field(
default="gpt-4o-mini",
default="gpt-4o-mini",
description="When set, changes the default autocommit model from GPT 4o mini."
)
providers: Dict[Type, Provider] = Field(
default_factory=dict,
default_factory=dict,
description="A dictionary mapping client types to provider classes."
)

def __init__(self, **data):
super().__init__(**data)
self._lock = threading.Lock()
self._local = threading.local()


def register_model(
self,
self,
name: str,
default_client: Optional[Union[openai.Client, Any]] = None,
supports_streaming: Optional[bool] = None
Expand All @@ -107,8 +107,6 @@ def register_model(
supports_streaming=supports_streaming
)



@contextmanager
def model_registry_override(self, overrides: Dict[str, _Model]):
"""
Expand All @@ -119,12 +117,12 @@ def model_registry_override(self, overrides: Dict[str, _Model]):
"""
if not hasattr(self._local, 'stack'):
self._local.stack = []

with self._lock:
current_registry = self._local.stack[-1] if self._local.stack else self.registry
new_registry = current_registry.copy()
new_registry.update(overrides)

self._local.stack.append(new_registry)
try:
yield
Expand All @@ -140,14 +138,16 @@ def get_client_for(self, model_name: str) -> Tuple[Optional[openai.Client], bool
:return: The OpenAI client for the specified model, or None if not found, and a fallback flag.
:rtype: Tuple[Optional[openai.Client], bool]
"""
current_registry = self._local.stack[-1] if hasattr(self._local, 'stack') and self._local.stack else self.registry
current_registry = self._local.stack[-1] if hasattr(
self._local, 'stack') and self._local.stack else self.registry
model_config = current_registry.get(model_name)
fallback = False
if not model_config:
warning_message = f"Warning: A default provider for model '{model_name}' could not be found. Falling back to default OpenAI client from environment variables."
if self.verbose:
from colorama import Fore, Style
_config_logger.warning(f"{Fore.LIGHTYELLOW_EX}{warning_message}{Style.RESET_ALL}")
_config_logger.warning(
f"{Fore.LIGHTYELLOW_EX}{warning_message}{Style.RESET_ALL}")
else:
_config_logger.debug(warning_message)
client = self.default_client
Expand All @@ -163,7 +163,8 @@ def register_provider(self, provider: Provider, client_type: Type[Any]) -> None:
:param provider_class: The provider class to register.
:type provider_class: Type[Provider]
"""
assert isinstance(client_type, type), "client_type must be a type (e.g. openai.Client), not an an instance (myclient := openai.Client()))"
assert isinstance(
client_type, type), "client_type must be a type (e.g. openai.Client), not an an instance (myclient := openai.Client()))"
with self._lock:
self.providers[client_type] = provider

Expand All @@ -188,6 +189,7 @@ def get_provider_for(self, client: Union[Type[Any], Any]) -> Optional[Provider]:
# XXX: Make a singleton
config = Config()


def init(
store: Optional[Union[Store, str]] = None,
verbose: bool = False,
Expand Down Expand Up @@ -224,7 +226,8 @@ def init(
from ell.stores.sql import SQLiteStore
config.store = SQLiteStore(store)
except ImportError:
raise ImportError("Failed importing SQLiteStore. Install with `pip install -U ell-ai[all]`. More info: https://docs.ell.so/installation")
raise ImportError(
'Failed importing SQLiteStore. Install with `pip install -U "ell-ai[all]"`. More info: https://docs.ell.so/installation')
else:
config.store = store
config.autocommit = autocommit or config.autocommit
Expand All @@ -239,15 +242,22 @@ def init(
config.autocommit_model = autocommit_model

# Existing helper functions


def get_store() -> Union[Store, None]:
return config.store

# Will be deprecated at 0.1.0
# Will be deprecated at 0.1.0

# You can add more helper functions here if needed


def register_provider(provider: Provider, client_type: Type[Any]) -> None:
return config.register_provider(provider, client_type)

# Deprecated now (remove at 0.1.0)


def set_store(*args, **kwargs) -> None:
raise DeprecationWarning("The set_store function is deprecated and will be removed in a future version. Use ell.init(store=...) instead.")
raise DeprecationWarning(
"The set_store function is deprecated and will be removed in a future version. Use ell.init(store=...) instead.")
3 changes: 2 additions & 1 deletion src/ell/stores/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
try:
import sqlmodel
except ImportError:
raise ImportError("ell.stores has missing dependencies. Install them with `pip install -U ell-ai[sqlite]` or `pip install -U ell-ai[postgres]`. More info: https://docs.ell.so/installation/custom-installation")
raise ImportError(
'ell.stores has missing dependencies. Install them with `pip install -U "ell-ai[sqlite]"` or `pip install -U "ell-ai[postgres]"`. More info: https://docs.ell.so/installation/custom-installation')
3 changes: 2 additions & 1 deletion src/ell/studio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
import fastapi
import ell.stores
except ImportError:
raise ImportError("ell.studio is missing dependencies. Install them with `pip install -U ell-ai[studio]. More info: https://docs.ell.so/installation/custom-installation")
raise ImportError(
'ell.studio is missing dependencies. Install them with `pip install -U "ell-ai[studio]"`. More info: https://docs.ell.so/installation/custom-installation')

0 comments on commit 6dc1de4

Please sign in to comment.