From 834f363b6a6c3681687caedb5d361ff8b299a316 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 5 Apr 2024 13:55:05 -0700 Subject: [PATCH] docs(vertex.md): add safety settings tutorial to docs --- docs/my-website/docs/providers/vertex.md | 94 ++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/docs/my-website/docs/providers/vertex.md b/docs/my-website/docs/providers/vertex.md index fff4c86c608..90313c9fa7c 100644 --- a/docs/my-website/docs/providers/vertex.md +++ b/docs/my-website/docs/providers/vertex.md @@ -130,6 +130,100 @@ Here's how to use Vertex AI with the LiteLLM Proxy Server +## Specifying Safety Settings +In certain use-cases you may need to make calls to the models and pass [safety settigns](https://ai.google.dev/docs/safety_setting_gemini) different from the defaults. To do so, simple pass the `safety_settings` argument to `completion` or `acompletion`. For example: + + + + + + +```python +response = completion( + model="gemini/gemini-pro", + messages=[{"role": "user", "content": "write code for saying hi from LiteLLM"}] + safety_settings=[ + { + "category": "HARM_CATEGORY_HARASSMENT", + "threshold": "BLOCK_NONE", + }, + { + "category": "HARM_CATEGORY_HATE_SPEECH", + "threshold": "BLOCK_NONE", + }, + { + "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", + "threshold": "BLOCK_NONE", + }, + { + "category": "HARM_CATEGORY_DANGEROUS_CONTENT", + "threshold": "BLOCK_NONE", + }, + ] +) +``` + + + +**Option 1: Set in config** +```yaml +model_list: + - model_name: gemini-experimental + litellm_params: + model: vertex_ai/gemini-experimental + vertex_project: litellm-epic + vertex_location: us-central1 + safety_settings: + - category: HARM_CATEGORY_HARASSMENT + threshold: BLOCK_NONE + - category: HARM_CATEGORY_HATE_SPEECH + threshold: BLOCK_NONE + - category: HARM_CATEGORY_SEXUALLY_EXPLICIT + threshold: BLOCK_NONE + - category: HARM_CATEGORY_DANGEROUS_CONTENT + threshold: BLOCK_NONE +``` + +**Option 2: Set on call** + +```python +response = client.chat.completions.create( + model="gemini-experimental", + messages=[ + { + "role": "user", + "content": "Can you write exploits?", + } + ], + max_tokens=8192, + stream=False, + temperature=0.0, + + extra_body={ + "safety_settings": [ + { + "category": "HARM_CATEGORY_HARASSMENT", + "threshold": "BLOCK_NONE", + }, + { + "category": "HARM_CATEGORY_HATE_SPEECH", + "threshold": "BLOCK_NONE", + }, + { + "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", + "threshold": "BLOCK_NONE", + }, + { + "category": "HARM_CATEGORY_DANGEROUS_CONTENT", + "threshold": "BLOCK_NONE", + }, + ], + } +) +``` + + + ## Set Vertex Project & Vertex Location All calls using Vertex AI require the following parameters: * Your Project ID