|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
| 5 | +from astrbot.core.provider.sources.groq_source import ProviderGroq |
5 | 6 | from astrbot.core.provider.sources.openai_source import ProviderOpenAIOfficial |
6 | 7 |
|
7 | 8 |
|
@@ -32,6 +33,21 @@ def _make_provider(overrides: dict | None = None) -> ProviderOpenAIOfficial: |
32 | 33 | ) |
33 | 34 |
|
34 | 35 |
|
| 36 | +def _make_groq_provider(overrides: dict | None = None) -> ProviderGroq: |
| 37 | + provider_config = { |
| 38 | + "id": "test-groq", |
| 39 | + "type": "groq_chat_completion", |
| 40 | + "model": "qwen/qwen3-32b", |
| 41 | + "key": ["test-key"], |
| 42 | + } |
| 43 | + if overrides: |
| 44 | + provider_config.update(overrides) |
| 45 | + return ProviderGroq( |
| 46 | + provider_config=provider_config, |
| 47 | + provider_settings={}, |
| 48 | + ) |
| 49 | + |
| 50 | + |
35 | 51 | @pytest.mark.asyncio |
36 | 52 | async def test_handle_api_error_content_moderated_removes_images(): |
37 | 53 | provider = _make_provider( |
@@ -198,6 +214,57 @@ def test_extract_error_text_candidates_truncates_long_response_text(): |
198 | 214 | ) |
199 | 215 |
|
200 | 216 |
|
| 217 | +@pytest.mark.asyncio |
| 218 | +async def test_openai_payload_keeps_reasoning_content_in_assistant_history(): |
| 219 | + provider = _make_provider() |
| 220 | + try: |
| 221 | + payloads = { |
| 222 | + "messages": [ |
| 223 | + { |
| 224 | + "role": "assistant", |
| 225 | + "content": [ |
| 226 | + {"type": "think", "think": "step 1"}, |
| 227 | + {"type": "text", "text": "final answer"}, |
| 228 | + ], |
| 229 | + } |
| 230 | + ] |
| 231 | + } |
| 232 | + |
| 233 | + provider._finally_convert_payload(payloads) |
| 234 | + |
| 235 | + assistant_message = payloads["messages"][0] |
| 236 | + assert assistant_message["content"] == [{"type": "text", "text": "final answer"}] |
| 237 | + assert assistant_message["reasoning_content"] == "step 1" |
| 238 | + finally: |
| 239 | + await provider.terminate() |
| 240 | + |
| 241 | + |
| 242 | +@pytest.mark.asyncio |
| 243 | +async def test_groq_payload_drops_reasoning_content_from_assistant_history(): |
| 244 | + provider = _make_groq_provider() |
| 245 | + try: |
| 246 | + payloads = { |
| 247 | + "messages": [ |
| 248 | + { |
| 249 | + "role": "assistant", |
| 250 | + "content": [ |
| 251 | + {"type": "think", "think": "step 1"}, |
| 252 | + {"type": "text", "text": "final answer"}, |
| 253 | + ], |
| 254 | + } |
| 255 | + ] |
| 256 | + } |
| 257 | + |
| 258 | + provider._finally_convert_payload(payloads) |
| 259 | + |
| 260 | + assistant_message = payloads["messages"][0] |
| 261 | + assert assistant_message["content"] == [{"type": "text", "text": "final answer"}] |
| 262 | + assert "reasoning_content" not in assistant_message |
| 263 | + assert "reasoning" not in assistant_message |
| 264 | + finally: |
| 265 | + await provider.terminate() |
| 266 | + |
| 267 | + |
201 | 268 | @pytest.mark.asyncio |
202 | 269 | async def test_handle_api_error_content_moderated_without_images_raises(): |
203 | 270 | provider = _make_provider( |
|
0 commit comments