Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add stripthink parameter to LLM API endpoint, closes #980

davidmezzetti4447053dd403
diff --git a/src/python/txtai/api/routers/llm.py b/src/python/txtai/api/routers/llm.py
index 2d2a1a0c..e9d5d45a 100644
--- a/src/python/txtai/api/routers/llm.py
+++ b/src/python/txtai/api/routers/llm.py
@@ -14,7 +14,7 @@ router = APIRouter(route_class=EncodingAPIRoute)
@router.get("/llm")
-def llm(text: str, maxlength: Optional[int] = None, stream: Optional[bool] = False):
+def llm(text: str, maxlength: Optional[int] = None, stream: Optional[bool] = False, stripthink: Optional[bool] = False):
"""
Runs a LLM pipeline for the input text.
@@ -28,7 +28,8 @@ def llm(text: str, maxlength: Optional[int] = None, stream: Optional[bool] = Fal
"""
# Build keyword arguments
- kwargs = {key: value for key, value in [("stream", stream), ("maxlength", maxlength)] if value}
+ params = [("maxlength", maxlength), ("stream", stream), ("stripthink", stripthink)]
+ kwargs = {key: value for key, value in params if value}
# Run pipeline
result = application.get().pipeline("llm", text, **kwargs)
@@ -38,7 +39,12 @@ def llm(text: str, maxlength: Optional[int] = None, stream: Optional[bool] = Fal
@router.post("/batchllm")
-def batchllm(texts: List[str] = Body(...), maxlength: Optional[int] = Body(default=None), stream: Optional[bool] = Body(default=False)):
+def batchllm(
+ texts: List[str] = Body(...),
+ maxlength: Optional[int] = Body(default=None),
+ stream: Optional[bool] = Body(default=False),
+ stripthink: Optional[bool] = Body(default=False),
+):
"""
Runs a LLM pipeline for the input texts.
@@ -52,7 +58,8 @@ def batchllm(texts: List[str] = Body(...), maxlength: Optional[int] = Body(defau
"""
# Build keyword arguments
- kwargs = {key: value for key, value in [("stream", stream), ("maxlength", maxlength)] if value}
+ params = [("maxlength", maxlength), ("stream", stream), ("stripthink", stripthink)]
+ kwargs = {key: value for key, value in params if value}
# Run pipeline
result = application.get().pipeline("llm", texts, **kwargs)
diff --git a/src/python/txtai/api/routers/rag.py b/src/python/txtai/api/routers/rag.py
index 6679c9c7..c8f68041 100644
--- a/src/python/txtai/api/routers/rag.py
+++ b/src/python/txtai/api/routers/rag.py
@@ -14,7 +14,7 @@ router = APIRouter(route_class=EncodingAPIRoute)
@router.get("/rag")
-def rag(query: str, maxlength: Optional[int] = None, stream: Optional[bool] = False):
+def rag(query: str, maxlength: Optional[int] = None, stream: Optional[bool] = False, stripthink: Optional[bool] = False):
"""
Runs a RAG pipeline for the input query.
@@ -28,7 +28,8 @@ def rag(query: str, maxlength: Optional[int] = None, stream: Optional[bool] = Fa
"""
# Build keyword arguments
- kwargs = {key: value for key, value in [("stream", stream), ("maxlength", maxlength)] if value}
+ params = [("maxlength", maxlength), ("stream", stream), ("stripthink", stripthink)]
+ kwargs = {key: value for key, value in params if value}
# Run pipeline
result = application.get().pipeline("rag", query, **kwargs)
@@ -38,7 +39,12 @@ def rag(query: str, maxlength: Optional[int] = None, stream: Optional[bool] = Fa
@router.post("/batchrag")
-def batchrag(queries: List[str] = Body(...), maxlength: Optional[int] = Body(default=None), stream: Optional[bool] = Body(default=False)):
+def batchrag(
+ queries: List[str] = Body(...),
+ maxlength: Optional[int] = Body(default=None),
+ stream: Optional[bool] = Body(default=False),
+ stripthink: Optional[bool] = Body(default=False),
+):
"""
Runs a RAG pipeline for the input queries.
@@ -52,7 +58,8 @@ def batchrag(queries: List[str] = Body(...), maxlength: Optional[int] = Body(def
"""
# Build keyword arguments
- kwargs = {key: value for key, value in [("stream", stream), ("maxlength", maxlength)] if value}
+ params = [("maxlength", maxlength), ("stream", stream), ("stripthink", stripthink)]
+ kwargs = {key: value for key, value in params if value}
# Run pipeline
result = application.get().pipeline("rag", queries, **kwargs)