Improve message schema, assign or create main agent chat automatically
This commit is contained in:
1 parent
4aa374820c
commit
b907698829
3 files changed
+47
-33
No files matched your search
+30
-13
@@ -73,12 +73,22 @@ class App:
|
||||
user_connections[remotename] = []
|
||||
user_connections[remotename].append(channel)
|
||||
|
||||
def create_agent(self, user_id, name, agentname, description, picture, kind, data):
|
||||
def create_agent(self, user_id, name, agentname, description, picture, kind, data, main_chat_id=None):
|
||||
with self.sql_session() as session:
|
||||
if main_chat_id is None:
|
||||
chat = db.Chat()
|
||||
chat.user_id = user_id
|
||||
chat.name = name
|
||||
|
||||
session.add(chat)
|
||||
session.commit()
|
||||
main_chat_id = chat.id
|
||||
|
||||
agent = db.Agent()
|
||||
agent.user_id = user_id
|
||||
agent.name = name
|
||||
agent.agentname = agentname
|
||||
agent.main_chat_id = main_chat_id
|
||||
agent.description = description
|
||||
agent.picture = picture
|
||||
agent.kind = kind
|
||||
@@ -87,6 +97,13 @@ class App:
|
||||
session.add(agent)
|
||||
session.commit()
|
||||
print(f"Created agent #{agent.id}: {agent.name}")
|
||||
|
||||
membership = db.Membership()
|
||||
membership.chat_id = main_chat_id
|
||||
membership.agent_id = agent.id
|
||||
session.add(membership)
|
||||
session.commit()
|
||||
|
||||
return agent.id
|
||||
|
||||
def create_chat(self, user_id, name, description, picture, members=[]):
|
||||
@@ -368,22 +385,22 @@ class App:
|
||||
asyncio.create_task(control.received_message(message))
|
||||
|
||||
def generate_default_user_data(self, user_id):
|
||||
agent_id = self.create_agent(
|
||||
user_id=user_id,
|
||||
name="Intro",
|
||||
description="Introduces you to the application.",
|
||||
picture=None,
|
||||
kind="basic", # Should be 'intro'
|
||||
data={}
|
||||
)
|
||||
|
||||
# Create a chat with that agent in it
|
||||
chat_id = self.create_chat(
|
||||
user_id=user_id,
|
||||
name="Initial Chat",
|
||||
description=None,
|
||||
description="First user chat with Intro.",
|
||||
picture=None,
|
||||
members=[agent_id],
|
||||
members=[],
|
||||
)
|
||||
agent_id = self.create_agent(
|
||||
user_id=user_id,
|
||||
name="Intro",
|
||||
agentname="intro",
|
||||
main_chat_id=chat_id,
|
||||
description="Introduces you to the application.",
|
||||
picture=None,
|
||||
kind="conversation", # Should be 'intro'
|
||||
data={}
|
||||
)
|
||||
|
||||
def create_chat_thread(self, chat_id, name=None):
|
||||
|
||||
Reference in new issue
Block a user