|
1 | 1 | """FastAPI server for LLMSearch.""" |
2 | 2 |
|
3 | 3 | import os |
| 4 | + |
| 5 | +# This is a temporary solution due to incompatimbility of ChromaDB with latest version of Protobuf |
| 6 | +os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python" |
| 7 | + |
4 | 8 | from functools import lru_cache |
5 | 9 | from typing import Any, List |
6 | 10 |
|
|
24 | 28 |
|
25 | 29 |
|
26 | 30 | load_dotenv() |
27 | | -langchain.debug = True # Enable debug mode for langchain # type: ignore |
| 31 | +langchain.debug = False |
28 | 32 |
|
29 | 33 |
|
30 | 34 | # Load the configuration |
@@ -101,7 +105,7 @@ def get_llm_bundle_cached() -> LLMBundle: |
101 | 105 | description="pyLLMSearch MCP Server", |
102 | 106 | describe_all_responses=True, # Include all possible response schemas |
103 | 107 | describe_full_response_schema=True, # Include full JSON schema in descriptions |
104 | | - include_operations=["rag_retrieve_chunks", "rag_generate_answer"], |
| 108 | + include_operations=["rag_retrieve_chunks", "rag_generate_answer", "rag_generate_answer_simple"], |
105 | 109 | ) |
106 | 110 |
|
107 | 111 |
|
@@ -145,6 +149,26 @@ async def llmsearch( |
145 | 149 | ) |
146 | 150 | return output.model_dump() |
147 | 151 |
|
| 152 | +@api_app.get("/rag", operation_id="rag_generate_answer_simple") |
| 153 | +async def llmsearch_simple( |
| 154 | + question: str, |
| 155 | + label: str = "", |
| 156 | + llm_bundle: LLMBundle = Depends(get_llm_bundle_cached), |
| 157 | +) -> str: |
| 158 | + """Retrieves answer to the question from the embedded documents, using semantic search.""" |
| 159 | + if label and (label not in get_config().embeddings.labels): |
| 160 | + raise HTTPException( |
| 161 | + status_code=404, |
| 162 | + detail=f"Label '{label}' doesn't exist. Use GET /labels to get a list of labels.", |
| 163 | + ) |
| 164 | + |
| 165 | + output = get_and_parse_response( |
| 166 | + query=question, |
| 167 | + llm_bundle=llm_bundle, |
| 168 | + config=get_config(), |
| 169 | + label=label, |
| 170 | + ) |
| 171 | + return output.response |
148 | 172 |
|
149 | 173 | @api_app.get("/semantic/{question}", operation_id="rag_retrieve_chunks") |
150 | 174 | async def semanticsearch(question: str): |
|
0 commit comments