Create an async mock for litellm.acompletion.
(responses: list[str])
| 1130 | |
| 1131 | |
| 1132 | def _mock_acompletion(responses: list[str]): |
| 1133 | """Create an async mock for litellm.acompletion.""" |
| 1134 | call_count = {"n": 0} |
| 1135 | |
| 1136 | async def side_effect(*args, **kwargs): |
| 1137 | idx = min(call_count["n"], len(responses) - 1) |
| 1138 | call_count["n"] += 1 |
| 1139 | mock_resp = MagicMock() |
| 1140 | mock_resp.choices = [MagicMock()] |
| 1141 | mock_resp.choices[0].message.content = responses[idx] |
| 1142 | mock_resp.usage = MagicMock(prompt_tokens=100, completion_tokens=50) |
| 1143 | mock_resp.usage.prompt_tokens_details = None |
| 1144 | return mock_resp |
| 1145 | |
| 1146 | return side_effect |
| 1147 | |
| 1148 | |
| 1149 | class TestCompileShortDoc: |
no outgoing calls
no test coverage detected