Skip to content

Commit 2333594

Browse files
authored
Merge pull request #83 from isabelizimm/trailing-slashes
remove trailing slashes
2 parents a04e5f3 + 47b6c5b commit 2333594

5 files changed

Lines changed: 33 additions & 24 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ repos:
99
# line too long and line before binary operator (black is ok with these)
1010
types:
1111
- python
12+
args:
13+
- "--max-line-length=90"
1214
- id: trailing-whitespace
1315
- id: end-of-file-fixer
1416
- id: check-yaml

vetiver/server.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import uvicorn
77
import requests
88
import pandas as pd
9-
import numpy as np
109
from typing import Callable, Union, List
1110

1211
from . import __version__
@@ -65,7 +64,7 @@ async def ping():
6564

6665
if self.check_ptype is True:
6766

68-
@app.post("/predict/")
67+
@app.post("/predict")
6968
async def prediction(
7069
input_data: Union[self.model.ptype, List[self.model.ptype]]
7170
):
@@ -82,7 +81,7 @@ async def prediction(
8281

8382
elif self.check_ptype is False:
8483

85-
@app.post("/predict/")
84+
@app.post("/predict")
8685
async def prediction(input_data: Request):
8786

8887
y = await input_data.json()
@@ -99,17 +98,25 @@ async def rapidoc():
9998
<!doctype html>
10099
<html>
101100
<head>
102-
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,user-scalable=yes">
101+
<meta name="viewport"
102+
content="width=device-width,minimum-scale=1,initial-scale=1,user-scalable=yes">
103103
<title>RapiDoc</title>
104-
<script type="module" src="https://unpkg.com/rapidoc@9.1.3/dist/rapidoc-min.js"></script>
104+
<script type="module"
105+
src="https://unpkg.com/rapidoc@9.3.3/dist/rapidoc-min.js"></script>
105106
</script></head>
106107
<body>
107108
<rapi-doc spec-url="{self.app.openapi_url[1:]}"
108-
id="thedoc" render-style="read" schema-style="tree"
109-
show-components="true" show-info="true" show-header="true"
109+
id="thedoc"
110+
render-style="read"
111+
schema-style="tree"
112+
show-components="true"
113+
show-info="true"
114+
show-header="true"
110115
allow-search="true"
111116
show-side-nav="false"
112-
allow-authentication="false" update-route="false" match-type="regex"
117+
allow-authentication="false"
118+
update-route="false"
119+
match-type="regex"
113120
theme="light"
114121
header-color="#F2C6AC"
115122
primary-color = "#8C2D2D">
@@ -143,15 +150,15 @@ def vetiver_post(
143150
"""
144151
if self.check_ptype is True:
145152

146-
@self.app.post("/" + endpoint_name + "/")
153+
@self.app.post("/" + endpoint_name)
147154
async def custom_endpoint(input_data: self.model.ptype):
148155
y = _prepare_data(input_data)
149156
new = endpoint_fx(pd.Series(y))
150157
return {endpoint_name: new.tolist()}
151158

152159
else:
153160

154-
@self.app.post("/" + endpoint_name + "/")
161+
@self.app.post("/" + endpoint_name)
155162
async def custom_endpoint(input_data: Request):
156163
y = await input_data.json()
157164
new = endpoint_fx(pd.Series(y))
@@ -204,7 +211,7 @@ def predict(endpoint, data: Union[dict, pd.DataFrame, pd.Series], **kw):
204211
"""
205212
if isinstance(endpoint, testclient.TestClient):
206213
requester = endpoint
207-
endpoint = "/predict/"
214+
endpoint = "/predict"
208215
else:
209216
requester = requests
210217

vetiver/tests/test_add_endpoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_endpoint_adds_ptype():
2828

2929
client = TestClient(app)
3030
data = {"B": 0, "C": 0, "D": 0}
31-
response = client.post("/sum/", json=data)
31+
response = client.post("/sum", json=data)
3232
assert response.status_code == 200, response.text
3333
assert response.json() == {"sum": 0}, response.json()
3434

@@ -38,6 +38,6 @@ def test_endpoint_adds_no_ptype():
3838

3939
client = TestClient(app)
4040
data = [0, 0, 0]
41-
response = client.post("/sum/", json=data)
41+
response = client.post("/sum", json=data)
4242
assert response.status_code == 200, response.text
4343
assert response.json() == {"sum": 0}, response.json()

vetiver/tests/test_pytorch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_torch_predict_ptype():
6363

6464
client = TestClient(v_api.app)
6565
data = {"0": 3.3}
66-
response = client.post("/predict/", json=data)
66+
response = client.post("/predict", json=data)
6767

6868
assert response.status_code == 200, response.text
6969
assert response.json() == {"prediction": [-4.060722351074219]}, response.text
@@ -77,7 +77,7 @@ def test_torch_predict_ptype_batch():
7777

7878
client = TestClient(v_api.app)
7979
data = [{"0": 3.3}, {"0": 3.3}]
80-
response = client.post("/predict/", json=data)
80+
response = client.post("/predict", json=data)
8181

8282
assert response.status_code == 200, response.text
8383
assert response.json() == {
@@ -93,7 +93,7 @@ def test_torch_predict_ptype_error():
9393

9494
client = TestClient(v_api.app)
9595
data = {"0": "bad"}
96-
response = client.post("/predict/", json=data)
96+
response = client.post("/predict", json=data)
9797

9898
assert response.status_code == 422, response.text # value is not a valid float
9999

@@ -106,7 +106,7 @@ def test_torch_predict_no_ptype_batch():
106106

107107
client = TestClient(v_api.app)
108108
data = [[3.3], [3.3]]
109-
response = client.post("/predict/", json=data)
109+
response = client.post("/predict", json=data)
110110
assert response.status_code == 200, response.text
111111
assert response.json() == {
112112
"prediction": [[-4.060722351074219], [-4.060722351074219]]
@@ -121,6 +121,6 @@ def test_torch_predict_no_ptype():
121121

122122
client = TestClient(v_api.app)
123123
data = [[3.3]]
124-
response = client.post("/predict/", json=data)
124+
response = client.post("/predict", json=data)
125125
assert response.status_code == 200, response.text
126126
assert response.json() == {"prediction": [[-4.060722351074219]]}, response.text

vetiver/tests/test_sklearn.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_predict_endpoint_ptype():
2424
np.random.seed(500)
2525
client = TestClient(_start_application().app)
2626
data = {"B": 0, "C": 0, "D": 0}
27-
response = client.post("/predict/", json=data)
27+
response = client.post("/predict", json=data)
2828
assert response.status_code == 200, response.text
2929
assert response.json() == {"prediction": [44.47]}, response.json()
3030

@@ -33,7 +33,7 @@ def test_predict_endpoint_ptype_batch():
3333
np.random.seed(500)
3434
client = TestClient(_start_application().app)
3535
data = [{"B": 0, "C": 0, "D": 0}, {"B": 0, "C": 0, "D": 0}]
36-
response = client.post("/predict/", json=data)
36+
response = client.post("/predict", json=data)
3737
assert response.status_code == 200, response.text
3838
assert response.json() == {"prediction": [44.47, 44.47]}, response.json()
3939

@@ -42,15 +42,15 @@ def test_predict_endpoint_ptype_error():
4242
np.random.seed(500)
4343
client = TestClient(_start_application().app)
4444
data = {"B": 0, "C": "a", "D": 0}
45-
response = client.post("/predict/", json=data)
45+
response = client.post("/predict", json=data)
4646
assert response.status_code == 422, response.text # value is not a valid integer
4747

4848

4949
def test_predict_endpoint_no_ptype():
5050
np.random.seed(500)
5151
client = TestClient(_start_application(save_ptype=False).app)
5252
data = "0,0,0"
53-
response = client.post("/predict/", json=data)
53+
response = client.post("/predict", json=data)
5454
assert response.status_code == 200, response.text
5555
assert response.json() == {"prediction": [44.47]}, response.json()
5656

@@ -59,7 +59,7 @@ def test_predict_endpoint_no_ptype_batch():
5959
np.random.seed(500)
6060
client = TestClient(_start_application(save_ptype=False).app)
6161
data = [["0,0,0"], ["0,0,0"]]
62-
response = client.post("/predict/", json=data)
62+
response = client.post("/predict", json=data)
6363
assert response.status_code == 200, response.text
6464
assert response.json() == {"prediction": [44.47, 44.47]}, response.json()
6565

@@ -69,4 +69,4 @@ def test_predict_endpoint_no_ptype_error():
6969
client = TestClient(_start_application(save_ptype=False).app)
7070
data = {"hell0", 9, 32.0}
7171
with pytest.raises(TypeError):
72-
client.post("/predict/", json=data)
72+
client.post("/predictt", json=data)

0 commit comments

Comments
 (0)