MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _mock_acompletion

Function _mock_acompletion

tests/test_compiler.py:1132–1146  ·  view source on GitHub ↗

Create an async mock for litellm.acompletion.

(responses: list[str])

Source from the content-addressed store, hash-verified

1130
1131
1132def _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
1149class TestCompileShortDoc:

Calls

no outgoing calls

Tested by

no test coverage detected