Skip to content

Commit

Permalink
Fix request url path (#304)
Browse files Browse the repository at this point in the history
Under the current configuration, if the request URL ends with a slash, a
307 jump will actually occur.

for example:

  ```bash
curl --location --request POST 'http://localhost:8000/joke/invoke/' \
     --header 'Content-Type: application/json' \
     --data-raw '{
         "input": {
             "topic": "cats"
         }
     }'
```

In fact, 2 requests were generated:

```bash
INFO: 127.0.0.1:53936 - "POST /joke/invoke/ HTTP/1.1" 307 Temporary
Redirect
INFO: 127.0.0.1:53936 - "POST /joke/invoke HTTP/1.1" 200 OK
```

If this is the case, users should be directed to use the URL directly without the slashes

Co-authored-by: Eugene Yurtsev <[email protected]>
  • Loading branch information
169 and eyurtsev authored Dec 9, 2023
1 parent 7a82f03 commit f669334
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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:
Expand All @@ -56,7 +56,7 @@ or `pip install "langserve[client]"` for client code, and `pip install "langserv

Use the `LangChain` CLI to bootstrap a `LangServe` project quickly.

To use the langchain CLI make sure that you have a recent version of `langchain-cli`
To use the langchain CLI make sure that you have a recent version of `langchain-cli`
installed. You can install it with `pip install -U langchain-cli`.

```sh
Expand All @@ -65,11 +65,11 @@ langchain app new ../path/to/directory

## Examples

Get your LangServe instance started quickly with
Get your LangServe instance started quickly with
[LangChain Templates](https://github.com/langchain-ai/langchain/blob/master/templates/README.md).

For more examples, see the templates
[index](https://github.com/langchain-ai/langchain/blob/master/templates/docs/INDEX.md)
For more examples, see the templates
[index](https://github.com/langchain-ai/langchain/blob/master/templates/docs/INDEX.md)
or the [examples](https://github.com/langchain-ai/langserve/tree/main/examples) directory.

### Server
Expand Down Expand Up @@ -127,7 +127,7 @@ If you've deployed the server above, you can view the generated OpenAPI docs usi
curl localhost:8000/docs
```

make sure to **add** the `/docs` suffix.
make sure to **add** the `/docs` suffix.

> ⚠️ 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("/")`.
Expand Down Expand Up @@ -192,7 +192,7 @@ Python using `requests`:
```python
import requests
response = requests.post(
"http://localhost:8000/joke/invoke/",
"http://localhost:8000/joke/invoke",
json={'input': {'topic': 'cats'}}
)
response.json()
Expand All @@ -201,7 +201,7 @@ response.json()
You can also use `curl`:

```sh
curl --location --request POST 'http://localhost:8000/joke/invoke/' \
curl --location --request POST 'http://localhost:8000/joke/invoke' \
--header 'Content-Type: application/json' \
--data-raw '{
"input": {
Expand Down Expand Up @@ -264,12 +264,12 @@ If you encounter any errors, please open an issue on THIS repo, and we will work

## Deployment

### Deploy to Azure
### Deploy to Azure

You can deploy to Azure using Azure Container Apps (Serverless):

```
az containerapp up --name [container-app-name] --source . --resource-group [resource-group-name] --environment [environment-name] --ingress external --target-port 8001 --env-vars=OPENAI_API_KEY=your_key
az containerapp up --name [container-app-name] --source . --resource-group [resource-group-name] --environment [environment-name] --ingress external --target-port 8001 --env-vars=OPENAI_API_KEY=your_key
```

You can find more info [here](https://learn.microsoft.com/en-us/azure/container-apps/containerapp-up)
Expand All @@ -296,7 +296,7 @@ LangServe provides support for Pydantic 2 with some limitations.
1. OpenAPI docs will not be generated for invoke/batch/stream/stream_log when using Pydantic V2. Fast API does not support [mixing pydantic v1 and v2 namespaces].
2. LangChain uses the v1 namespace in Pydantic v2. Please read the [following guidelines to ensure compatibility with LangChain](https://github.com/langchain-ai/langchain/discussions/9337)

Except for these limitations, we expect the API endpoints, the playground and any other features to work as expected.
Except for these limitations, we expect the API endpoints, the playground and any other features to work as expected.

## Advanced

Expand All @@ -319,8 +319,8 @@ that can be made to implement file processing; at a high level:

You should determine what is the appropriate architecture for your application.

Currently, to upload files by value to a runnable, use base64 encoding for the
file (`multipart/form-data` is not supported yet).
Currently, to upload files by value to a runnable, use base64 encoding for the
file (`multipart/form-data` is not supported yet).

Here's an [example](https://github.com/langchain-ai/langserve/tree/main/examples/file_processing) that shows
how to use base64 encoding to send a file to a remote runnable.
Expand Down Expand Up @@ -363,7 +363,7 @@ add_routes(app, runnable)

### Custom User Types

Inherit from `CustomUserType` if you want the data to de-serialize into a
Inherit from `CustomUserType` if you want the data to de-serialize into a
pydantic model rather than the equivalent dict representation.

At the moment, this type only works *server* side and is used
Expand Down Expand Up @@ -395,7 +395,7 @@ def func(foo: Foo) -> int:
# runnable = RunnableLambda(func).with_types( # <-- Not needed in this case
# input_schema=Foo,
# output_schema=int,
#
#
add_routes(app, RunnableLambda(func), path="/foo")
```

Expand Down Expand Up @@ -448,7 +448,7 @@ class FileProcessingRequest(CustomUserType):

```

Example widget:
Example widget:

<p align="center">
<img src="https://github.com/langchain-ai/langserve/assets/3205522/52199e46-9464-4c2e-8be8-222250e08c3f" width="50%"/>
Expand All @@ -470,5 +470,5 @@ add_routes(app, chain, enabled_endpoints=["invoke", "batch", "config_hashes"])
Disable: The code below will disable the playground for the chain

```python
add_routes(app, chain, disabled_endpoints=["playground"])
add_routes(app, chain, disabled_endpoints=["playground"])
```

0 comments on commit f669334

Please sign in to comment.