clean install and import - vertexai

This commit is contained in:
ishaan-jaff 2023-09-05 16:10:07 -07:00
parent 99359b6464
commit 262bb07ade
2 changed files with 15 additions and 3 deletions

View file

@ -10,6 +10,9 @@ All calls using Vertex AI require the following parameters:
* Your Project Location * Your Project Location
`litellm.vertex_location` = "us-central1" `litellm.vertex_location` = "us-central1"
### Pre-requisites
`pip install google-cloud-aiplatform`
Authentication: Authentication:
VertexAI uses Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information on setting this up VertexAI uses Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information on setting this up

View file

@ -605,7 +605,10 @@ def completion(
return response return response
response = model_response response = model_response
elif model in litellm.vertex_chat_models: elif model in litellm.vertex_chat_models:
try:
import vertexai import vertexai
except:
Exception("vertexai import failed please run `pip install google-cloud-aiplatform`")
from vertexai.preview.language_models import ChatModel, InputOutputTextPair from vertexai.preview.language_models import ChatModel, InputOutputTextPair
vertexai.init( vertexai.init(
@ -633,7 +636,10 @@ def completion(
model_response["model"] = model model_response["model"] = model
response = model_response response = model_response
elif model in litellm.vertex_text_models: elif model in litellm.vertex_text_models:
try:
import vertexai import vertexai
except:
Exception("vertexai import failed please run `pip install google-cloud-aiplatform`")
from vertexai.language_models import TextGenerationModel from vertexai.language_models import TextGenerationModel
vertexai.init( vertexai.init(
@ -790,7 +796,10 @@ def completion(
def completion_with_retries(*args, **kwargs): def completion_with_retries(*args, **kwargs):
try:
import tenacity import tenacity
except:
Exception("tenacity import failed please run `pip install tenacity`")
retryer = tenacity.Retrying(stop=tenacity.stop_after_attempt(3), reraise=True) retryer = tenacity.Retrying(stop=tenacity.stop_after_attempt(3), reraise=True)
return retryer(completion, *args, **kwargs) return retryer(completion, *args, **kwargs)