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
14.6k stars 1.71k forks source link

[Feature]: Support adding vertex models via `/model/new` #3036

Closed krrishdholakia closed 7 months ago

krrishdholakia commented 7 months ago

The Feature

Allow adding new vertex models via the /model/new endpoint

Motivation, pitch

allow user to not need to add vertex models via the config

Twitter / LinkedIn details

No response

krrishdholakia commented 7 months ago

Vertex credentials will need to be passed in.

User can pass this in as a json.

We will then need to store this json in the db, and have a client initialized in the router (or dynamically initialized when call is made)

krrishdholakia commented 7 months ago

assuming the credentials are a service_account.json,

krrishdholakia commented 7 months ago

Putting sample code here:

import google.oauth2.service_account

json_obj = json.loads(service_account_json_str) 

credentials = google.oauth2.service_account.Credentials.from_service_account_info(json_obj)

vertexai.init(project="vertex_project", location="vertex_location", credentials=credentials)

### CODE FOR TESTING ### 
from vertexai.generative_models import GenerativeModel, Part

multimodal_model = GenerativeModel("gemini-1.0-pro-vision")
# Query the model
response = multimodal_model.generate_content(
    [
        # Add an example image
        Part.from_uri(
            "gs://generativeai-downloads/images/scones.jpg", mime_type="image/jpeg"
        ),
        # Add an example query
        "what is shown in this image?",
    ]
)
print(response)
krrishdholakia commented 7 months ago
curl --location 'http://0.0.0.0:4000/model/new' \
--header 'Authorization: Bearer sk-my-api-key' \ # 👈 ADMIN KEY
--header 'Content-Type: application/json' \
--data '{
  "model_name": "gemini",
  "litellm_params": {
     "model": "vertex_ai/gemini-pro",
     "vertex_project": "vertex-project",
     "vertex_location": "us-east-1",
     "vertex_credentials": json.dumps(service_account_obj.json) 
  }
}'
krrishdholakia commented 7 months ago

live in v1.35.6