From b77b5d470ed23105262ba3eb2cae799092b8db19 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Thu, 9 Nov 2023 21:35:00 -0500 Subject: [PATCH 1/3] x --- tests/unit_tests/test_server_client.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit_tests/test_server_client.py b/tests/unit_tests/test_server_client.py index 5984c9c3..8e878bc8 100644 --- a/tests/unit_tests/test_server_client.py +++ b/tests/unit_tests/test_server_client.py @@ -113,7 +113,6 @@ async def add_one_or_passthrough( else: return x - os.environ["LANGCHAIN_TRACING_V2"] = "true" runnable_lambda = RunnableLambda(func=add_one_or_passthrough) app = FastAPI() try: @@ -1630,7 +1629,6 @@ async def test_feedback_fails_when_run_doesnt_exist() -> None: "score": 1000, }, ) - assert response.status_code == 404 From fc6b212fbfd035b0e61ce3f87905451668fefda7 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Mon, 13 Nov 2023 10:49:34 -0500 Subject: [PATCH 2/3] x --- tests/unit_tests/test_server_client.py | 128 ++++++++++++------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/tests/unit_tests/test_server_client.py b/tests/unit_tests/test_server_client.py index 8e878bc8..b7d86629 100644 --- a/tests/unit_tests/test_server_client.py +++ b/tests/unit_tests/test_server_client.py @@ -2,7 +2,6 @@ import asyncio import datetime import json -import os from asyncio import AbstractEventLoop from contextlib import asynccontextmanager, contextmanager from enum import Enum @@ -1554,82 +1553,83 @@ async def test_feedback_succeeds_when_langsmith_enabled() -> None: """Tests that the feedback endpoint can accept feedback to langsmith.""" with patch("langserve.server.ls_client") as mocked_ls_client_package: - mocked_client = MagicMock(return_value=None) - mocked_ls_client_package.Client.return_value = mocked_client - - mocked_client.create_feedback.return_value = ls_schemas.Feedback( - id="5484c6b3-5a1a-4a87-b2c7-2e39e7a7e4ac", - created_at=datetime.datetime(1994, 9, 19, 9, 19), - modified_at=datetime.datetime(1994, 9, 19, 9, 19), - run_id="f47ac10b-58cc-4372-a567-0e02b2c3d479", - key="silliness", - score=1000, - ) + with patch("langserve.server.tracing_is_enabled") as tracing_is_enabled: + tracing_is_enabled.return_value = True + mocked_client = MagicMock(return_value=None) + mocked_ls_client_package.Client.return_value = mocked_client + mocked_client.create_feedback.return_value = ls_schemas.Feedback( + id="5484c6b3-5a1a-4a87-b2c7-2e39e7a7e4ac", + created_at=datetime.datetime(1994, 9, 19, 9, 19), + modified_at=datetime.datetime(1994, 9, 19, 9, 19), + run_id="f47ac10b-58cc-4372-a567-0e02b2c3d479", + key="silliness", + score=1000, + ) - local_app = FastAPI() - add_routes( - local_app, - RunnableLambda(lambda foo: "hello"), - enable_feedback_endpoint=True, - ) + local_app = FastAPI() + add_routes( + local_app, + RunnableLambda(lambda foo: "hello"), + enable_feedback_endpoint=True, + ) - async with get_async_test_client( - local_app, raise_app_exceptions=True - ) as async_client: - response = await async_client.post( - "/feedback", - json={ + async with get_async_test_client( + local_app, raise_app_exceptions=True + ) as async_client: + response = await async_client.post( + "/feedback", + json={ + "run_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", + "key": "silliness", + "score": 1000, + }, + ) + + expected_response_json = { "run_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "key": "silliness", "score": 1000, - }, - ) - - expected_response_json = { - "run_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", - "key": "silliness", - "score": 1000, - "created_at": datetime.datetime(1994, 9, 19, 9, 19).strftime( - "%Y-%m-%dT%H:%M:%S" - ), - "modified_at": datetime.datetime(1994, 9, 19, 9, 19).strftime( - "%Y-%m-%dT%H:%M:%S" - ), - "comment": None, - "correction": None, - "value": None, - } + "created_at": "1994-09-19T09:19:00", + "modified_at": "1994-09-19T09:19:00", + "comment": None, + "correction": None, + "value": None, + } - assert response.json() == expected_response_json + assert response.json() == expected_response_json @pytest.mark.asyncio async def test_feedback_fails_when_run_doesnt_exist() -> None: - """Tests that the feedback endpoint can't accept feedback for a non existent run.""" + """Tests that the feedback endpoint can't accept feedback for a non-existent run.""" with patch("langserve.server.ls_client") as mocked_ls_client_package: - mocked_client = MagicMock(return_value=None) - mocked_ls_client_package.Client.return_value = mocked_client - mocked_client.create_feedback.side_effect = LangSmithNotFoundError("no run :/") - local_app = FastAPI() - add_routes( - local_app, - RunnableLambda(lambda foo: "hello"), - enable_feedback_endpoint=True, - ) - - async with get_async_test_client( - local_app, raise_app_exceptions=True - ) as async_client: - response = await async_client.post( - "/feedback", - json={ - "run_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", - "key": "silliness", - "score": 1000, - }, + with patch("langserve.server.tracing_is_enabled") as tracing_is_enabled: + tracing_is_enabled.return_value = True + mocked_client = MagicMock(return_value=None) + mocked_ls_client_package.Client.return_value = mocked_client + mocked_client.create_feedback.side_effect = LangSmithNotFoundError( + "no run :/" + ) + local_app = FastAPI() + add_routes( + local_app, + RunnableLambda(lambda foo: "hello"), + enable_feedback_endpoint=True, ) - assert response.status_code == 404 + + async with get_async_test_client( + local_app, raise_app_exceptions=True + ) as async_client: + response = await async_client.post( + "/feedback", + json={ + "run_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479", + "key": "silliness", + "score": 1000, + }, + ) + assert response.status_code == 404 @pytest.mark.asyncio From dd538fbb99ec626d75c3aa76853136dd1c41ea00 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Mon, 13 Nov 2023 10:52:52 -0500 Subject: [PATCH 3/3] x --- .github/workflows/langserve_ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/langserve_ci.yml b/.github/workflows/langserve_ci.yml index 080e83cf..7556ae8a 100644 --- a/.github/workflows/langserve_ci.yml +++ b/.github/workflows/langserve_ci.yml @@ -11,6 +11,7 @@ on: - '.github/workflows/_test.yml' - '.github/workflows/langserve_ci.yml' - 'langserve/**' + - 'tests/**' - 'examples/**' - 'pyproject.toml' - 'poetry.lock'