Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ client = chromadb.CloudClient(
|
|
| 27 |
tenant=tenant,
|
| 28 |
database=database
|
| 29 |
)
|
| 30 |
-
print(f"Connection to chromabd successful
|
| 31 |
|
| 32 |
# === COLLECTION VALIDATION ===
|
| 33 |
# Ensure the required collection exists and has data
|
|
@@ -350,42 +350,75 @@ def get_available_sources() -> Dict[str, Any]:
|
|
| 350 |
except Exception as e:
|
| 351 |
return {"error": f"Failed to get sources: {str(e)}", "sources": [], "success": False}
|
| 352 |
|
| 353 |
-
|
| 354 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
"""
|
| 356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
Args:
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
Returns:
|
| 362 |
-
|
| 363 |
"""
|
| 364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
|
| 366 |
-
def say_hello(name: str) -> str:
|
| 367 |
-
"""
|
| 368 |
-
A tool that returns message "Hello <name>"
|
| 369 |
-
Args:
|
| 370 |
-
str: name to say hello to.
|
| 371 |
-
Returns:
|
| 372 |
-
Hello <name>
|
| 373 |
-
"""
|
| 374 |
-
return f"Hello, {name}"
|
| 375 |
|
| 376 |
with gr.Blocks() as demo:
|
| 377 |
gr.Markdown(
|
| 378 |
"""
|
| 379 |
-
This is a
|
| 380 |
-
This
|
| 381 |
This tool is MCP-only, so it does not have a UI.
|
| 382 |
"""
|
| 383 |
)
|
| 384 |
gr.api(
|
| 385 |
-
|
| 386 |
-
)
|
| 387 |
-
gr.api(
|
| 388 |
-
say_hello
|
| 389 |
)
|
| 390 |
|
| 391 |
_, url, _ = demo.launch(mcp_server=True)
|
|
|
|
| 27 |
tenant=tenant,
|
| 28 |
database=database
|
| 29 |
)
|
| 30 |
+
print(f"Connection to chromabd successful...")
|
| 31 |
|
| 32 |
# === COLLECTION VALIDATION ===
|
| 33 |
# Ensure the required collection exists and has data
|
|
|
|
| 350 |
except Exception as e:
|
| 351 |
return {"error": f"Failed to get sources: {str(e)}", "sources": [], "success": False}
|
| 352 |
|
| 353 |
+
# MCP Tool Definitions
|
| 354 |
+
def search_rs_studies(
|
| 355 |
+
query: str,
|
| 356 |
+
num_results: int = 5,
|
| 357 |
+
source_filter: Optional[str] = None,
|
| 358 |
+
task_type: str = "search"
|
| 359 |
+
) -> str:
|
| 360 |
"""
|
| 361 |
+
Search the RS Studies knowledge base for relevant information.
|
| 362 |
+
|
| 363 |
+
This tool provides semantic search across RS trading system documentation,
|
| 364 |
+
Chennai meetup transcripts, and Q&A content with optimized EmbeddingGemma prompts.
|
| 365 |
+
|
| 366 |
Args:
|
| 367 |
+
query: Your search question or topic (required)
|
| 368 |
+
num_results: Number of results to return (1-50, default: 5)
|
| 369 |
+
source_filter: Limit search to specific source:
|
| 370 |
+
- 'rs_stkege_01': RS trading system documentation
|
| 371 |
+
- 'cheenai_meet_full': Chennai meetup transcripts
|
| 372 |
+
- 'QnAYoutubeChannel': Q&A discussions
|
| 373 |
+
- None: Search all sources (default)
|
| 374 |
+
task_type: Search optimization using EmbeddingGemma task-specific prompts:
|
| 375 |
+
- 'search'/'retrieval_query': General search (default)
|
| 376 |
+
- 'question'/'question_answering': Question answering format
|
| 377 |
+
- 'fact'/'fact_checking': Fact checking format
|
| 378 |
+
- 'classification': Text classification tasks
|
| 379 |
+
- 'clustering': Document clustering and grouping
|
| 380 |
+
- 'semantic_similarity': Semantic similarity assessment
|
| 381 |
+
- 'code_retrieval': Code search and retrieval
|
| 382 |
+
|
| 383 |
Returns:
|
| 384 |
+
JSON string with search results including content, sources, and similarity scores
|
| 385 |
"""
|
| 386 |
+
# Validate parameters
|
| 387 |
+
if not query or not query.strip():
|
| 388 |
+
return json.dumps({"error": "Query cannot be empty", "results": [], "success": False})
|
| 389 |
+
|
| 390 |
+
num_results = max(1, min(num_results, config.MAX_NUM_RESULTS))
|
| 391 |
+
|
| 392 |
+
if source_filter and source_filter not in config.VALID_SOURCES:
|
| 393 |
+
return json.dumps({
|
| 394 |
+
"error": f"Invalid source_filter. Must be one of: {config.VALID_SOURCES}",
|
| 395 |
+
"results": [],
|
| 396 |
+
"success": False
|
| 397 |
+
})
|
| 398 |
+
|
| 399 |
+
valid_task_types = list(EmbeddingGemmaPrompts.TASKS.keys())
|
| 400 |
+
if task_type not in valid_task_types:
|
| 401 |
+
return json.dumps({
|
| 402 |
+
"error": f"Invalid task_type. Must be one of: {valid_task_types}",
|
| 403 |
+
"results": [],
|
| 404 |
+
"success": False
|
| 405 |
+
})
|
| 406 |
+
|
| 407 |
+
# Perform search
|
| 408 |
+
results = search_knowledge_base(query, num_results, source_filter, task_type)
|
| 409 |
+
return json.dumps(results, indent=2)
|
| 410 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
with gr.Blocks() as demo:
|
| 413 |
gr.Markdown(
|
| 414 |
"""
|
| 415 |
+
This is a MCP only tool for RS Studies
|
| 416 |
+
This connects to a remote chromadb instance.
|
| 417 |
This tool is MCP-only, so it does not have a UI.
|
| 418 |
"""
|
| 419 |
)
|
| 420 |
gr.api(
|
| 421 |
+
search_rs_studies
|
|
|
|
|
|
|
|
|
|
| 422 |
)
|
| 423 |
|
| 424 |
_, url, _ = demo.launch(mcp_server=True)
|