BerriAI / litellm

Python SDK, Proxy Server (LLM Gateway) to call 100+ LLM APIs in OpenAI format - [Bedrock, Azure, OpenAI, VertexAI, Cohere, Anthropic, Sagemaker, HuggingFace, Replicate, Groq]
https://docs.litellm.ai/docs/
Other
12.67k stars 1.48k forks source link

Exception: Invalid response object 'NoneType' object is not iterable #2395

Open priamai opened 7 months ago

priamai commented 7 months ago

Example code:


    print("Model: " + model)
    response = completion(
                model=model,
                temperature = 0,
                messages=[{"content": "You are an expert in Structured Threat Information Expression (STIX) is a language and serialization format used to exchange cyber threat intelligence (CTI)", "role": "system"},
                    {"content": "Please list all the SDOs available in the STIX 2.1 version. Provide only their name in a comma separated list.", "role": "user"}],
            )

    for choice in response.choices:
        message_content = choice.message.content
        finish_reason = choice.finish_reason

        info = {'model':model,"question":"List of SDO","response":message_content,"finish_reason":finish_reason,"temperature":0}
        index.append(info)

Error:


LiteLLM.Info: If you need to debug this error, use `litellm.set_verbose=True'.

Traceback (most recent call last):
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/utils.py", line 5122, in convert_to_model_response_object
    for idx, choice in enumerate(response_object["choices"]):
TypeError: 'NoneType' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/llms/openai.py", line 344, in completion
    raise e
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/llms/openai.py", line 318, in completion
    return convert_to_model_response_object(
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/utils.py", line 5204, in convert_to_model_response_object
    raise Exception(f"Invalid response object {e}")
Exception: Invalid response object 'NoneType' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/main.py", line 1262, in completion
    response = openai_chat_completions.completion(
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/llms/openai.py", line 352, in completion
    raise OpenAIError(status_code=500, message=str(e))
litellm.llms.openai.OpenAIError: Invalid response object 'NoneType' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/robomotic/DevOps/azuredevops/ava-backend-ai-ml/experimental/llm/understanding_stix.py", line 40, in <module>
    response = completion(
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/utils.py", line 2171, in wrapper
    raise e
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/utils.py", line 2078, in wrapper
    result = original_function(*args, **kwargs)
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/main.py", line 1808, in completion
    raise exception_type(
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/utils.py", line 6713, in exception_type
    raise e
  File "/home/robomotic/DevOps/github/cyber-llm-exam/venv/lib/python3.10/site-packages/litellm/utils.py", line 6681, in exception_type
    raise APIConnectionError(
litellm.exceptions.APIConnectionError: Invalid response object 'NoneType' object is not iterable
priamai commented 7 months ago

With more debug info:

POST Request Sent from LiteLLM:
curl -X POST \
https://openrouter.ai/api/v1/ \
-H 'HTTP-Referer: https://litellm.ai' -H 'X-Title: liteLLM' \
-d '{'model': 'cognitivecomputations/dolphin-mixtral-8x7b', 'messages': [{'content': 'You are an expert in Structured Threat Information Expression (STIX) is a language and serialization format used to exchange cyber threat intelligence (CTI)', 'role': 'system'}, {'content': 'Please list all the SROs available in the STIX 2.1 version. Provide only their name in a comma separated list.', 'role': 'user'}], 'temperature': 0, 'extra_body': {'transforms': []}, 'extra_headers': {'HTTP-Referer': 'https://litellm.ai', 'X-Title': 'liteLLM'}}'

RAW RESPONSE:
{"id": null, "choices": null, "created": null, "model": null, "object": null, "system_fingerprint": null, "usage": null, "error": {"message": "error code: 524", "code": 524}}