fix(vertex_ai.py): fix output parsing

This commit is contained in:
Krrish Dholakia 2023-10-24 12:06:24 -07:00
parent 3a9c828437
commit f12dc5df21
7 changed files with 14 additions and 8 deletions

View file

@ -121,7 +121,7 @@ def completion(
model_response = text_model.predict_streaming(prompt, **optional_params)
return model_response
completion_response = text_model.predict(prompt, **optional_params)
completion_response = text_model.predict(prompt, **optional_params).text
## LOGGING
logging_obj.post_call(

View file

@ -1480,7 +1480,7 @@ def embedding(
api_version: Optional[str] = None,
api_key: Optional[str] = None,
api_type: Optional[str] = None,
caching=False,
caching: bool=False,
custom_llm_provider=None,
):
"""

View file

@ -21,6 +21,7 @@ class Router:
router = Router(model_list=model_list)
"""
model_names: List = []
cache_responses: bool = False
def __init__(self,
model_list: Optional[list]=None,
redis_host: Optional[str] = None,
@ -44,6 +45,7 @@ class Router:
self.cache = litellm.Cache(cache_config) # use Redis for tracking load balancing
if cache_responses:
litellm.cache = litellm.Cache(**cache_config) # use Redis for caching completion requests
self.cache_responses = cache_responses
litellm.success_callback = [self.deployment_callback]
def completion(self,
@ -60,10 +62,9 @@ class Router:
# pick the one that is available (lowest TPM/RPM)
deployment = self.get_available_deployment(model=model, messages=messages)
print(f"kwargs: {kwargs}")
data = deployment["litellm_params"]
data["messages"] = messages
print(f"data: {data}")
data["caching"] = self.cache_responses
# call via litellm.completion()
return litellm.completion(**{**data, **kwargs})

View file

@ -2,3 +2,7 @@
[{"model": "gpt-3.5-turbo-16k", "messages": [{"content": "Please provide a summary of the latest scientific discoveries.", "role": "user"}], "api_key": "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"}, {"id": "chatcmpl-86XzBof0OA5JEEClaK9qGv1gHhAs8", "object": "chat.completion", "created": 1696571301, "model": "gpt-3.5-turbo-16k-0613", "choices": [{"index": 0, "message": {"role": "assistant", "content": "As an AI language model, I can provide you with a general overview of some recent scientific discoveries across various fields. However, please note that the summaries provided may not encompass every single discovery happening since scientific progress is a continuous and constantly evolving process. Here are a few of the notable recent scientific discoveries:\n\n1. Mars Rover Finds Evidence of Ancient Life: NASA's Mars Perseverance rover discovered rocks believed to be volcanic, containing possible signs of ancient microbial life on Mars. The samples collected from a crater could provide crucial insights into the planet's past habitability.\n\n2. Quantum Supremacy Achieved: Google's prototype quantum computer, Sycamore, achieved \"quantum supremacy,\" demonstrating calculations that are impossible for classical computers. This milestone brings a new era of computing possibilities and has the potential to impact cryptography and optimization problems.\n\n3. CRISPR Advancements: CRISPR gene-editing technology continues to make progress with new discoveries. Recent breakthroughs include high-precision gene editing techniques, expansion to new organisms, and potential therapies for genetic diseases.\n\n4. Black Hole Imaging: In 2019, the Event Horizon Telescope captured the first-ever direct image of a black hole, located at the center of the galaxy Messier 87. The image provided valuable insights into the nature and behavior of these enigmatic cosmic objects.\n\n5. Renewable Energy Innovations: Scientists and engineers are continuously working on improving renewable energy technologies. Recent advancements include highly efficient solar panels, next-generation wind turbines, and advancements in energy storage systems.\n\n6. COVID-19 Vaccines: Rapid development and deployment of COVID-19 vaccines emerged as a significant scientific achievement. Multiple vaccines, such as those developed by Pfizer-BioNTech, Moderna, and AstraZeneca, have been authorized for emergency use or full approval, contributing to global efforts in combating the pandemic.\n\n7. Artificial Intelligence Breakthroughs: Researchers continue to push the boundaries of artificial intelligence. Advancements include improved natural language processing models, reinforcement learning algorithms, and the development of AI systems for medical diagnosis and autonomous vehicles.\n\nThese are just a few examples of recent scientific discoveries and breakthroughs. Scientific research is a vast and diverse domain, with discoveries occurring across many fields, often on a daily basis."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 17, "completion_tokens": 454, "total_tokens": 471}}]
[{"model": "gpt-3.5-turbo-16k", "messages": [{"content": "Please provide a summary of the latest scientific discoveries.", "role": "user"}], "api_key": "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"}, {"id": "chatcmpl-88APE6LBJebPYs1OkBdzaAiWr4yIc", "object": "chat.completion", "created": 1696957316, "model": "gpt-3.5-turbo-16k-0613", "choices": [{"index": 0, "message": {"role": "assistant", "content": "As an AI language model, I don't have real-time access to current news or the ability to browse the internet. Therefore, I'm unable to provide a summary of the latest scientific discoveries as they are constantly evolving. However, I can provide information on various scientific topics or answer specific questions you may have. If you would like information on a particular scientific discovery or topic, please let me know."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 17, "completion_tokens": 80, "total_tokens": 97}}]
[{"model": "gpt-3.5-turbo-16k", "messages": [{"content": "Please provide a summary of the latest scientific discoveries.", "role": "user"}], "api_key": "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"}, {"id": "chatcmpl-88APEz1u9Dq2XDL3BIkfjspXQbP4J", "object": "chat.completion", "created": 1696957316, "model": "gpt-3.5-turbo-16k-0613", "choices": [{"index": 0, "message": {"role": "assistant", "content": "As an AI language model, I don't have access to real-time data or the ability to browse the internet. Hence, I cannot provide you with a summary of the latest scientific discoveries, as it would require up-to-date information. Scientific discoveries are constantly being made across various fields, including physics, chemistry, biology, medicine, and more. To stay updated on the latest scientific discoveries, I recommend referring to reputable scientific journals, news outlets, or websites that specialize in scientific communication and research."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 17, "completion_tokens": 99, "total_tokens": 116}}]
[{"model": "gpt-3.5-turbo-16k", "messages": [{"content": "Please provide a summary of the latest scientific discoveries.", "role": "user"}], "api_key": "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"}, {"id": "chatcmpl-8DFcOk70rRNjtjhjZ5XnXy7mFViZZ", "object": "chat.completion", "created": 1698168992, "model": "gpt-3.5-turbo-16k-0613", "choices": [{"index": 0, "message": {"role": "assistant", "content": "As an AI language model, I cannot provide real-time updates on the latest scientific discoveries as my responses are based on pre-existing knowledge. However, I can offer a summary of prominent scientific discoveries from various fields up until now. If you are interested in a specific scientific field or topic, please let me know, and I'll be happy to provide more information."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 17, "completion_tokens": 72, "total_tokens": 89}}]
[{"model": "gpt-3.5-turbo-16k", "messages": [{"content": "Please provide a summary of the latest scientific discoveries.", "role": "user"}], "api_key": "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"}, {"id": "chatcmpl-8DFcOhvi41mgdtH6WBVzGKWOVAvpG", "object": "chat.completion", "created": 1698168992, "model": "gpt-3.5-turbo-16k-0613", "choices": [{"index": 0, "message": {"role": "assistant", "content": "As an AI language model, I don't have direct access to real-time information or the ability to browse the internet. Therefore, I cannot provide you with the latest scientific discoveries. Scientific discoveries are constantly being made across various fields, including physics, chemistry, biology, medicine, and more. To stay up to date with the latest scientific breakthroughs, I recommend referring to reputable scientific journals or news outlets that cover recent scientific research."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 17, "completion_tokens": 86, "total_tokens": 103}}]
[{"model": "gpt-3.5-turbo-16k", "messages": [{"content": "Please provide a summary of the latest scientific discoveries.", "role": "user"}], "api_key": "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"}, {"id": "chatcmpl-8DG44xxtT4lsAoVX1rHlC6CJaUjUK", "object": "chat.completion", "created": 1698170708, "model": "gpt-3.5-turbo-16k-0613", "choices": [{"index": 0, "message": {"role": "assistant", "content": "As an AI language model, I don't have real-time data or the ability to browse the internet. Therefore, I cannot provide information on the latest scientific discoveries. Discoveries and breakthroughs occur regularly in various fields of science, including biology, physics, chemistry, and more. To stay updated on the latest scientific discoveries, I recommend referring to reliable sources like scientific journals, news outlets, or university and research institute websites that cover recent scientific breakthroughs."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 17, "completion_tokens": 91, "total_tokens": 108}}]
[{"model": "gpt-3.5-turbo-16k", "messages": [{"content": "Please provide a summary of the latest scientific discoveries.", "role": "user"}], "api_key": "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"}, {"id": "chatcmpl-8DG4449c5ZTIrzJ6s0eslGRib3Jw3", "object": "chat.completion", "created": 1698170708, "model": "gpt-3.5-turbo-16k-0613", "choices": [{"index": 0, "message": {"role": "assistant", "content": "As an AI language model, I don't have access to real-time information or the ability to browse the internet. Consequently, I cannot provide a summary of the very latest scientific discoveries. However, I can provide a general overview of some significant recent discoveries from various scientific fields that have been covered in the news. Keep in mind that these summaries are not exhaustive and may not include the most recent breakthroughs:\n\n1. Astrophysics: In April 2019, the Event Horizon Telescope captured the first-ever image of a black hole in the center of the galaxy Messier 87. This provided dramatic evidence supporting Einstein's theory of general relativity.\n\n2. Medicine: In November 2020, the Pfizer/BioNTech and Moderna COVID-19 vaccines were announced, marking significant progress in the fight against the global pandemic. Both vaccines utilize mRNA technology to stimulate an immune response to the virus.\n\n3. Quantum Computing: In October 2019, Google claimed to have achieved \"quantum supremacy\" by solving a calculation that would have taken the world's most powerful supercomputer thousands of years in just 200 seconds.\n\n4. Genetics: CRISPR-Cas9, a revolutionary gene-editing technology, has made significant strides in recent years. Researchers have successfully edited genes in human embryos to correct genetic mutations, opening up possibilities for treating otherwise incurable genetic diseases.\n\n5. Climate Change: Scientists have been studying the impacts of climate change and their consequences. Recent findings include increased melting of polar ice caps, rising sea levels, and the higher frequency and intensity of extreme weather events like hurricanes and heatwaves.\n\nPlease note that these summaries might not represent the most recent scientific discoveries in each field. Scientific advancements occur at a rapid pace, and it is best to refer to reputable scientific journals, news outlets, or academic sources for the most up-to-date information."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 17, "completion_tokens": 373, "total_tokens": 390}}]

View file

@ -190,7 +190,7 @@ def test_embedding_caching_azure():
os.environ['AZURE_API_BASE'] = api_base
os.environ['AZURE_API_KEY'] = api_key
test_embedding_caching_azure()
# test_embedding_caching_azure()
# test caching with streaming
@ -344,7 +344,7 @@ def test_custom_redis_cache_with_key():
if response3['choices'][0]['message']['content'] == response2['choices'][0]['message']['content']:
pytest.fail(f"Error occurred:")
# test_custom_redis_cache_with_key()
test_custom_redis_cache_with_key()
def test_hosted_cache():
litellm.cache = Cache(type="hosted") # use api.litellm.ai for caching

View file

@ -51,7 +51,7 @@ def test_completion_claude():
except Exception as e:
pytest.fail(f"Error occurred: {e}")
# test_completion_claude()
test_completion_claude()
# def test_completion_oobabooga():
# try:

View file

@ -776,7 +776,8 @@ def client(original_function):
litellm.cache = Cache()
print_verbose(f"kwargs[caching]: {kwargs.get('caching', False)}; litellm.cache: {litellm.cache}")
if kwargs.get("caching", False) or litellm.cache is not None: # allow users to control returning cached responses from the completion function
# if caching is false, don't run this
if (kwargs.get("caching", None) is None and litellm.cache is not None) or kwargs.get("caching", False) == True: # allow users to control returning cached responses from the completion function
# checking cache
if (litellm.cache != None or litellm.caching or litellm.caching_with_models):
print_verbose(f"Checking Cache")