Spaces:
Build error
fix(mistralai): detect v0.x package + force pip --upgrade in Dockerfile
Browse filesThe container had mistralai v0.x installed (identified by '(unknown location)'
in the traceback and ImportError on 'Mistral'). Two fixes:
1. provider_mistral.py: detect v0.x vs not-installed with separate
RuntimeError messages that point clearly to the Docker rebuild:
- v0.x present β "mistralai 0.x ne supporte pas la vision, reconstruisez"
- not installed β "mistralai n'est pas installΓ©, reconstruisez"
Raises RuntimeError (job fails cleanly) instead of ImportError.
2. infra/Dockerfile: add --upgrade to pip install so Docker rebuilds
always upgrade to the latest compatible version rather than keeping
a stale cached layer that had mistralai 0.x.
Added test: test_generate_content_v0_package_raises_runtime_error.
Note: vertex_api_key 403 in logs is a GCP configuration issue (Generative
Language API not enabled in project 347387665578) β not a code fix.
https://claude.ai/code/session_018woyEHc8HG2th7V4ewJ4Kg
|
@@ -69,11 +69,23 @@ class MistralProvider(AIProvider):
|
|
| 69 |
|
| 70 |
try:
|
| 71 |
from mistralai import Mistral # v1.x β import local
|
| 72 |
-
except ImportError
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
api_key = os.environ[_ENV_KEY]
|
| 79 |
client = Mistral(api_key=api_key)
|
|
|
|
| 69 |
|
| 70 |
try:
|
| 71 |
from mistralai import Mistral # v1.x β import local
|
| 72 |
+
except ImportError:
|
| 73 |
+
# DΓ©tecter si c'est mistralai v0.x (ne supporte pas la vision / Pixtral)
|
| 74 |
+
try:
|
| 75 |
+
import mistralai as _ms_pkg # noqa: F401
|
| 76 |
+
_v0_present = True
|
| 77 |
+
except ImportError:
|
| 78 |
+
_v0_present = False
|
| 79 |
+
if _v0_present:
|
| 80 |
+
raise RuntimeError(
|
| 81 |
+
"Le package mistralai est installΓ© en version 0.x qui ne supporte pas "
|
| 82 |
+
"la vision (Pixtral). Reconstruisez le container Docker pour obtenir "
|
| 83 |
+
"mistralai>=1.0 : `docker build --no-cache ...`"
|
| 84 |
+
)
|
| 85 |
+
raise RuntimeError(
|
| 86 |
+
"Le package mistralai n'est pas installΓ©. "
|
| 87 |
+
"Ajoutez 'mistralai>=1.0' aux dΓ©pendances et reconstruisez le container."
|
| 88 |
+
)
|
| 89 |
|
| 90 |
api_key = os.environ[_ENV_KEY]
|
| 91 |
client = Mistral(api_key=api_key)
|
|
@@ -164,3 +164,19 @@ def test_generate_content_empty_response(monkeypatch):
|
|
| 164 |
|
| 165 |
result = MistralProvider().generate_content(b"img", "prompt", "pixtral-large-latest")
|
| 166 |
assert result == ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
result = MistralProvider().generate_content(b"img", "prompt", "pixtral-large-latest")
|
| 166 |
assert result == ""
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def test_generate_content_v0_package_raises_runtime_error(monkeypatch):
|
| 170 |
+
"""Si mistralai est installé en v0.x (pas de classe Mistral), lève RuntimeError avec un message clair."""
|
| 171 |
+
monkeypatch.setenv("MISTRAL_API_KEY", "test-key")
|
| 172 |
+
|
| 173 |
+
import sys
|
| 174 |
+
import types as _types
|
| 175 |
+
|
| 176 |
+
# Simuler mistralai v0.x : le module existe mais n'a pas la classe Mistral
|
| 177 |
+
fake_mistralai_v0 = _types.ModuleType("mistralai")
|
| 178 |
+
# Pas d'attribut Mistral β from mistralai import Mistral lΓ¨vera ImportError
|
| 179 |
+
monkeypatch.setitem(sys.modules, "mistralai", fake_mistralai_v0)
|
| 180 |
+
|
| 181 |
+
with pytest.raises(RuntimeError, match="version 0.x"):
|
| 182 |
+
MistralProvider().generate_content(b"img", "prompt", "pixtral-large-latest")
|
|
@@ -35,7 +35,7 @@ WORKDIR /app
|
|
| 35 |
COPY backend/pyproject.toml /tmp/build/
|
| 36 |
RUN mkdir -p /tmp/build/app \
|
| 37 |
&& touch /tmp/build/app/__init__.py \
|
| 38 |
-
&& pip install --no-cache-dir /tmp/build/ \
|
| 39 |
&& rm -rf /tmp/build
|
| 40 |
|
| 41 |
# ββ Code source backend ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 35 |
COPY backend/pyproject.toml /tmp/build/
|
| 36 |
RUN mkdir -p /tmp/build/app \
|
| 37 |
&& touch /tmp/build/app/__init__.py \
|
| 38 |
+
&& pip install --no-cache-dir --upgrade /tmp/build/ \
|
| 39 |
&& rm -rf /tmp/build
|
| 40 |
|
| 41 |
# ββ Code source backend ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|