-
Notifications
You must be signed in to change notification settings - Fork 493
[fix] Resolve Mistral api key issue #3969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c12ae2b
7ed1034
66acbfa
999b150
909cdbc
1dd39a4
a9c99d7
de83074
62649b1
148110d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import pytest | ||
| from pydantic import ValidationError | ||
|
|
||
| from oss.src.core.secrets.dtos import CreateSecretDTO, UpdateSecretDTO | ||
|
|
||
|
|
||
| def test_create_secret_normalizes_mistralai_standard_provider_payload(): | ||
| payload = { | ||
| "header": {"name": "Mistral AI", "description": ""}, | ||
| "secret": { | ||
| "kind": "provider_key", | ||
| "data": { | ||
| "kind": "mistralai", | ||
| "provider": { | ||
| "key": "TEST_KEY", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| secret = CreateSecretDTO.model_validate(payload) | ||
|
|
||
| assert secret.secret.data.kind == "mistral" | ||
| assert secret.secret.data.provider.key == "TEST_KEY" | ||
|
|
||
|
|
||
| def test_update_secret_normalizes_mistralai_standard_provider_payload(): | ||
| payload = { | ||
| "secret": { | ||
| "kind": "provider_key", | ||
| "data": { | ||
| "kind": "mistralai", | ||
| "provider": { | ||
| "key": "TEST_KEY", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| secret = UpdateSecretDTO.model_validate(payload) | ||
|
|
||
| assert secret.secret.data.kind == "mistral" | ||
| assert secret.secret.data.provider.key == "TEST_KEY" | ||
|
|
||
|
|
||
| def test_create_secret_rejects_missing_standard_provider_kind(): | ||
| payload = { | ||
| "header": {"name": "Mistral AI", "description": ""}, | ||
| "secret": { | ||
| "kind": "provider_key", | ||
| "data": { | ||
| "provider": { | ||
| "key": "TEST_KEY", | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| with pytest.raises(ValidationError, match="StandardProviderKind"): | ||
| CreateSecretDTO.model_validate(payload) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
|
|
||
| from oss.src.core.secrets.enums import StandardProviderKind | ||
| from oss.src.core.secrets.utils import ( | ||
| get_system_llm_providers_secrets, | ||
| get_user_llm_providers_secrets, | ||
| ) | ||
|
|
||
|
|
||
| class _FakeVaultService: | ||
| def __init__(self, *_args, **_kwargs): | ||
| pass | ||
|
|
||
| async def list_secrets(self, project_id): | ||
| del project_id | ||
| return [ | ||
| SimpleNamespace( | ||
| kind="provider_key", | ||
| model_dump=lambda include=None: { | ||
| "data": { | ||
| "kind": StandardProviderKind.MISTRALAI, | ||
| "provider": {"key": "mistral-key"}, | ||
| } | ||
| }, | ||
| ), | ||
| SimpleNamespace( | ||
| kind="provider_key", | ||
| model_dump=lambda include=None: { | ||
| "data": { | ||
| "kind": StandardProviderKind.TOGETHERAI, | ||
| "provider": {"key": "together-key"}, | ||
| } | ||
| }, | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_get_user_llm_providers_secrets_normalizes_legacy_provider_slugs( | ||
| monkeypatch, | ||
| ): | ||
| monkeypatch.setattr("oss.src.core.secrets.utils.VaultService", _FakeVaultService) | ||
|
|
||
| secrets = await get_user_llm_providers_secrets( | ||
| "00000000-0000-0000-0000-000000000000" | ||
| ) | ||
|
|
||
| assert secrets["MISTRAL_API_KEY"] == "mistral-key" | ||
| assert "MISTRALAI_API_KEY" not in secrets | ||
| assert secrets["TOGETHERAI_API_KEY"] == "together-key" | ||
| assert "TOGETHER_AI_API_KEY" not in secrets | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_get_system_llm_providers_secrets_reads_legacy_mistralai_env(monkeypatch): | ||
| monkeypatch.delenv("MISTRAL_API_KEY", raising=False) | ||
| monkeypatch.setenv("MISTRALAI_API_KEY", "legacy-mistral-key") | ||
|
|
||
| secrets = await get_system_llm_providers_secrets() | ||
|
|
||
| assert secrets["MISTRAL_API_KEY"] == "legacy-mistral-key" | ||
| assert "MISTRALAI_API_KEY" not in secrets |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Custom provider kind matching broken by asymmetric normalization of 'mistralai' alias In both Before this PR, (Refers to lines 227-228) Was this helpful? React with 👍 or 👎 to provide feedback.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Same asymmetric custom provider kind normalization in get_provider_settings_from_workflow Duplicate of the same bug as in (Refers to lines 371-372) Was this helpful? React with 👍 or 👎 to provide feedback. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| from types import SimpleNamespace | ||
|
|
||
| from agenta.sdk.contexts.running import RunningContext | ||
| from agenta.sdk.managers.secrets import SecretsManager | ||
| from agenta.sdk.workflows.runners.daytona import DaytonaRunner | ||
|
|
||
|
|
||
| def test_secrets_manager_accepts_mistralai_secret_for_mistral_model(monkeypatch): | ||
| monkeypatch.setattr( | ||
| SecretsManager, | ||
| "get_from_route", | ||
| staticmethod( | ||
| lambda scope="all": [ | ||
| { | ||
| "kind": "provider_key", | ||
| "data": { | ||
| "kind": "mistralai", | ||
| "provider": {"key": "TEST_KEY"}, | ||
| }, | ||
| } | ||
| ] | ||
| ), | ||
| ) | ||
|
|
||
| settings = SecretsManager.get_provider_settings("mistral/mistral-small") | ||
|
|
||
| assert settings is not None | ||
| assert settings["model"] == "mistral/mistral-small" | ||
| assert settings["api_key"] == "TEST_KEY" | ||
|
|
||
|
|
||
| def test_daytona_runner_exports_canonical_mistral_env_var(monkeypatch): | ||
| monkeypatch.setenv("DAYTONA_API_KEY", "test-daytona-key") | ||
| runner = DaytonaRunner() | ||
| monkeypatch.setattr( | ||
| RunningContext, | ||
| "get", | ||
| staticmethod( | ||
| lambda: SimpleNamespace( | ||
| vault_secrets=[ | ||
| { | ||
| "kind": "provider_key", | ||
| "data": { | ||
| "kind": "mistralai", | ||
| "provider": {"key": "TEST_KEY"}, | ||
| }, | ||
| } | ||
| ] | ||
| ) | ||
| ), | ||
| ) | ||
|
|
||
| env_vars = runner._get_provider_env_vars() | ||
|
|
||
| assert env_vars["MISTRAL_API_KEY"] == "TEST_KEY" |
Uh oh!
There was an error while loading. Please reload this page.