|
| 1 | +# Copyright (c) The OGX Contributors. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the terms described in the LICENSE file in |
| 5 | +# the root directory of this source tree. |
| 6 | + |
| 7 | +import os |
| 8 | +from unittest.mock import patch |
| 9 | + |
| 10 | +import pytest |
| 11 | + |
| 12 | +from ogx.core.stack import replace_env_vars |
| 13 | +from ogx.providers.remote.inference.deepseek.config import DeepSeekImplConfig |
| 14 | +from ogx.providers.remote.inference.deepseek.deepseek import DeepSeekInferenceAdapter |
| 15 | +from ogx_api import OpenAICompletionRequestWithExtraBody |
| 16 | + |
| 17 | + |
| 18 | +class TestDeepSeekConfig: |
| 19 | + """Tests for the DeepSeek inference provider config and adapter wiring.""" |
| 20 | + |
| 21 | + def test_default_base_url(self): |
| 22 | + config = DeepSeekImplConfig(api_key="test-key") |
| 23 | + adapter = DeepSeekInferenceAdapter(config=config) |
| 24 | + adapter.provider_data_api_key_field = None |
| 25 | + |
| 26 | + assert adapter.get_base_url() == "https://api.deepseek.com/v1" |
| 27 | + |
| 28 | + def test_custom_base_url_from_config(self): |
| 29 | + custom_url = "https://custom.deepseek.com/v1" |
| 30 | + config = DeepSeekImplConfig(api_key="test-key", base_url=custom_url) |
| 31 | + adapter = DeepSeekInferenceAdapter(config=config) |
| 32 | + adapter.provider_data_api_key_field = None |
| 33 | + |
| 34 | + assert adapter.get_base_url() == custom_url |
| 35 | + |
| 36 | + @patch.dict(os.environ, {"DEEPSEEK_BASE_URL": "https://env.deepseek.com/v1"}) |
| 37 | + def test_base_url_from_environment_variable(self): |
| 38 | + config_data = DeepSeekImplConfig.sample_run_config(api_key="test-key") |
| 39 | + processed_config = replace_env_vars(config_data) |
| 40 | + config = DeepSeekImplConfig.model_validate(processed_config) |
| 41 | + |
| 42 | + assert str(config.base_url) == "https://api.deepseek.com/v1" |
| 43 | + |
| 44 | + def test_sample_run_config_uses_env_placeholder(self): |
| 45 | + cfg = DeepSeekImplConfig.sample_run_config() |
| 46 | + assert cfg["base_url"] == "https://api.deepseek.com/v1" |
| 47 | + assert cfg["api_key"] == "${env.DEEPSEEK_API_KEY:=}" |
| 48 | + |
| 49 | + def test_provider_data_api_key_field(self): |
| 50 | + config = DeepSeekImplConfig(api_key="test-key") |
| 51 | + adapter = DeepSeekInferenceAdapter(config=config) |
| 52 | + assert adapter.provider_data_api_key_field == "deepseek_api_key" |
| 53 | + |
| 54 | + async def test_embeddings_not_supported(self): |
| 55 | + config = DeepSeekImplConfig(api_key="test-key") |
| 56 | + adapter = DeepSeekInferenceAdapter(config=config) |
| 57 | + with pytest.raises(NotImplementedError, match="does not expose an embeddings endpoint"): |
| 58 | + await adapter.openai_embeddings(None) # type: ignore[arg-type] |
| 59 | + |
| 60 | + async def test_legacy_completions_endpoint_not_supported(self): |
| 61 | + """DeepSeek does not support the legacy /v1/completions endpoint.""" |
| 62 | + config = DeepSeekImplConfig(api_key="test-key") |
| 63 | + adapter = DeepSeekInferenceAdapter(config=config) |
| 64 | + |
| 65 | + params = OpenAICompletionRequestWithExtraBody(model="deepseek-chat", prompt="Hello") |
| 66 | + |
| 67 | + with pytest.raises(NotImplementedError, match="does not support /v1/completions endpoint"): |
| 68 | + await adapter.openai_completion(params) |
0 commit comments