1
- import logging
2
1
import os
3
2
import time
4
3
from typing import Any , Dict , Union
5
4
6
- from azure .cosmos import exceptions
7
5
from azure .cosmos .aio import ContainerProxy , CosmosClient
8
6
from azure .identity .aio import AzureDeveloperCliCredential , ManagedIdentityCredential
9
7
from quart import Blueprint , current_app , jsonify , make_response , request
17
15
from decorators import authenticated
18
16
from error import error_response
19
17
20
- logger = logging .getLogger ("scripts" )
21
-
22
18
chat_history_cosmosdb_bp = Blueprint ("chat_history_cosmos" , __name__ , static_folder = "static" )
23
19
24
20
@@ -71,14 +67,7 @@ async def post_chat_history(auth_claims: Dict[str, Any]):
71
67
72
68
batch_operations = [("upsert" , (session ,))] + [("upsert" , (message ,)) for message in messages ]
73
69
74
- try :
75
- await container .execute_item_batch (batch_operations = batch_operations , partition_key = [entra_oid , session_id ])
76
- except exceptions .CosmosBatchOperationError as e :
77
- error_operation_index = e .error_index
78
- error_operation_response = e .operation_responses [error_operation_index ]
79
- error_operation = batch_operations [error_operation_index ]
80
- logger .error (f"Batch operation failed: { error_operation_response } for operation { error_operation } " )
81
- return jsonify ({"error" : "Batch operation failed" }), 400
70
+ await container .execute_item_batch (batch_operations = batch_operations , partition_key = [entra_oid , session_id ])
82
71
return jsonify ({}), 201
83
72
except Exception as error :
84
73
return error_response (error , "/chat_history" )
@@ -99,7 +88,6 @@ async def get_chat_history_sessions(auth_claims: Dict[str, Any]):
99
88
return jsonify ({"error" : "User OID not found" }), 401
100
89
101
90
try :
102
- # get the count and continuation token from the request URL
103
91
count = int (request .args .get ("count" , 10 ))
104
92
continuation_token = request .args .get ("continuation_token" )
105
93
@@ -110,7 +98,6 @@ async def get_chat_history_sessions(auth_claims: Dict[str, Any]):
110
98
max_item_count = count ,
111
99
)
112
100
113
- # set the continuation token for the next page
114
101
pager = res .by_page (continuation_token )
115
102
116
103
# Get the first page, and the continuation token
0 commit comments