-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfluence_tool.py
More file actions
69 lines (55 loc) · 1.95 KB
/
confluence_tool.py
File metadata and controls
69 lines (55 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
confluence_tool.py
The search_confluence(query) tool for Pattern 2 integration.
Plugs directly into your existing Flask app alongside the weather tool.
"""
import json
from confluence_rag import ConfluenceRAG
# Singleton - load once, reuse
_rag: ConfluenceRAG | None = None
def get_rag() -> ConfluenceRAG:
global _rag
if _rag is None:
_rag = ConfluenceRAG()
return _rag
def search_confluence(query: str, top_k: int = 5) -> dict:
"""
Search the Confluence knowledge base for information.
Returns relevant content with source URLs.
"""
try:
rag = get_rag()
if rag.collection.count() == 0:
return {
"error": "Knowledge base is empty. Please run ingest.py first.",
"results": []
}
results = rag.search(query, top_k=top_k)
context = rag.format_context(results)
return {
"query": query,
"results": results,
"context": context,
"total_chunks_searched": rag.collection.count()
}
except Exception as e:
return {"error": str(e), "results": []}
# ── Tool definition for Pattern 2 (add to your tools list in app.py) ─────────
CONFLUENCE_TOOL_DEFINITION = {
"name": "search_confluence",
"description": "Search the internal knowledge base (Confluence) for information, documentation, guides, or any internal content. Use this when the user asks about documentation, processes, guides, or internal knowledge.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The search query - describe what information you're looking for"
}
},
"required": ["query"]
}
}
if __name__ == "__main__":
# Quick test
result = search_confluence("How to integrate Confluence with Slack?")
print(json.dumps(result, indent=2))