Skip to content

Commit c8d8054

Browse files
committed
update readme
1 parent 2d2804c commit c8d8054

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

muse_as_service/client/README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
### Client
2-
MUSE as Service has next endpoints:
2+
MUSE as Service has the following endpoints:
33
<pre>
4-
- /login - POST request with `username` and `password` to get JWT tokens (access and refresh)
5-
- /logout/access - POST request to remove JWT access token (JWT access token required)
6-
- /logout/refresh - POST request to remove JWT refresh token (JWT refresh token required)
7-
- /token/refresh - POST request to refresh JWT access token (JWT refresh token required)
8-
- /tokenize - GET request for `sentence` tokenization (JWT access token required)
9-
- /embed - GET request for `sentence` embedding (JWT access token required)
4+
- /login - POST request with `username` and `password` to get tokens (access and refresh)
5+
- /logout - POST request to remove tokens (access and refresh)
6+
- /token/refresh - POST request to refresh access token (refresh token required)
7+
- /tokenize - GET request for `sentence` tokenization (access token required)
8+
- /embed - GET request for `sentence` embedding (access token required)
109
</pre>
1110

1211
You can use python **requests** package to work with HTTP requests:
@@ -20,29 +19,37 @@ port = 5000
2019

2120
sentences = ["This is sentence example.", "This is yet another sentence example."]
2221

22+
# start session
23+
session = requests.Session()
24+
2325
# login
24-
response = requests.post(
26+
response = session.post(
2527
url=f"http://{ip}:{port}/login",
2628
json={"username": "admin", "password": "admin"},
2729
)
28-
token = response.json()["access_token"]
2930

3031
# tokenizer
31-
response = requests.get(
32+
response = session.get(
3233
url=f"http://{ip}:{port}/tokenize",
3334
params={"sentence": sentences},
34-
headers={"Authorization": f"Bearer {token}"},
3535
)
3636
tokenized_sentence = response.json()["tokens"]
3737

3838
# embedder
39-
response = requests.get(
39+
response = session.get(
4040
url=f"http://{ip}:{port}/embed",
4141
params={"sentence": sentences},
42-
headers={"Authorization": f"Bearer {token}"},
4342
)
4443
embedding = np.array(response.json()["embedding"])
4544

45+
# logout
46+
response = session.post(
47+
url=f"http://{ip}:{port}/logout",
48+
)
49+
50+
# close session
51+
session.close()
52+
4653
# results
4754
print(tokenized_sentence) # [
4855
# ["▁This", "▁is", "▁sentence", "▁example", "."],
@@ -51,7 +58,7 @@ print(tokenized_sentence) # [
5158
print(embedding.shape) # (2, 512)
5259
```
5360

54-
But it is better to use the built-in client **MUSEClient** for sentence tokenization and embedding, that wraps the functionality of the python **requests** package and provides a user with a simpler interface.
61+
However it is better to use built-in client **MUSEClient** for sentence tokenization and embedding, that wraps the functionality of the python **requests** package and provides user with a simpler interface.
5562

5663
Instead of using endpoints, listed above, directly, **MUSEClient** provides the following methods to work with:
5764
<pre>

muse_as_service/database/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ python muse_as_service/database/add_user.py --username {username} --password {pa
1414
**NOTE**: run it from parent directory `muse_as_service`
1515

1616
**NOTE**: no passwords are stored in the database, only their hashes.
17+
18+
To remove the user with `username` run:
19+
```
20+
python muse_as_service/database/remove_user.py --username {username}
21+
```
22+
**NOTE**: run it from parent directory `muse_as_service`

0 commit comments

Comments
 (0)