From 22831cabed126343ceb09178d19662ca98d1aca8 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Thu, 16 Nov 2023 12:44:02 -0500 Subject: [PATCH] Reorganize readme, add documentation to config hash endpoints (#241) * Re organize some sections in the readme * Use more highlighting in the readme for sections where attention is required * Expand doc-strings for config hash endpoints ![image](https://github.com/langchain-ai/langserve/assets/3205522/9cfb8039-b9e6-4079-b677-d8a298575763) --- README.md | 43 ++++++++++++++++++++++--------------------- langserve/server.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 05e1228a..c674d666 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,17 @@ We will be releasing a hosted version of LangServe for one-click deployments of ## Security * Vulnerability in Versions 0.0.13 - 0.0.15 -- playground endpoint allows accessing arbitrary files on server. [Resolved in 0.0.16](https://github.com/langchain-ai/langserve/pull/98). + +## Installation + +For both client and server: + +```bash +pip install "langserve[all]" +``` + +or `pip install "langserve[client]"` for client code, and `pip install "langserve[server]"` for server code. + ## LangChain CLI 🛠️ @@ -110,17 +121,16 @@ if __name__ == "__main__": If you've deployed the server above, you can view the generated OpenAPI docs using: +> ⚠️ If using pydantic v2, docs will not be generated for invoke/batch/stream/stream_log. See [Pydantic](#pydantic) section below for more details. + ```sh curl localhost:8000/docs ``` make sure to **add** the `/docs` suffix. -Below will return a 404 until you define a `@app.get("/")` - -```sh -localhost:8000 -``` +> ⚠️ Index page `/` is not defined by **design**, so `curl localhost:8000` or visiting the URL +> will return a 404. If you want content at `/` define an endpoint `@app.get("/")`. ### Client @@ -245,16 +255,6 @@ In addition, for configurable runnables, the playground will allow you to config

-## Installation - -For both client and server: - -```bash -pip install "langserve[all]" -``` - -or `pip install "langserve[client]"` for client code, and `pip install "langserve[server]"` for server code. - ## Legacy Chains LangServe works with both Runnables (constructed via [LangChain Expression Language](https://python.langchain.com/docs/expression_language/)) and legacy chains (inheriting from `Chain`). @@ -262,12 +262,6 @@ However, some of the input schemas for legacy chains may be incomplete/incorrect This can be fixed by updating the `input_schema` property of those chains in LangChain. If you encounter any errors, please open an issue on THIS repo, and we will work to address it. -## Handling Authentication - -If you need to add authentication to your server, -please reference FastAPI's [security documentation](https://fastapi.tiangolo.com/tutorial/security/) -and [middleware documentation](https://fastapi.tiangolo.com/tutorial/middleware/). - ## Deployment ### Deploy to GCP @@ -289,6 +283,13 @@ Except for these limitations, we expect the API endpoints, the playground and an ## Advanced +## Handling Authentication + +If you need to add authentication to your server, +please reference FastAPI's [security documentation](https://fastapi.tiangolo.com/tutorial/security/) +and [middleware documentation](https://fastapi.tiangolo.com/tutorial/middleware/). + + ### Files LLM applications often deal with files. There are different architectures diff --git a/langserve/server.py b/langserve/server.py index c7b075d4..11320a8e 100644 --- a/langserve/server.py +++ b/langserve/server.py @@ -534,7 +534,10 @@ def _route_name_with_config(name: str) -> str: "name": route_tags_with_config[0], "description": ( "Endpoints with a default configuration " - "set by `config_hash` path parameter." + "set by `config_hash` path parameter. " + "Used in conjunction with share links generated using the " + "LangServe UI playground. " + "The hash is an LZString compressed JSON string." ), }, ] @@ -1101,6 +1104,13 @@ async def feedback(feedback_create_req: FeedbackCreateRequest) -> Feedback: response_model=InvokeResponse, tags=route_tags_with_config, name=_route_name_with_config("invoke"), + description=( + "This endpoint is to be used with share links generated by the " + "LangServe playground. " + "The hash is an LZString compressed JSON string. " + "For regular use cases, use the /invoke endpoint without " + "the `c/{config_hash}` path parameter." + ), ) @app.post( f"{namespace}/invoke", @@ -1120,6 +1130,13 @@ async def _invoke_docs( response_model=BatchResponse, tags=route_tags_with_config, name=_route_name_with_config("batch"), + description=( + "This endpoint is to be used with share links generated by the " + "LangServe playground. " + "The hash is an LZString compressed JSON string. " + "For regular use cases, use the /batch endpoint without " + "the `c/{config_hash}` path parameter." + ), ) @app.post( f"{namespace}/batch", @@ -1139,6 +1156,13 @@ async def _batch_docs( include_in_schema=True, tags=route_tags_with_config, name=_route_name_with_config("stream"), + description=( + "This endpoint is to be used with share links generated by the " + "LangServe playground. " + "The hash is an LZString compressed JSON string. " + "For regular use cases, use the /stream endpoint without " + "the `c/{config_hash}` path parameter." + ), ) @app.post( f"{namespace}/stream", @@ -1198,6 +1222,13 @@ async def _stream_docs( include_in_schema=True, tags=route_tags_with_config, name=_route_name_with_config("stream_log"), + description=( + "This endpoint is to be used with share links generated by the " + "LangServe playground. " + "The hash is an LZString compressed JSON string. " + "For regular use cases, use the /stream_log endpoint without " + "the `c/{config_hash}` path parameter." + ), ) @app.post( f"{namespace}/stream_log",