From 03d62a737a80b94e9413eb506131b923ad8dd4cc Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Fri, 26 Jul 2024 10:59:33 -0400 Subject: [PATCH] together: Add rate limiter to integration tests (#24714) Rate limit the integration tests to avoid getting 429s. --- .../test_chat_models_standard.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libs/partners/together/tests/integration_tests/test_chat_models_standard.py b/libs/partners/together/tests/integration_tests/test_chat_models_standard.py index 4397725837..2250873f4b 100644 --- a/libs/partners/together/tests/integration_tests/test_chat_models_standard.py +++ b/libs/partners/together/tests/integration_tests/test_chat_models_standard.py @@ -4,12 +4,17 @@ from typing import Type import pytest from langchain_core.language_models import BaseChatModel -from langchain_standard_tests.integration_tests import ( # type: ignore[import-not-found] - ChatModelIntegrationTests, # type: ignore[import-not-found] -) +from langchain_core.rate_limiters import InMemoryRateLimiter +from langchain_standard_tests.integration_tests import ChatModelIntegrationTests from langchain_together import ChatTogether +# Initialize the rate limiter in global scope, so it can be re-used +# across tests. +rate_limiter = InMemoryRateLimiter( + requests_per_second=0.5, +) + class TestTogetherStandard(ChatModelIntegrationTests): @property @@ -18,7 +23,10 @@ class TestTogetherStandard(ChatModelIntegrationTests): @property def chat_model_params(self) -> dict: - return {"model": "mistralai/Mistral-7B-Instruct-v0.1"} + return { + "model": "mistralai/Mistral-7B-Instruct-v0.1", + "rate_limiter": rate_limiter, + } @pytest.mark.xfail(reason=("May not call a tool.")) def test_tool_calling_with_no_arguments(self, model: BaseChatModel) -> None: