From 57fb356c653cf823fcb7b66207e8b02b78bac9c9 Mon Sep 17 00:00:00 2001 From: James Braza Date: Thu, 12 Sep 2024 12:55:56 -0700 Subject: [PATCH 1/2] Restoring CI running on min Python versions --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 84b12f34..4a60ded6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: if: github.event_name == 'pull_request' # pre-commit-ci/lite-action only runs here strategy: matrix: - python-version: [3.12] # Our min and max supported Python versions + python-version: [3.11, 3.12] # Our min and max supported Python versions steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -39,7 +39,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.12] # Our min and max supported Python versions + python-version: [3.11, 3.12] # Our min and max supported Python versions steps: - uses: actions/checkout@v4 - name: Set up uv From 81dae50c40fb957763c8934a2a321bfb0942fefa Mon Sep 17 00:00:00 2001 From: James Braza Date: Thu, 12 Sep 2024 12:56:24 -0700 Subject: [PATCH 2/2] Restoring validation functionality after #383 turns out to not work for Python 3.11 --- paperqa/llms.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/paperqa/llms.py b/paperqa/llms.py index 5fb5ff21..6c9b7401 100644 --- a/paperqa/llms.py +++ b/paperqa/llms.py @@ -6,6 +6,7 @@ from collections.abc import AsyncIterable, Awaitable, Callable, Iterable, Sequence from enum import StrEnum from inspect import signature +from sys import version_info from typing import Any import numpy as np @@ -350,9 +351,12 @@ async def _run_completion( }, ] -_DeploymentTypedDictValidator = TypeAdapter( - list[DeploymentTypedDict], config=ConfigDict(arbitrary_types_allowed=True) -) + +IS_PYTHON_BELOW_312 = version_info < (3, 12) +if not IS_PYTHON_BELOW_312: + _DeploymentTypedDictValidator = TypeAdapter( + list[DeploymentTypedDict], config=ConfigDict(arbitrary_types_allowed=True) + ) class LiteLLMModel(LLMModel): @@ -390,11 +394,15 @@ def maybe_set_config_attribute(cls, data: dict[str, Any]) -> dict[str, Any]: "router_kwargs": {"num_retries": 3, "retry_after": 5}, } # we only support one "model name" for now, here we validate - _DeploymentTypedDictValidator.validate_python(data["config"]["model_list"]) - if ( - "config" in data - and len({m["model_name"] for m in data["config"]["model_list"]}) > 1 - ): + model_list = data["config"]["model_list"] + if IS_PYTHON_BELOW_312: + if not isinstance(model_list, list): + # Work around https://github.com/BerriAI/litellm/issues/5664 + raise TypeError(f"model_list must be a list, not a {type(model_list)}.") + else: + # pylint: disable-next=possibly-used-before-assignment + _DeploymentTypedDictValidator.validate_python(model_list) + if "config" in data and len({m["model_name"] for m in model_list}) > 1: raise ValueError("Only one model name per router is supported for now.") return data