mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-13 14:15:52 +00:00
feat: improved compatability layer and responses api handing
This commit is contained in:
1 parent
3e978759de
commit
0adf88abed
45 files changed
+2566
-337
No files matched your search
@@ -127,6 +127,84 @@ def test_stream_cache_miss(mock_make_redis):
|
||||
mock_redis_instance.set.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@patch("application.cache.get_redis_instance")
|
||||
def test_stream_cache_preserves_json_chunk_types(mock_make_redis):
|
||||
mock_redis_instance = MagicMock()
|
||||
mock_make_redis.return_value = mock_redis_instance
|
||||
mock_redis_instance.get.return_value = json.dumps({
|
||||
"version": 1,
|
||||
"chunks": ["text", {"type": "thought", "thought": "reasoning"}],
|
||||
}).encode("utf-8")
|
||||
|
||||
@stream_cache
|
||||
def mock_function(self, model, messages, stream, tools):
|
||||
yield "new_chunk"
|
||||
|
||||
result = list(mock_function(
|
||||
None,
|
||||
"model",
|
||||
[{"role": "user", "content": "test"}],
|
||||
stream=True,
|
||||
tools=None,
|
||||
))
|
||||
|
||||
assert result == ["text", {"type": "thought", "thought": "reasoning"}]
|
||||
mock_redis_instance.set.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@patch("application.cache.get_redis_instance")
|
||||
def test_stream_cache_does_not_stringify_protocol_objects(mock_make_redis):
|
||||
mock_redis_instance = MagicMock()
|
||||
mock_make_redis.return_value = mock_redis_instance
|
||||
mock_redis_instance.get.return_value = None
|
||||
terminal_chunk = MagicMock(name="responses_terminal_choice")
|
||||
|
||||
@stream_cache
|
||||
def mock_function(self, model, messages, stream, tools):
|
||||
yield "partial"
|
||||
yield terminal_chunk
|
||||
|
||||
result = list(mock_function(
|
||||
None,
|
||||
"model",
|
||||
[{"role": "user", "content": "test"}],
|
||||
stream=True,
|
||||
tools=None,
|
||||
))
|
||||
|
||||
assert result[0] == "partial"
|
||||
assert result[1] is terminal_chunk
|
||||
mock_redis_instance.set.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@patch("application.cache.get_redis_instance")
|
||||
def test_stream_cache_rejects_legacy_protocol_object_repr(mock_make_redis):
|
||||
mock_redis_instance = MagicMock()
|
||||
mock_make_redis.return_value = mock_redis_instance
|
||||
mock_redis_instance.get.return_value = json.dumps([
|
||||
"partial",
|
||||
"<application.llm.openai._RespChoice object at 0x123>",
|
||||
]).encode("utf-8")
|
||||
|
||||
@stream_cache
|
||||
def mock_function(self, model, messages, stream, tools):
|
||||
yield "fresh"
|
||||
|
||||
result = list(mock_function(
|
||||
None,
|
||||
"model",
|
||||
[{"role": "user", "content": "test"}],
|
||||
stream=True,
|
||||
tools=None,
|
||||
))
|
||||
|
||||
assert result == ["fresh"]
|
||||
mock_redis_instance.delete.assert_called_once()
|
||||
|
||||
|
||||
# ── get_redis_instance ──────────────────────────────────────────────────────
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user