Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.
Python agent-evaluationaiai-alignmentai-evaluationai-governanceai-safetyclidiagnostic-tooleu-ai-acthallucination-detectioniso-42001llm-evaluationllm-securitynist-ai-rmfowasp-llmprompt-injectionpythonresponsible-airisk-assessmentrisk-management
import pytest
from aiohttp import web
from ifixai.core.types import ChatMessage, ProviderConfig
from ifixai.providers.base import ProviderRateLimitError, is_fatal_provider_error
from ifixai.providers.minimax import MiniMaxProvider
@pytest.mark.asyncio
@pytest.mark.parametrize("error", [
{"code": "insufficient_quota", "message": "owned quota exhausted"},
{"code": 1008, "message": "insufficient balance"},
])
async def test_minimax_exhausted_quota_is_fatal_without_retrying(monkeypatch, error):
requests = []
async def no_sleep(*args):
return None
async def reply(request):
requests.append(await request.json())
return web.json_response({'error': error}, status=429)
monkeypatch.setattr('ifixai.providers.minimax.asyncio.sleep', no_sleep)
app = web.Application()
app.router.add_post('/chat/completions', reply)
runner = web.AppRunner(app)
await runner.setup()
site = web.TCPSite(runner, '127.0.0.1', 0)
await site.start()
endpoint = f'http://127.0.0.1:{site._server.sockets[0].getsockname()[1]}'
provider = MiniMaxProvider()
try:
with pytest.raises(ProviderRateLimitError) as caught:
await provider.send_message([ChatMessage(content='hello')], ProviderConfig(provider='minimax', endpoint=endpoint, max_retries=1))
assert is_fatal_provider_error(caught.value)
assert len(requests) == 1
finally:
await provider.aclose()
await runner.cleanup()
@pytest.mark.asyncio
async def test_minimax_temporary_throttle_still_recovers(monkeypatch):
requests = []
sleeps = []
async def no_sleep(delay):
sleeps.append(delay)
async def reply(request):
requests.append(await request.json())
if len(requests) == 1:
return web.json_response({'error': {'code': 1002, 'message': 'rate limit exceeded'}}, status=429)
return web.json_response({'choices': [{'message': {'content': 'owned recovered reply'}}]})
monkeypatch.setattr('ifixai.providers.minimax.asyncio.sleep', no_sleep)
app = web.Application()
app.router.add_post('/chat/completions', reply)
runner = web.AppRunner(app)
await runner.setup()
site = web.TCPSite(runner, '127.0.0.1', 0)
await site.start()
endpoint = f'http://127.0.0.1:{site._server.sockets[0].getsockname()[1]}'
provider = MiniMaxProvider()
try:
assert await provider.send_message([ChatMessage(content='hello')], ProviderConfig(provider='minimax', endpoint=endpoint, max_retries=1)) == 'owned recovered reply'
assert len(requests) == 2
assert sleeps == [1]
finally:
await provider.aclose()
await runner.cleanup()