Skip to content

Commit

Permalink
Update feedback enabled endpoint (#332)
Browse files Browse the repository at this point in the history
Update feedback endabled endpoint behavior
  • Loading branch information
eyurtsev authored Dec 15, 2023
1 parent 5eaff89 commit aefd94a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
18 changes: 13 additions & 5 deletions langserve/api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ def __init__(
including events that occurred on the server side.
Be sure not to include any sensitive information in the callback events.
enable_feedback_endpoint: Whether to enable an endpoint for logging feedback
to LangSmith. Enabled by default. If this flag is disabled or LangSmith
tracing is not enabled for the runnable, then 400 errors will be thrown
to LangSmith. Disabled by default. If this flag is disabled or LangSmith
tracing is not enabled for the runnable, then 4xx errors will be thrown
when accessing the feedback endpoint
per_req_config_modifier: optional function that can be used to update the
RunnableConfig for a given run based on the raw request. This is useful,
Expand Down Expand Up @@ -1070,15 +1070,23 @@ async def create_feedback(
comment=feedback_from_langsmith.comment,
)

async def check_feedback_enabled(self, config_hash: str = "") -> None:
"""Check if feedback is enabled for the runnable."""
if not tracing_is_enabled() or not self._enable_feedback_endpoint:
async def _check_feedback_enabled(self, config_hash: str = "") -> None:
"""Check if feedback is enabled for the runnable.
This endpoint is private since it will be deprecated in the future.
"""
if not (await self.check_feedback_enabled(config_hash)):
raise HTTPException(
400,
"The feedback endpoint is only accessible when LangSmith is "
+ "enabled on your LangServe server.",
)

async def check_feedback_enabled(self, config_hash: str = "") -> bool:
"""Check if feedback is enabled for the runnable."""
return self._enable_feedback_endpoint or not tracing_is_enabled()


_MODEL_REGISTRY = {}
_SEEN_NAMES = set()
6 changes: 6 additions & 0 deletions langserve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@ def _route_name_with_config(name: str) -> str:

check_feedback_enabled = app.head(
namespace + "/feedback",
)(api_handler._check_feedback_enabled)

# Add get version which returns True/False for flow control
# instead of 200/400 for flow control
app.get(
namespace + "/feedback",
)(api_handler.check_feedback_enabled)

if endpoint_configuration.is_config_hash_enabled: # Is this needed?
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/test_server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,7 @@ async def test_endpoint_configurations() -> None:
("GET", "/config_schema", {}),
("GET", "/playground/index.html", {}),
("HEAD", "/feedback", {}),
("GET", "/feedback", {}),
# Check config hashes
("POST", "/c/1234/invoke", {"input": 1}),
("POST", "/c/1234/batch", {"inputs": [1, 2]}),
Expand Down

0 comments on commit aefd94a

Please sign in to comment.