Skip to content

Commit 3094a27

Browse files
committed
fix: add more tests for client.py and refactor docs links
1 parent 34c76d7 commit 3094a27

5 files changed

Lines changed: 2209 additions & 51 deletions

File tree

docs/foundation_models.rst

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -357,41 +357,6 @@ Streaming ответы
357357
except Exception as e:
358358
print(f"Неправильные параметры: {e}")
359359
360-
Тестирование
361-
------------
362-
363-
Запуск примеров
364-
~~~~~~~~~~~~~~~
365-
366-
В проекте есть готовые примеры для Foundation Models:
367-
368-
.. code-block:: bash
369-
370-
# Запуск примеров Foundation Models
371-
python examples/foundation_models_example.py
372-
373-
Интеграционные тесты
374-
~~~~~~~~~~~~~~~~~~~~
375-
376-
.. code-block:: bash
377-
378-
# Установка переменных окружения
379-
export EVOLUTION_KEY_ID=your_key_id
380-
export EVOLUTION_SECRET=your_secret
381-
export EVOLUTION_PROJECT_ID=your_project_id
382-
export EVOLUTION_FOUNDATION_MODELS_URL=https://foundation-models.api.cloud.ru/api/gigacube/openai/v1
383-
export ENABLE_FOUNDATION_MODELS_TESTS=true
384-
385-
# Запуск тестов
386-
pytest tests/test_foundation_models_integration.py -v
387-
388-
Модульные тесты
389-
~~~~~~~~~~~~~~~
390-
391-
.. code-block:: bash
392-
393-
# Запуск модульных тестов
394-
pytest tests/test_foundation_models_unit.py -v
395360
396361
Лучшие практики
397362
---------------
@@ -515,13 +480,4 @@ Foundation Models могут работать медленнее обычных
515480
project_id="your_project_id",
516481
timeout=120.0, # 2 минуты
517482
max_retries=5, # 5 попыток
518-
)
519-
520-
Ссылки
521-
------
522-
523-
- `Примеры Foundation Models <https://github.com/cloud-ru-tech/evolution-openai-python/blob/main/examples/foundation_models_example.py>`_
524-
- `Интеграционные тесты <https://github.com/cloud-ru-tech/evolution-openai-python/blob/main/tests/test_foundation_models_integration.py>`_
525-
- `Модульные тесты <https://github.com/cloud-ru-tech/evolution-openai-python/blob/main/tests/test_foundation_models_unit.py>`_
526-
- `Документация Cloud.ru <https://cloud.ru/docs/>`_
527-
- `OpenAI API Reference <https://platform.openai.com/docs/api-reference>`_
483+
)

src/evolution_openai/client.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,20 @@ def get_request_headers(self) -> Dict[str, str]:
244244
headers: Dict[str, str] = {}
245245

246246
# Собираем заголовки из различных источников
247-
if hasattr(self._client, "_auth_headers"):
247+
if (
248+
hasattr(self._client, "_auth_headers")
249+
and self._client._auth_headers
250+
):
248251
headers.update(self._client._auth_headers) # type: ignore[reportAttributeAccessIssue]
249-
if hasattr(self._client, "default_headers"):
252+
if (
253+
hasattr(self._client, "default_headers")
254+
and self._client.default_headers
255+
):
250256
headers.update(self._client.default_headers) # type: ignore[reportAttributeAccessIssue]
251-
if hasattr(self._client, "_default_headers"):
257+
if (
258+
hasattr(self._client, "_default_headers")
259+
and self._client._default_headers
260+
):
252261
headers.update(self._client._default_headers) # type: ignore[reportAttributeAccessIssue]
253262
if hasattr(self, "default_headers") and self.default_headers:
254263
headers.update(self.default_headers) # type: ignore[reportAttributeAccessIssue]
@@ -485,11 +494,20 @@ def get_request_headers(self) -> Dict[str, str]:
485494
headers: Dict[str, str] = {}
486495

487496
# Собираем заголовки из различных источников
488-
if hasattr(self._client, "_auth_headers"):
497+
if (
498+
hasattr(self._client, "_auth_headers")
499+
and self._client._auth_headers
500+
):
489501
headers.update(self._client._auth_headers) # type: ignore[reportAttributeAccessIssue]
490-
if hasattr(self._client, "default_headers"):
502+
if (
503+
hasattr(self._client, "default_headers")
504+
and self._client.default_headers
505+
):
491506
headers.update(self._client.default_headers) # type: ignore[reportAttributeAccessIssue]
492-
if hasattr(self._client, "_default_headers"):
507+
if (
508+
hasattr(self._client, "_default_headers")
509+
and self._client._default_headers
510+
):
493511
headers.update(self._client._default_headers) # type: ignore[reportAttributeAccessIssue]
494512
if hasattr(self, "default_headers") and self.default_headers:
495513
headers.update(self.default_headers) # type: ignore[reportAttributeAccessIssue]

0 commit comments

Comments
 (0)