Skip to content

Commit 48b8ac6

Browse files
committed
Added API by complexity hybrid fallback in ollama_config
1 parent 6419a28 commit 48b8ac6

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

Project_Andrew/Andrew.rar

517 Bytes
Binary file not shown.

Project_Andrew/caios_bridge.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import subprocess
2121
import platform
2222
import atexit
23+
import socket
2324
from datetime import datetime, timezone
2425
from typing import Dict, Any
2526

@@ -105,6 +106,18 @@ def _bootstrap_shared_memory() -> Dict[str, Any]:
105106

106107
_spawned_procs = []
107108

109+
def _port_in_use(host: str, port: int, timeout: float = 1.0) -> bool:
110+
"""
111+
Raw TCP connect check — works even for SSE/streaming servers that don't
112+
respond correctly to JSON-RPC probes (e.g. windows-mcp already running).
113+
Returns True if something is listening on that port, regardless of protocol.
114+
"""
115+
try:
116+
with socket.create_connection((host, port), timeout=timeout):
117+
return True
118+
except OSError:
119+
return False
120+
108121
def _wait_until_ready(check_fn, timeout=20, interval=0.5) -> bool:
109122
deadline = time.time() + timeout
110123
while time.time() < deadline:
@@ -153,11 +166,19 @@ def start_services() -> None:
153166
client.fs_available
154167
)
155168
if platform.system() == 'Windows':
156-
_start_service(
157-
'windows-mcp',
158-
'uvx windows-mcp serve --transport sse --host localhost --port 8000',
159-
client.win_available
160-
)
169+
# windows-mcp uses SSE transport — its endpoint doesn't respond to
170+
# JSON-RPC initialize probes, so win_available() returns False even
171+
# when it's already running (e.g. survived a terminal close).
172+
# Check the port directly first before attempting a new launch.
173+
if _port_in_use('localhost', 8000):
174+
print('[BRIDGE] windows-mcp already running on port 8000')
175+
else:
176+
_start_service(
177+
'windows-mcp',
178+
'uvx windows-mcp serve --transport sse --host localhost --port 8000',
179+
lambda: _port_in_use('localhost', 8000),
180+
timeout=15
181+
)
161182
else:
162183
print('[BRIDGE] caios_mcp_client.py not found — MCP servers not auto-started')
163184

Project_Andrew/ollama_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ def get_cpol_ollama_params(
155155
# 'legal': None, # fall back to default sovereign model
156156
# }
157157

158+
# Uncomment DENSITY_MODEL_MAP to route queries to API by complexity.
159+
# In get_cpol_ollama_params() — replaces the current single model fallback
160+
# if contradiction_density < 0.3 and available:
161+
# model = available[-1] # lightest/fastest available (Gemma 4, 7B, etc.)
162+
# elif contradiction_density < 0.7 and available:
163+
# model = preferred_model or available[0] # your default
164+
# else:
165+
# # High complexity — use heaviest available (Qwen 27b, DeepSeek-R1)
166+
# model = preferred_model or available[0]
167+
158168
def get_model_for_domain(domain: str, default_model: str) -> str:
159169
"""
160170
Route to a specialist model based on CPOL-classified domain.

0 commit comments

Comments
 (0)