forked from ScottLogic/InferLLM
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
84 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import logging | ||
|
||
from .redis_session_middleware import get_session, set_session | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
CHAT_RESPONSE_SESSION_KEY = "chatresponse" | ||
|
||
def get_session_chat_response_ids() -> list[str]: | ||
return get_session(CHAT_RESPONSE_SESSION_KEY, []) | ||
|
||
|
||
def update_session_chat_response_ids(id:str): | ||
ids = get_session_chat_response_ids() | ||
ids.append(id) | ||
set_session(CHAT_RESPONSE_SESSION_KEY, ids) | ||
|
||
|
||
def clear_session_chat_response_ids(): | ||
set_session(CHAT_RESPONSE_SESSION_KEY, []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
from unittest.mock import patch, MagicMock | ||
from src.session.chat_response import (clear_session_chat_response_ids, | ||
get_session_chat_response_ids, | ||
update_session_chat_response_ids) | ||
|
||
@pytest.fixture | ||
def mock_request_context(): | ||
with patch('src.session.redis_session_middleware.request_context'): | ||
mock_instance = MagicMock() | ||
mock_instance.get.return_value.state.session = {} | ||
yield mock_instance | ||
|
||
|
||
def test_session_chat(mocker, mock_request_context): | ||
mocker.patch("src.session.redis_session_middleware.request_context", mock_request_context) | ||
|
||
update_session_chat_response_ids("one") | ||
update_session_chat_response_ids("two") | ||
assert get_session_chat_response_ids() == ["one", "two"] | ||
|
||
|
||
def test_clear_session_chat(mocker, mock_request_context): | ||
mocker.patch("src.session.redis_session_middleware.request_context", mock_request_context) | ||
|
||
update_session_chat_response_ids("123") | ||
assert get_session_chat_response_ids() == ["123"] | ||
clear_session_chat_response_ids() | ||
assert get_session_chat_response_ids() == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters