Skip to content

Commit bda1c7f

Browse files
committed
Exsits & id get method
1 parent 09afb19 commit bda1c7f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

cognition_objects/conversation.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ def get(project_id: str, conversation_id: str) -> CognitionConversation:
2525
)
2626

2727

28+
def exists(project_id: str, conversation_id: str) -> bool:
29+
return (
30+
session.query(CognitionConversation)
31+
.filter(
32+
CognitionConversation.project_id == project_id,
33+
CognitionConversation.id == conversation_id,
34+
)
35+
.first()
36+
is not None
37+
)
38+
39+
2840
def get_conversations_to_clean_up() -> List[Tuple[str, str, str]]:
2941
query = """
3042
SELECT cc.id, cc.project_id, o.id organization_id
@@ -285,6 +297,23 @@ def has_error(project_id: str, conversation_id: str) -> bool:
285297
return False
286298

287299

300+
def create_and_get_id(
301+
project_id: str,
302+
user_id: str,
303+
has_tmp_files: bool = False,
304+
with_commit: bool = True,
305+
created_at: Optional[datetime] = None,
306+
) -> CognitionConversation:
307+
created_conversation = create(
308+
project_id=project_id,
309+
user_id=user_id,
310+
has_tmp_files=has_tmp_files,
311+
with_commit=with_commit,
312+
created_at=created_at,
313+
)
314+
return str(created_conversation.id)
315+
316+
288317
def create(
289318
project_id: str,
290319
user_id: str,

0 commit comments

Comments
 (0)