Skip to content

Commit

Permalink
Merge branch 'feature/pipeline-deserialization-hook' of github.com:de…
Browse files Browse the repository at this point in the history
…epset-ai/haystack into feature/pipeline-deserialization-hook
  • Loading branch information
shadeMe committed Apr 9, 2024
2 parents e544fd3 + b78851b commit 8d8ac60
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 15 deletions.
30 changes: 27 additions & 3 deletions .github/workflows/github_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch: # this is useful to re-generate the release page without a new tag being pushed
push:
tags:
- "v2.0.0-beta*"
- "v2.[0-9]+.[0-9]+*"

jobs:
generate-notes:
Expand All @@ -28,9 +28,33 @@ jobs:
python -m pip install --upgrade pip
pip install "reno<5"
- name: Generate release notes for beta versions
- name: Generate release notes for release candidates - minor releases
if: steps.version.outputs.current_pre_release != '' && endsWith(steps.version.outputs.current_release, '.0')
env:
# When generating notes for release candidates of minor versions, pick every vX.Y.Z-rcN but
# stop when encounter vX.Y.Z-rc0. The -rc0 tag is added automatically when
# we create the release branch, so we can assume it's always there.
EARLIEST_VERSION: v${{ steps.version.outputs.current_release }}-rc0
run: |
reno report --no-show-source --ignore-cache --version v${{ steps.version.outputs.current_release }}-${{ steps.version.outputs.current_pre_release }} -o relnotes.rst
reno report --no-show-source --ignore-cache --earliest-version "$EARLIEST_VERSION" -o relnotes.rst
- name: Generate release notes for release candidates - bugfix releases
if: steps.version.outputs.current_pre_release != '' && !endsWith(steps.version.outputs.current_release, '.0')
env:
# When generating notes for release candidates of bugfix releases, pick every vX.Y.Z-rcN but
# stop when encounter vX.Y.Z-rc1.
# In this case, we don't have the -rc0 tag, because we don't need to go through commits on main,
# as we cherry-pick them into the release branch.
EARLIEST_VERSION: v${{ steps.version.outputs.current_release }}-rc1
run: |
reno report --no-show-source --ignore-cache --earliest-version "$EARLIEST_VERSION" -o relnotes.rst
- name: Generate release notes for the final release
if: steps.version.outputs.current_pre_release == ''
# When generating notes for the final release vX.Y.Z, we just pass --version and reno
# will automatically collapse all the vX.Y.Z-rcN.
run: |
reno report --no-show-source --ignore-cache --version v${{ steps.version.outputs.current_release }} -o relnotes.rst
- name: Convert to Markdown
uses: docker://pandoc/core:3.1
Expand Down
1 change: 1 addition & 0 deletions haystack/dataclasses/chat_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ChatMessage:
def to_openai_format(self) -> Dict[str, Any]:
"""
Convert the message to the format expected by OpenAI's Chat API.
See the [API reference](https://platform.openai.com/docs/api-reference/chat/create) for details.
:returns: A dictionary with the following key:
Expand Down
1 change: 1 addition & 0 deletions haystack/dataclasses/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class _BackwardCompatible(type):
def __call__(cls, *args, **kwargs):
"""
Called before Document.__init__, will remap legacy fields to new ones.
Also handles building a Document from a flattened dictionary.
"""
# Move `content` to new fields depending on the type
Expand Down
1 change: 1 addition & 0 deletions haystack/document_stores/in_memory/document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def write_documents(self, documents: List[Document], policy: DuplicatePolicy = D
def delete_documents(self, document_ids: List[str]) -> None:
"""
Deletes all documents with matching document_ids from the DocumentStore.
:param document_ids: The object_ids to delete.
"""
for doc_id in document_ids:
Expand Down
5 changes: 3 additions & 2 deletions haystack/lazy_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

class LazyImport(_DeferredImportExceptionContextManager):
"""
Wrapper on top of lazy_import's _DeferredImportExceptionContextManager that adds the possibility to customize the
error messages.
Wrapper on top of lazy_import's _DeferredImportExceptionContextManager.
It adds the possibility to customize the error messages.
"""

def __init__(self, message: str = DEFAULT_IMPORT_ERROR_MSG) -> None:
Expand Down
1 change: 1 addition & 0 deletions haystack/testing/document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class FilterableDocsFixtureMixin:

@pytest.fixture
def filterable_docs(self) -> List[Document]:
"""Fixture that returns a list of Documents that can be used to test filtering."""
documents = []
for i in range(3):
documents.append(
Expand Down
29 changes: 19 additions & 10 deletions haystack/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ def __str__(self):

@staticmethod
def from_str(string: str) -> "SecretType":
map = {e.value: e for e in SecretType}
type = map.get(string)
"""
Convert a string to a SecretType.
:param string: The string to convert.
"""
mapping = {e.value: e for e in SecretType}
type = mapping.get(string)
if type is None:
raise ValueError(f"Unknown secret type '{string}'")
return type
Expand Down Expand Up @@ -47,10 +52,9 @@ def from_token(token: str) -> "Secret":
@staticmethod
def from_env_var(env_vars: Union[str, List[str]], *, strict: bool = True) -> "Secret":
"""
Create an environment variable-based secret. Accepts
one or more environment variables. Upon resolution, it
returns a string token from the first environment variable
that is set.
Create an environment variable-based secret. Accepts one or more environment variables.
Upon resolution, it returns a string token from the first environment variable that is set.
:param env_vars:
A single environment variable or an ordered list of
Expand All @@ -66,6 +70,7 @@ def from_env_var(env_vars: Union[str, List[str]], *, strict: bool = True) -> "Se
def to_dict(self) -> Dict[str, Any]:
"""
Convert the secret to a JSON-serializable dictionary.
Some secrets may not be serializable.
:returns:
Expand Down Expand Up @@ -94,8 +99,7 @@ def from_dict(dict: Dict[str, Any]) -> "Secret":
@abstractmethod
def resolve_value(self) -> Optional[Any]:
"""
Resolve the secret to an atomic value. The semantics
of the value is secret-dependent.
Resolve the secret to an atomic value. The semantics of the value is secret-dependent.
:returns:
The value of the secret, if any.
Expand Down Expand Up @@ -124,6 +128,7 @@ def _from_dict(dict: Dict[str, Any]) -> "Secret":
class TokenSecret(Secret):
"""
A secret that uses a string token/API key.
Cannot be serialized.
"""

Expand All @@ -149,19 +154,21 @@ def _from_dict(dict: Dict[str, Any]) -> "Secret":
)

def resolve_value(self) -> Optional[Any]:
"""Return the token."""
return self._token

@property
def type(self) -> SecretType:
"""The type of the secret."""
return self._type


@dataclass(frozen=True)
class EnvVarSecret(Secret):
"""
A secret that accepts one or more environment variables.
Upon resolution, it returns a string token from the first
environment variable that is set. Can be serialized.
Upon resolution, it returns a string token from the first environment variable that is set. Can be serialized.
"""

_env_vars: Tuple[str, ...]
Expand All @@ -183,6 +190,7 @@ def _from_dict(dict: Dict[str, Any]) -> "Secret":
return EnvVarSecret(tuple(dict["env_vars"]), _strict=dict["strict"])

def resolve_value(self) -> Optional[Any]:
"""Resolve the secret to an atomic value. The semantics of the value is secret-dependent."""
out = None
for env_var in self._env_vars:
value = os.getenv(env_var)
Expand All @@ -195,6 +203,7 @@ def resolve_value(self) -> Optional[Any]:

@property
def type(self) -> SecretType:
"""The type of the secret."""
return self._type


Expand Down
6 changes: 6 additions & 0 deletions haystack/utils/hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def __str__(self):

@staticmethod
def from_str(string: str) -> "HFEmbeddingAPIType":
"""
Convert a string to a HFEmbeddingAPIType enum.
:param string:
:return: The corresponding HFEmbeddingAPIType enum.
"""
enum_map = {e.value: e for e in HFEmbeddingAPIType}
mode = enum_map.get(string)
if mode is None:
Expand Down

0 comments on commit 8d8ac60

Please sign in to comment.