|
1 | 1 | from typing import Dict |
2 | | -from app.admin.bots.schemas import Bot |
| 2 | +from app.admin.bots.schemas import Bot, NLUConfiguration |
3 | 3 | from app.admin.entities.store import list_entities, bulk_import_entities |
4 | 4 | from app.admin.intents.store import list_intents, bulk_import_intents |
5 | 5 | from app.database import database |
| 6 | +from datetime import datetime |
6 | 7 |
|
7 | 8 | bot_collection = database.get_collection("bot") |
8 | 9 |
|
9 | 10 |
|
10 | | -async def add_bot(data: dict): |
11 | | - await bot_collection.insert_one(data) |
| 11 | +async def ensure_default_bot(): |
| 12 | + # Check if the default bot exists |
| 13 | + default_bot = await bot_collection.find_one({"name": "default"}) |
| 14 | + if default_bot is None: |
| 15 | + # Create the default bot |
| 16 | + default_bot_data = Bot(name="default") |
| 17 | + default_bot_data.created_at = datetime.utcnow() |
| 18 | + default_bot_data.updated_at = datetime.utcnow() |
| 19 | + await bot_collection.insert_one( |
| 20 | + default_bot_data.model_dump(exclude={"id": True}) |
| 21 | + ) |
| 22 | + return default_bot_data |
| 23 | + return Bot.model_validate(default_bot) |
12 | 24 |
|
13 | 25 |
|
14 | 26 | async def get_bot(name: str) -> Bot: |
15 | 27 | bot = await bot_collection.find_one({"name": name}) |
16 | 28 | return Bot.model_validate(bot) |
17 | 29 |
|
18 | 30 |
|
19 | | -async def get_config(name: str) -> Dict: |
| 31 | +async def get_nlu_config(name: str) -> NLUConfiguration: |
20 | 32 | bot = await get_bot(name) |
21 | | - return bot.config |
| 33 | + return bot.nlu_config |
22 | 34 |
|
23 | 35 |
|
24 | | -async def update_config(name: str, entity_data: dict): |
25 | | - await bot_collection.update_one({"name": name}, {"$set": {"config": entity_data}}) |
| 36 | +async def update_nlu_config(name: str, nlu_config: dict): |
| 37 | + await bot_collection.update_one( |
| 38 | + {"name": name}, {"$set": {"nlu_config": nlu_config}} |
| 39 | + ) |
26 | 40 |
|
27 | 41 |
|
28 | 42 | async def export_bot(name) -> Dict: |
|
0 commit comments