init
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.pomodoro.service import PomodoroService
|
||||
|
||||
TOOL_DEFINITIONS: list[dict[str, Any]] = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_pomodoro_status",
|
||||
"description": "Получить текущий статус помидоро-таймера",
|
||||
"parameters": {"type": "object", "properties": {}, "required": []},
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "start_pomodoro",
|
||||
"description": "Запустить помидоро-таймер",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"duration_min": {
|
||||
"type": "integer",
|
||||
"description": "Длительность в минутах, по умолчанию 25",
|
||||
},
|
||||
"task_note": {
|
||||
"type": "string",
|
||||
"description": "Над чем работаем в этой сессии",
|
||||
},
|
||||
},
|
||||
"required": [],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "stop_pomodoro",
|
||||
"description": "Остановить текущий помидоро-таймер",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"result": {
|
||||
"type": "string",
|
||||
"description": "Краткий отчёт о том, что сделано",
|
||||
},
|
||||
"completed": {
|
||||
"type": "boolean",
|
||||
"description": "True если задача полностью завершена",
|
||||
},
|
||||
},
|
||||
"required": [],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_pomodoro_history",
|
||||
"description": "Получить историю завершённых помидоро-сессий",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"limit": {
|
||||
"type": "integer",
|
||||
"description": "Сколько последних сессий вернуть, по умолчанию 10",
|
||||
}
|
||||
},
|
||||
"required": [],
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def execute_tool(db: Session, name: str, arguments: dict[str, Any]) -> str:
|
||||
service = PomodoroService(db)
|
||||
|
||||
try:
|
||||
if name == "get_pomodoro_status":
|
||||
result = service.get_status()
|
||||
elif name == "start_pomodoro":
|
||||
result = service.start(
|
||||
duration_min=arguments.get("duration_min", 25),
|
||||
task_note=arguments.get("task_note", ""),
|
||||
)
|
||||
elif name == "stop_pomodoro":
|
||||
result = service.stop(
|
||||
result=arguments.get("result", ""),
|
||||
completed=arguments.get("completed", False),
|
||||
)
|
||||
elif name == "get_pomodoro_history":
|
||||
result = service.history(limit=arguments.get("limit", 10))
|
||||
else:
|
||||
return json.dumps({"error": f"Unknown tool: {name}"}, ensure_ascii=False)
|
||||
|
||||
return json.dumps(result, ensure_ascii=False)
|
||||
except ValueError as exc:
|
||||
return json.dumps({"error": str(exc)}, ensure_ascii=False)
|
||||
Reference in New Issue
Block a user