Skip to content

Commit b0aacb2

Browse files
committed
Change cast to type annotation, add initial test
1 parent 9863e67 commit b0aacb2

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

app/backend/chat_history/cosmosdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def post_chat_history(auth_claims: Dict[str, Any]):
2424
if not current_app.config[CONFIG_CHAT_HISTORY_COSMOS_ENABLED]:
2525
return jsonify({"error": "Chat history not enabled"}), 405
2626

27-
container = cast(ContainerProxy, current_app.config[CONFIG_COSMOS_HISTORY_CONTAINER])
27+
container: ContainerProxy = current_app.config[CONFIG_COSMOS_HISTORY_CONTAINER]
2828
if not container:
2929
return jsonify({"error": "Chat history not enabled"}), 405
3030

@@ -193,6 +193,6 @@ async def setup_clients():
193193

194194
@chat_history_cosmosdb_bp.after_app_serving
195195
async def close_clients():
196-
cosmos_client = cast(CosmosClient, current_app.config.get(CONFIG_COSMOS_HISTORY_CLIENT))
196+
cosmos_client: CosmosClient = current_app.config.get(CONFIG_COSMOS_HISTORY_CLIENT)
197197
if cosmos_client:
198198
await cosmos_client.close()

docs/deploy_features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ You should typically enable these features before running `azd up`. Once you've
77
* [Using GPT-4](#using-gpt-4)
88
* [Using text-embedding-3 models](#using-text-embedding-3-models)
99
* [Enabling GPT-4 Turbo with Vision](#enabling-gpt-4-turbo-with-vision)
10-
* [Enabling chat history](#enabling-chat-history)
10+
* [Enabling client-side chat history](#enabling-client-side-chat-history)
1111
* [Enabling persistent chat history with Azure Cosmos DB](#enabling-persistent-chat-history-with-azure-cosmos-db)
1212
* [Enabling language picker](#enabling-language-picker)
1313
* [Enabling speech input/output](#enabling-speech-inputoutput)
@@ -151,7 +151,7 @@ If you have already deployed:
151151

152152
This section covers the integration of GPT-4 Vision with Azure AI Search. Learn how to enhance your search capabilities with the power of image and text indexing, enabling advanced search functionalities over diverse document types. For a detailed guide on setup and usage, visit our [Enabling GPT-4 Turbo with Vision](gpt4v.md) page.
153153

154-
## Enabling chat history
154+
## Enabling client-side chat history
155155

156156
This feature allows users to view the chat history of their conversation, stored in the browser using [IndexedDB](https://developer.mozilla.org/docs/Web/API/IndexedDB_API). That means the chat history will be available only on the device where the chat was initiated. To enable browser-stored chat history, run:
157157

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ async def auth_public_documents_client(
419419
monkeypatch.setenv("USE_LOCAL_PDF_PARSER", "true")
420420
monkeypatch.setenv("USE_LOCAL_HTML_PARSER", "true")
421421
monkeypatch.setenv("AZURE_DOCUMENTINTELLIGENCE_SERVICE", "test-documentintelligence-service")
422+
monkeypatch.setenv("USE_CHAT_HISTORY_COSMOS", "true")
423+
monkeypatch.setenv("AZURE_COSMOSDB_ACCOUNT", "test-cosmosdb-account")
424+
monkeypatch.setenv("AZURE_CHAT_HISTORY_DATABASE", "test-cosmosdb-database")
425+
monkeypatch.setenv("AZURE_CHAT_HISTORY_CONTAINER", "test-cosmosdb-container")
426+
422427
for key, value in request.param.items():
423428
monkeypatch.setenv(key, value)
424429

tests/test_cosmosdb.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
from azure.cosmos.aio import ContainerProxy
3+
4+
5+
@pytest.mark.asyncio
6+
async def test_chathistory(auth_public_documents_client, monkeypatch):
7+
8+
async def mock_upsert_item(container_proxy, item, **kwargs):
9+
assert item["id"] == "123"
10+
assert item["answers"] == [["This is a test message"]]
11+
assert item["entra_oid"] == "OID_X"
12+
assert item["title"] == "This is a test message"
13+
14+
monkeypatch.setattr(ContainerProxy, "upsert_item", mock_upsert_item)
15+
16+
response = await auth_public_documents_client.post(
17+
"/chat_history",
18+
headers={"Authorization": "Bearer MockToken"},
19+
json={
20+
"id": "123",
21+
"answers": [["This is a test message"]],
22+
},
23+
)
24+
assert response.status_code == 201

0 commit comments

Comments
 (0)