-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd1e44b
commit ca7672c
Showing
6 changed files
with
187 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
Defines API paths for llm endpoints. | ||
""" | ||
|
||
from typing import List, Optional | ||
|
||
from fastapi import APIRouter, Body | ||
|
||
from .. import application | ||
from ..route import EncodingAPIRoute | ||
|
||
router = APIRouter(route_class=EncodingAPIRoute) | ||
|
||
|
||
@router.get("/llm") | ||
def llm(text: str, maxlength: Optional[int] = None): | ||
""" | ||
Runs a LLM pipeline for the input text. | ||
Args: | ||
text: input text | ||
maxlength: optional response max length | ||
Returns: | ||
response text | ||
""" | ||
|
||
kwargs = {"maxlength": maxlength} if maxlength else {} | ||
return application.get().pipeline("llm", text, **kwargs) | ||
|
||
|
||
@router.post("/batchllm") | ||
def batchllm(texts: List[str] = Body(...), maxlength: Optional[int] = Body(default=None)): | ||
""" | ||
Runs a LLM pipeline for the input texts. | ||
Args: | ||
texts: input texts | ||
maxlength: optional response max length | ||
Returns: | ||
list of response texts | ||
""" | ||
|
||
kwargs = {"maxlength": maxlength} if maxlength else {} | ||
return application.get().pipeline("llm", texts, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
Defines API paths for rag endpoints. | ||
""" | ||
|
||
from typing import List, Optional | ||
|
||
from fastapi import APIRouter, Body | ||
|
||
from .. import application | ||
from ..route import EncodingAPIRoute | ||
|
||
router = APIRouter(route_class=EncodingAPIRoute) | ||
|
||
|
||
@router.get("/rag") | ||
def rag(query: str, maxlength: Optional[int] = None): | ||
""" | ||
Runs a RAG pipeline for the input query. | ||
Args: | ||
query: input RAG query | ||
maxlength: optional response max length | ||
Returns: | ||
answer | ||
""" | ||
|
||
kwargs = {"maxlength": maxlength} if maxlength else {} | ||
return application.get().pipeline("rag", query, **kwargs) | ||
|
||
|
||
@router.post("/batchrag") | ||
def batchrag(queries: List[str] = Body(...), maxlength: Optional[int] = Body(default=None)): | ||
""" | ||
Runs a RAG pipeline for the input queries. | ||
Args: | ||
queries: input RAG queries | ||
maxlength: optional response max length | ||
Returns: | ||
list of answers | ||
""" | ||
|
||
kwargs = {"maxlength": maxlength} if maxlength else {} | ||
return application.get().pipeline("rag", queries, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters