Skip to content

Commit

Permalink
Changes based on Marks call
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelafox committed Jan 29, 2025
1 parent 952917c commit e46dc9f
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 258 deletions.
20 changes: 4 additions & 16 deletions app/backend/chat_history/cosmosdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,12 @@ async def post_chat_history(auth_claims: Dict[str, Any]):
"type": "message_pair",
"question": message_pair[0],
"response": message_pair[1],
"order": ind,
"timestamp": None,
}
)

batch_operations = [("upsert", (session_item,))] + [
("upsert", (message_pair_item,)) for message_pair_item in message_pair_items
]

await container.execute_item_batch(batch_operations=batch_operations, partition_key=[entra_oid, session_id])
return jsonify({}), 201
except Exception as error:
Expand Down Expand Up @@ -148,30 +145,21 @@ async def get_chat_history_session(auth_claims: Dict[str, Any], session_id: str)

try:
res = container.query_items(
query="SELECT * FROM c WHERE c.session_id = @session_id",
parameters=[dict(name="@session_id", value=session_id)],
query="SELECT * FROM c WHERE c.session_id = @session_id AND c.type = @type",
parameters=[dict(name="@session_id", value=session_id), dict(name="@type", value="message_pair")],
partition_key=[entra_oid, session_id],
)

message_pairs = []
session = None
async for page in res.by_page():
async for item in page:
if item.get("type") == "session":
session = item
elif item.get("type") == "message_pair":
message_pairs.append([item["question"], item["response"]])

if session is None:
return jsonify({"error": "Session not found"}), 404
message_pairs.append([item["question"], item["response"]])

return (
jsonify(
{
"id": session.get("id"),
"id": session_id,
"entra_oid": entra_oid,
"title": session.get("title"),
"timestamp": session.get("timestamp"),
"answers": message_pairs,
}
),
Expand Down
2 changes: 1 addition & 1 deletion app/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ azure-core==1.30.2
# msrest
azure-core-tracing-opentelemetry==1.0.0b11
# via azure-monitor-opentelemetry
azure-cosmos==4.7.0
azure-cosmos==4.9.0
# via -r requirements.in
azure-identity==1.17.1
# via
Expand Down
Loading

0 comments on commit e46dc9f

Please sign in to comment.