Cleanup test, at least pass with openai

This commit is contained in:
yujong-lee 2023-08-31 20:33:34 +09:00
parent 119e75655f
commit 2cc9074d09
2 changed files with 5 additions and 39 deletions

View file

@ -33,50 +33,16 @@ litellm.failure_callback = ["sentry"]
# Approach: Run each model through the test -> assert if the correct error (always the same one) is triggered # Approach: Run each model through the test -> assert if the correct error (always the same one) is triggered
# models = ["gpt-3.5-turbo", "chatgpt-test", "claude-instant-1", "command-nightly"] models = ["gpt-3.5-turbo"]
test_model = "claude-instant-1" test_model = "claude-instant-1"
models = ["claude-instant-1"]
def logging_fn(model_call_dict):
return
if "model" in model_call_dict:
print(f"model_call_dict: {model_call_dict['model']}")
else:
print(f"model_call_dict: {model_call_dict}")
# Test 1: Context Window Errors
@pytest.mark.parametrize("model", models) @pytest.mark.parametrize("model", models)
def test_context_window(model): def test_context_window(model):
sample_text = "how does a court case get to the Supreme Court?" * 50000 sample_text = "how does a court case get to the Supreme Court?" * 1000
messages = [{"content": sample_text, "role": "user"}] messages = [{"content": sample_text, "role": "user"}]
try:
print(f"model: {model}")
response = completion(
model=model,
messages=messages,
logger_fn=logging_fn,
)
except ContextWindowExceededError as e:
print(f"ContextWindowExceededError: {e.llm_provider}")
return
except InvalidRequestError as e:
print(f"InvalidRequestError: {e.llm_provider}")
print(f"InvalidRequestError message: {e.message}")
return
except OpenAIError as e:
print(f"OpenAIError: {e.llm_provider}")
return
except Exception as e:
print("Uncaught Error in test_context_window")
print(f"Error Type: {type(e).__name__}")
print(f"Uncaught Exception - {e}")
pytest.fail(f"Error occurred: {e}")
return
with pytest.raises(ContextWindowExceededError):
test_context_window(test_model) completion(model=model, messages=messages)
# Test 2: InvalidAuth Errors # Test 2: InvalidAuth Errors

View file

@ -1361,7 +1361,7 @@ def exception_type(model, original_exception, custom_llm_provider):
original_exception.llm_provider = "azure" original_exception.llm_provider = "azure"
else: else:
original_exception.llm_provider = "openai" original_exception.llm_provider = "openai"
if "This model's maximum context length is" in original_exception.message: if "This model's maximum context length is" in original_exception._message:
raise ContextWindowExceededError( raise ContextWindowExceededError(
message=str(original_exception), message=str(original_exception),
model=model, model=model,