Skip to content

Commit adfc4fa

Browse files
author
Kabir Khan
authored
Merge pull request #3 from microsoft/example-request
add example request body for easier testing
2 parents 4b23cca + 3e25a84 commit adfc4fa

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

{{cookiecutter.project_slug}}/app/api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from starlette.middleware.cors import CORSMiddleware
1010
from starlette.responses import RedirectResponse
1111
import spacy
12+
import srsly
1213
import uvicorn
1314

1415
from app.models import (
@@ -31,6 +32,8 @@
3132
openapi_prefix=prefix,
3233
)
3334

35+
example_request = srsly.read_json("app/data/example_request.json")
36+
3437
nlp = spacy.load("{{cookiecutter.project_language}}")
3538
extractor = SpacyExtractor(nlp)
3639

@@ -41,7 +44,7 @@ def docs_redirect():
4144

4245

4346
@app.post("/entities", response_model=RecordsResponse, tags=["NER"])
44-
async def extract_entities(body: RecordsRequest):
47+
async def extract_entities(body: RecordsRequest = Body(..., example=example_request)):
4548
"""Extract Named Entities from a batch of Records."""
4649

4750
res = []
@@ -63,7 +66,7 @@ async def extract_entities(body: RecordsRequest):
6366
@app.post(
6467
"/entities_by_type", response_model=RecordsEntitiesByTypeResponse, tags=["NER"]
6568
)
66-
async def extract_entities_by_type(body: RecordsRequest):
69+
async def extract_entities_by_type(body: RecordsRequest = Body(..., example=example_request)):
6770
"""Extract Named Entities from a batch of Records separated by entity label.
6871
This route can be used directly as a Cognitive Skill in Azure Search
6972
For Documentation on integration with Azure Search, see here:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"values": [
3+
{
4+
"recordId": "a1",
5+
"data": {
6+
"text": "But Google is starting from behind. The company made a late push into hardware, and Apple's Siri, available on iPhones, and Amazon's Alexa software, which runs on its Echo and Dot devices, have clear leads in consumer adoption.",
7+
"language": "en"
8+
}
9+
}
10+
]
11+
}

0 commit comments

Comments
 (0)