mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
update testing for streaming to catch empty responses
This commit is contained in:
parent
d0eb126700
commit
06711e7d46
4 changed files with 86 additions and 52 deletions
|
@ -9,7 +9,7 @@ sys.path.insert(
|
|||
) # Adds the parent directory to the system path
|
||||
import litellm
|
||||
from litellm import completion
|
||||
litellm.logging = False
|
||||
litellm.logging = True
|
||||
litellm.set_verbose = True
|
||||
|
||||
score = 0
|
||||
|
@ -22,25 +22,69 @@ def logger_fn(model_call_object: dict):
|
|||
user_message = "Hello, how are you?"
|
||||
messages = [{"content": user_message, "role": "user"}]
|
||||
|
||||
# test on anthropic completion call
|
||||
# test on openai completion call
|
||||
try:
|
||||
start_time = time.time()
|
||||
response = completion(
|
||||
model="claude-instant-1", messages=messages, stream=True, logger_fn=logger_fn
|
||||
model="gpt-3.5-turbo", messages=messages, stream=True, logger_fn=logger_fn
|
||||
)
|
||||
response = ""
|
||||
for chunk in response:
|
||||
chunk_time = time.time()
|
||||
print(f"time since initial request: {chunk_time - start_time:.2f}")
|
||||
print(chunk["choices"][0]["delta"])
|
||||
score += 1
|
||||
response += chunk["choices"][0]["delta"]
|
||||
if response == "":
|
||||
raise Exception("Empty response received")
|
||||
except:
|
||||
print(f"error occurred: {traceback.format_exc()}")
|
||||
pass
|
||||
|
||||
# # test on openai completion call
|
||||
|
||||
# test on azure completion call
|
||||
try:
|
||||
response = completion(
|
||||
model="azure/chatgpt-test", messages=messages, stream=True, logger_fn=logger_fn
|
||||
)
|
||||
response = ""
|
||||
for chunk in response:
|
||||
chunk_time = time.time()
|
||||
print(f"time since initial request: {chunk_time - start_time:.2f}")
|
||||
print(chunk["choices"][0]["delta"])
|
||||
response += chunk["choices"][0]["delta"]
|
||||
if response == "":
|
||||
raise Exception("Empty response received")
|
||||
except:
|
||||
print(f"error occurred: {traceback.format_exc()}")
|
||||
pass
|
||||
|
||||
|
||||
# test on anthropic completion call
|
||||
try:
|
||||
response = completion(
|
||||
model="claude-instant-1", messages=messages, stream=True, logger_fn=logger_fn
|
||||
)
|
||||
response = ""
|
||||
for chunk in response:
|
||||
chunk_time = time.time()
|
||||
print(f"time since initial request: {chunk_time - start_time:.2f}")
|
||||
print(chunk["choices"][0]["delta"])
|
||||
response += chunk["choices"][0]["delta"]
|
||||
if response == "":
|
||||
raise Exception("Empty response received")
|
||||
except:
|
||||
print(f"error occurred: {traceback.format_exc()}")
|
||||
pass
|
||||
|
||||
|
||||
# # test on huggingface completion call
|
||||
# try:
|
||||
# response = completion(
|
||||
# model="gpt-3.5-turbo", messages=messages, stream=True, logger_fn=logger_fn
|
||||
# model="meta-llama/Llama-2-7b-chat-hf",
|
||||
# messages=messages,
|
||||
# custom_llm_provider="huggingface",
|
||||
# custom_api_base="https://s7c7gytn18vnu4tw.us-east-1.aws.endpoints.huggingface.cloud",
|
||||
# stream=True,
|
||||
# logger_fn=logger_fn,
|
||||
# )
|
||||
# for chunk in response:
|
||||
# print(chunk["choices"][0]["delta"])
|
||||
|
@ -48,47 +92,3 @@ except:
|
|||
# except:
|
||||
# print(f"error occurred: {traceback.format_exc()}")
|
||||
# pass
|
||||
|
||||
|
||||
# # test on azure completion call
|
||||
# try:
|
||||
# response = completion(
|
||||
# model="azure/chatgpt-test", messages=messages, stream=True, logger_fn=logger_fn
|
||||
# )
|
||||
# for chunk in response:
|
||||
# print(chunk["choices"][0]["delta"])
|
||||
# score += 1
|
||||
# except:
|
||||
# print(f"error occurred: {traceback.format_exc()}")
|
||||
# pass
|
||||
|
||||
|
||||
# # test on anthropic completion call
|
||||
# try:
|
||||
# response = completion(
|
||||
# model="claude-instant-1", messages=messages, stream=True, logger_fn=logger_fn
|
||||
# )
|
||||
# for chunk in response:
|
||||
# print(chunk["choices"][0]["delta"])
|
||||
# score += 1
|
||||
# except:
|
||||
# print(f"error occurred: {traceback.format_exc()}")
|
||||
# pass
|
||||
|
||||
|
||||
# # # test on huggingface completion call
|
||||
# # try:
|
||||
# # response = completion(
|
||||
# # model="meta-llama/Llama-2-7b-chat-hf",
|
||||
# # messages=messages,
|
||||
# # custom_llm_provider="huggingface",
|
||||
# # custom_api_base="https://s7c7gytn18vnu4tw.us-east-1.aws.endpoints.huggingface.cloud",
|
||||
# # stream=True,
|
||||
# # logger_fn=logger_fn,
|
||||
# # )
|
||||
# # for chunk in response:
|
||||
# # print(chunk["choices"][0]["delta"])
|
||||
# # score += 1
|
||||
# # except:
|
||||
# # print(f"error occurred: {traceback.format_exc()}")
|
||||
# # pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue