2025-10-07 13:19:48 +02:00
|
|
|
|
"""
|
|
|
|
|
|
app/routers/tools.py — Tool-Definitionen für Ollama/n8n/MCP (read-only)
|
2025-10-07 13:30:12 +02:00
|
|
|
|
|
|
|
|
|
|
Zweck:
|
|
|
|
|
|
Liefert Funktions-Schemas (OpenAI-/Ollama-kompatibles Tool-JSON) für:
|
2025-10-07 13:38:49 +02:00
|
|
|
|
- mindnet_query -> POST /query
|
|
|
|
|
|
- mindnet_subgraph -> GET /graph/{note_id}
|
2025-10-07 13:30:12 +02:00
|
|
|
|
Kompatibilität:
|
|
|
|
|
|
Python 3.12+, FastAPI 0.110+
|
|
|
|
|
|
Version:
|
2025-10-07 13:38:49 +02:00
|
|
|
|
0.1.1 (query ODER query_vector möglich)
|
2025-10-07 13:30:12 +02:00
|
|
|
|
Stand:
|
|
|
|
|
|
2025-10-07
|
|
|
|
|
|
Nutzung:
|
|
|
|
|
|
app.include_router(tools.router, prefix="/tools", tags=["tools"])
|
|
|
|
|
|
Änderungsverlauf:
|
2025-10-07 13:38:49 +02:00
|
|
|
|
0.1.1 (2025-10-07) – mindnet_query: oneOf(query, query_vector).
|
2025-10-07 13:30:12 +02:00
|
|
|
|
0.1.0 (2025-10-07) – Erstanlage.
|
2025-10-07 13:19:48 +02:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
from fastapi import APIRouter
|
|
|
|
|
|
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
|
|
TOOLS = {
|
|
|
|
|
|
"tools": [
|
2025-10-07 13:30:12 +02:00
|
|
|
|
{
|
|
|
|
|
|
"type": "function",
|
|
|
|
|
|
"function": {
|
|
|
|
|
|
"name": "mindnet_query",
|
|
|
|
|
|
"description": "Hybrid-Retrieval über mindnet (Semantik + Edges).",
|
|
|
|
|
|
"parameters": {
|
|
|
|
|
|
"type": "object",
|
2025-10-07 13:38:49 +02:00
|
|
|
|
"oneOf": [
|
|
|
|
|
|
{"required": ["query"]},
|
|
|
|
|
|
{"required": ["query_vector"]}
|
|
|
|
|
|
],
|
2025-10-07 13:30:12 +02:00
|
|
|
|
"properties": {
|
2025-10-07 13:38:49 +02:00
|
|
|
|
"query": {
|
|
|
|
|
|
"type": "string",
|
|
|
|
|
|
"description": "Freitext-Query; wird serverseitig in 384-d Embedding konvertiert."
|
|
|
|
|
|
},
|
|
|
|
|
|
"query_vector": {
|
|
|
|
|
|
"type": "array",
|
|
|
|
|
|
"items": {"type": "number"},
|
|
|
|
|
|
"description": "Direkter 384-d Query-Vektor (optional)."
|
|
|
|
|
|
},
|
2025-10-07 13:30:12 +02:00
|
|
|
|
"top_k": {"type":"integer","default":10,"minimum":1,"maximum":50},
|
|
|
|
|
|
"expand_depth": {"type":"integer","default":1,"minimum":0,"maximum":3},
|
|
|
|
|
|
"edge_types": {
|
|
|
|
|
|
"type":"array","items":{"type":"string"},
|
|
|
|
|
|
"default": ["references","belongs_to","prev","next"]
|
|
|
|
|
|
},
|
|
|
|
|
|
"filters": {"type":"object","description":"payload-Filter (tags etc.)"}
|
2025-10-07 13:38:49 +02:00
|
|
|
|
}
|
2025-10-07 13:30:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"type": "function",
|
|
|
|
|
|
"function": {
|
|
|
|
|
|
"name": "mindnet_subgraph",
|
|
|
|
|
|
"description": "Gibt die Nachbarschaft (Edges) einer Note/Seed-ID zurück.",
|
|
|
|
|
|
"parameters": {
|
|
|
|
|
|
"type":"object",
|
|
|
|
|
|
"properties": {
|
|
|
|
|
|
"note_id":{"type":"string"},
|
|
|
|
|
|
"depth":{"type":"integer","default":1,"minimum":0,"maximum":3},
|
|
|
|
|
|
"edge_types":{
|
|
|
|
|
|
"type":"array","items":{"type":"string"},
|
|
|
|
|
|
"default":["references","belongs_to","prev","next","backlink"]
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
"required":["note_id"]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-07 13:19:48 +02:00
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/ollama")
|
|
|
|
|
|
def get_ollama_tools():
|
|
|
|
|
|
return TOOLS
|