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.

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)

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?

You can read this document Configure safety attributes | Vertex AI | Google Cloud

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’

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.