tabbyAPI-ollama/common/utils.py
kingbri b9fd8555fe Sampling: Copy over iterable overrides
If an override was iterable, any modifications to the returned value
would alter the reference to the global storage dict.

Therefore, copy the structure if it's an iterable so any modification
won't alter the original override. Also apply this for the function
that checks for forced overrides.

Signed-off-by: kingbri <bdashore3@proton.me>
2024-05-17 21:38:28 -04:00

20 lines
466 B
Python

"""Common utility functions"""
def unwrap(wrapped, default=None):
"""Unwrap function for Optionals."""
if wrapped is None:
return default
return wrapped
def coalesce(*args):
"""Coalesce function for multiple unwraps."""
return next((arg for arg in args if arg is not None), None)
def prune_dict(input_dict):
"""Trim out instances of None from a dictionary."""
return {k: v for k, v in input_dict.items() if v is not None}