MCPcopy Index your code
hub / github.com/TaskingAI/TaskingAI / create

Method create

backend/app/operators/assistant/chat.py:14–49  ·  view source on GitHub ↗
(self, create_dict: Dict, **kwargs)

Source from the content-addressed store, hash-verified

12
13class ChatModelOperator(PostgresModelOperator):
14 async def create(self, create_dict: Dict, **kwargs) -> ModelEntity:
15 kwargs = self._check_kwargs(object_id_required=None, **kwargs)
16 assistant_id = kwargs.get("assistant_id")
17 name = create_dict.get("name", "")
18 metadata = create_dict.get("metadata", {})
19
20 async with self.postgres_pool.get_db_connection() as conn:
21 async with conn.transaction():
22 # validate assistant
23 assistant: Assistant = await assistant_ops.get(
24 postgres_conn=conn,
25 assistant_id=assistant_id,
26 )
27
28 # initialize chat memory
29 chat_memory: ChatMemory = assistant.memory.init_chat_memory()
30
31 # create chat
32 chat = await self._create_entity(
33 conn,
34 create_dict={
35 "memory": chat_memory.model_dump(),
36 "name": name,
37 "metadata": metadata,
38 },
39 **kwargs,
40 )
41
42 # update assistant num_chats
43 await assistant_ops.update(
44 postgres_conn=conn,
45 assistant_id=assistant_id,
46 update_dict={"num_chats": assistant.num_chats + 1},
47 )
48
49 return chat
50
51 async def delete(self, **kwargs) -> ModelEntity:
52 kwargs = self._check_kwargs(object_id_required=True, **kwargs)

Callers

nothing calls this directly

Calls 7

_check_kwargsMethod · 0.80
get_db_connectionMethod · 0.80
init_chat_memoryMethod · 0.80
_create_entityMethod · 0.80
getMethod · 0.45
model_dumpMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected