/ src / python / txtai / api / routers / segmentation.py
segmentation.py
 1  """
 2  Defines API paths for segmentation endpoints.
 3  """
 4  
 5  from typing import List
 6  
 7  from fastapi import APIRouter, Body
 8  
 9  from .. import application
10  from ..route import EncodingAPIRoute
11  
12  router = APIRouter(route_class=EncodingAPIRoute)
13  
14  
15  @router.get("/segment")
16  def segment(text: str):
17      """
18      Segments text into semantic units.
19  
20      Args:
21          text: input text
22  
23      Returns:
24          segmented text
25      """
26  
27      return application.get().pipeline("segmentation", (text,))
28  
29  
30  @router.post("/batchsegment")
31  def batchsegment(texts: List[str] = Body(...)):
32      """
33      Segments text into semantic units.
34  
35      Args:
36          texts: list of texts to segment
37  
38      Returns:
39          list of segmented text
40      """
41  
42      return application.get().pipeline("segmentation", (texts,))