diff --git a/langserve/api_handler.py b/langserve/api_handler.py index 32d06983..c9d9d6bd 100644 --- a/langserve/api_handler.py +++ b/langserve/api_handler.py @@ -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, @@ -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() diff --git a/langserve/server.py b/langserve/server.py index c86be79f..8f6d09ba 100644 --- a/langserve/server.py +++ b/langserve/server.py @@ -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? diff --git a/tests/unit_tests/test_server_client.py b/tests/unit_tests/test_server_client.py index 37e2224e..deff0ff8 100644 --- a/tests/unit_tests/test_server_client.py +++ b/tests/unit_tests/test_server_client.py @@ -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]}),