Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

VertexAI API | Set safety filters

How can I set safety filters in my API call to VertexAI API. I want least to no filter in place for all my API calls.  I am using chat-bison and text-bison models. 

1 5 1,425
5 REPLIES 5

to set safety filters in your API call to VertexAI API, you can use the safety_filters parameter in your API request. The safety_filters parameter is a list of strings that specify the safety filters you want to apply to the API call.

To disable all safety filters, you can pass an empty list to the safety_filters parameter. For example, the following code snippet shows how to disable all safety filters when using the chat-bison model:

import vertexai

# Set the project ID and location
project_id = "YOUR_PROJECT_ID"
location = "us-central1"

# Create a VertexAI client
client = vertexai.Client(project=project_id)

# Set the safety filters
safety_filters = []

# Create the request
request = client.projects().locations().models().generate().deployments().predict()
request.parameters.put(
vertexai.types.GenerateSequencePredictionRequestParameters(
prompt="Hello",
max_tokens=100,
temperature=1.0,
safety_filters=safety_filters,
)
)

# Send the request
response = request.execute()
print("Response:")
print(response)

 

 

    safety_filters = []
    chat = client.start_chat(  
        context=context,
        temperature=temperature,
        max_output_tokens=max_output_tokens,
        top_p=top_p,
        safety_filters=safety_filters,
)
    answer = chat.send_message(question)
    print(answer)
    return answer
i am getting this TypeError: _PreviewChatModel.start_chat() got an unexpected keyword argument 'safety_filters'
 

Hi, vertexai package does not contain a "Client" function, would be possible to make your example more clear?

OP: Have you found a solution for this?

Adjust model settings to minimize or disable safety filters.

Specify desired filter settings in API request parameters.

Test thoroughly and consider legal and ethical implications.