mindnet/app/routers/tools.py
Lars 104ddddb96
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 4s
app/routers/tools.py aktualisiert
2025-10-07 13:38:49 +02:00

85 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
app/routers/tools.py — Tool-Definitionen für Ollama/n8n/MCP (read-only)
Zweck:
Liefert Funktions-Schemas (OpenAI-/Ollama-kompatibles Tool-JSON) für:
- mindnet_query -> POST /query
- mindnet_subgraph -> GET /graph/{note_id}
Kompatibilität:
Python 3.12+, FastAPI 0.110+
Version:
0.1.1 (query ODER query_vector möglich)
Stand:
2025-10-07
Nutzung:
app.include_router(tools.router, prefix="/tools", tags=["tools"])
Änderungsverlauf:
0.1.1 (2025-10-07) mindnet_query: oneOf(query, query_vector).
0.1.0 (2025-10-07) Erstanlage.
"""
from __future__ import annotations
from fastapi import APIRouter
router = APIRouter()
TOOLS = {
"tools": [
{
"type": "function",
"function": {
"name": "mindnet_query",
"description": "Hybrid-Retrieval über mindnet (Semantik + Edges).",
"parameters": {
"type": "object",
"oneOf": [
{"required": ["query"]},
{"required": ["query_vector"]}
],
"properties": {
"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)."
},
"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.)"}
}
}
}
},
{
"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"]
}
}
}
]
}
@router.get("/ollama")
def get_ollama_tools():
return TOOLS