-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
97 lines (74 loc) · 2.8 KB
/
main.py
File metadata and controls
97 lines (74 loc) · 2.8 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import asyncio
import logging
import os
import importlib.metadata
import colorlog
from dotenv import load_dotenv
from mcp.server import NotificationOptions, Server
from mcp.server.models import InitializationOptions
from mcp.server.stdio import stdio_server
from rag_server import ObsidianRAGServer
from mcp_handlers import register_handlers
logger = logging.getLogger("obsidian-rag")
def setup_logging():
"""Sets up colored logging for the application."""
handler = colorlog.StreamHandler()
formatter = colorlog.ColoredFormatter(
'%(log_color)s%(levelname)-8s %(name)s: %(message)s%(reset)s',
log_colors={
'DEBUG': 'cyan',
'INFO': 'white',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red,bg_white',
},
reset=True,
style='%'
)
handler.setFormatter(formatter)
# Getting the root logger for 'obsidian-rag' and adding the handler:
app_logger = logging.getLogger('obsidian-rag')
app_logger.addHandler(handler)
app_logger.setLevel(logging.INFO)
app_logger.propagate = False # Prevent duplicate logs in the root logger
async def main():
"""Main function"""
# Setting up logging first:
setup_logging()
# Loading environment variables from the .env file:
load_dotenv()
vault_path = os.getenv("OBSIDIAN_VAULT_PATH")
milvus_host = os.getenv("MILVUS_HOST", "localhost")
milvus_port = int(os.getenv("MILVUS_PORT", "19530"))
if not vault_path:
logger.error("OBSIDIAN_VAULT_PATH environment variable not set. Please create a .env file.")
return
logger.info(f"Starting ObsidianRAG with vault: {vault_path}")
# Initializing the RAG server:
rag_server = ObsidianRAGServer(vault_path, milvus_host, milvus_port)
await rag_server.initialize()
# Initializing the MCP server:
server = Server("obsidian-rag")
register_handlers(server, rag_server)
# Getting server version from package metadata:
try:
server_version = importlib.metadata.version("personal-notes-assistant")
except importlib.metadata.PackageNotFoundError:
logger.warning("Package 'personal-notes-assistant' not found. Defaulting version to '0.0.0'")
server_version = "0.0.0"
# Running the MCP server:
async with stdio_server() as (read_stream, write_stream):
await server.run(
read_stream,
write_stream,
InitializationOptions(
server_name="obsidian-rag",
server_version=server_version,
capabilities=server.get_capabilities(
notification_options=NotificationOptions(),
experimental_capabilities={},
),
),
)
if __name__ == "__main__":
asyncio.run(main())