Add sync_default_tools function to manage system-provided tools
- Introduce a new `sync_default_tools` function in `session.py` to ensure essential reusable tools are created without overwriting existing edits. - Update the `lifespan` context manager in `app.py` to call `sync_default_tools`, enhancing the initialization process for the application. - This change improves the management of default tools within the system, ensuring they are available for use while preserving user modifications.
This commit is contained in:
@@ -16,7 +16,7 @@ from contextlib import asynccontextmanager
|
|||||||
|
|
||||||
import settings
|
import settings
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from db.session import sync_interface_definitions
|
from db.session import sync_default_tools, sync_interface_definitions
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
@@ -36,6 +36,7 @@ from routes import (
|
|||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(_app: FastAPI):
|
async def lifespan(_app: FastAPI):
|
||||||
await sync_interface_definitions()
|
await sync_interface_definitions()
|
||||||
|
await sync_default_tools()
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,3 +45,39 @@ async def sync_interface_definitions() -> None:
|
|||||||
"field_schema": json.dumps({"fields": definition["fields"]}),
|
"field_schema": json.dumps({"fields": definition["fields"]}),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def sync_default_tools() -> None:
|
||||||
|
"""Ensure system-provided reusable tools exist without overwriting edits."""
|
||||||
|
async with engine.begin() as conn:
|
||||||
|
await conn.execute(
|
||||||
|
text(
|
||||||
|
"INSERT INTO tools "
|
||||||
|
"(id, name, function_name, type, description, definition, secrets, status) "
|
||||||
|
"VALUES ("
|
||||||
|
":id, :name, :function_name, :type, :description, "
|
||||||
|
"CAST(:definition AS jsonb), CAST(:secrets AS jsonb), :status"
|
||||||
|
") "
|
||||||
|
"ON CONFLICT (function_name) DO NOTHING"
|
||||||
|
),
|
||||||
|
{
|
||||||
|
"id": "tool_end_call_default",
|
||||||
|
"name": "结束对话",
|
||||||
|
"function_name": "end_call",
|
||||||
|
"type": "end_call",
|
||||||
|
"description": "当用户明确要求结束对话,或任务已完成时调用。",
|
||||||
|
"definition": json.dumps(
|
||||||
|
{
|
||||||
|
"schema_version": 1,
|
||||||
|
"type": "end_call",
|
||||||
|
"config": {
|
||||||
|
"message_type": "none",
|
||||||
|
"custom_message": "",
|
||||||
|
"capture_reason": True,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
),
|
||||||
|
"secrets": "{}",
|
||||||
|
"status": "active",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user