BerriAI / litellm

Call all LLM APIs using the OpenAI format. Use Bedrock, Azure, OpenAI, Cohere, Anthropic, Ollama, Sagemaker, HuggingFace, Replicate (100+ LLMs)
https://docs.litellm.ai/docs/
Other
10.3k stars 1.15k forks source link

[Feature]: Add working local tests for Azure Content Safety Callbacks #3591

Open ishaan-jaff opened 1 month ago

ishaan-jaff commented 1 month ago

The Feature

@Lunik would appreciate help on this - file is test_azure_content_safety.py

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x11737ba60>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x1173a8220>, 51413.432590791)]']
connector: <aiohttp.connector.TCPConnector object at 0x11737baf0>
Fatal error on SSL transport
protocol: <asyncio.sslproto.SSLProtocol object at 0x11737beb0>
transport: <_SelectorSocketTransport closing fd=14>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/selector_events.py", line 918, in write
    n = self._sock.send(data)
OSError: [Errno 9] Bad file descriptor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py", line 684, in _process_write_backlog
    self._transport.write(chunk)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/selector_events.py", line 924, in write
    self._fatal_error(exc, 'Fatal write error on socket transport')
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/selector_events.py", line 719, in _fatal_error
    self._force_close(exc)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/selector_events.py", line 731, in _force_close
    self._loop.call_soon(self._call_connection_lost, exc)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 745, in call_soon
    self._check_closed()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Motivation, pitch

Twitter / LinkedIn details

No response

Lunik commented 1 month ago

Hi, here is how is have tested it :

Prepare test env

python3 -m venv .venv
.venv/bin/activate

poetry install -E extra_proxy -E proxy
pip install pytest-asyncio
pip install azure-ai-contentsafety

Running the test

export AZURE_CONTENT_SAFETY_ENDPOINT="https://<INSTANCE_NAME>.cognitiveservices.azure.com/"
export AZURE_CONTENT_SAFETY_API_KEY="<API_KEY>"

poetry run pytest -p no:warnings litellm/tests/test_azure_content_safety.py

Result

====================================== test session starts =======================================
platform darwin -- Python 3.10.14, pytest-7.4.4, pluggy-1.4.0
rootdir: ~/litellm
plugins: anyio-4.3.0, mock-3.12.0, asyncio-0.23.6
asyncio: mode=strict
collected 8 items                                                                                                                                                      

litellm/tests/test_azure_content_safety.py ........                            [100%]

======================================= 8 passed in 4.36s ========================================