Skip to content
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

Do not enable langsmith tracer globally #205

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/langserve_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- '.github/workflows/_test.yml'
- '.github/workflows/langserve_ci.yml'
- 'langserve/**'
- 'tests/**'
- 'examples/**'
- 'pyproject.toml'
- 'poetry.lock'
Expand Down
134 changes: 66 additions & 68 deletions tests/unit_tests/test_server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,7 +112,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:
Expand Down Expand Up @@ -1555,88 +1553,88 @@ 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,
}

json_response = response.json()
json_response = response.json()

assert "id" in json_response
del json_response["id"]
assert "id" in json_response
del json_response["id"]

assert json_response == expected_response_json
assert json_response == 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
Expand Down