-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question]: Adding safety settings to vertex ai #13805
Comments
The correct format to pass the safety settings to Vertex AI models is to use the Here is an example of how to do it: from vertexai.generative_models._generative_models import SafetySettingsType
from llama_index.llms.vertex import Vertex
# Define your safety settings
safety_settings = SafetySettingsType(
# Add your specific safety settings here
)
# Set up necessary variables
credentials = {
"project_id": "INSERT_PROJECT_ID",
"api_key": "INSERT_API_KEY",
}
# Create an instance of the Vertex class with safety settings
llm = Vertex(
model="text-bison",
project=credentials["project_id"],
credentials=credentials,
safety_settings=safety_settings
)
# Access the complete method from the instance
response = llm.complete("Hello world!")
print(str(response)) This ensures that the
|
As the error says, update forward refs needs to be called, so the class has to be updated The workaround would be calling it yourself before using it
|
NameError: name 'SafetySetting' is not defined. Did you mean: 'SafetySettingsType'? |
To resolve the Here's how you can correctly define and pass the safety settings:
from vertexai.preview.language_models import HarmCategory, HarmBlockThreshold
from vertexai.generative_models._generative_models import SafetySettingsType
from llama_index.llms.vertex import Vertex
safety_settings = SafetySettingsType(
{
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_ONLY_HIGH,
HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE,
}
)
Vertex.update_forward_refs()
llm = Vertex(
model="gemini-1.5-pro-preview-0514",
safety_settings=safety_settings,
project=credentials.project_id,
credentials=credentials,
temperature=0.3,
max_tokens=8192,
) This should resolve the |
Question Validation
Question
I am trying to add safety settings to vertex ai models.
when I pass the above settings I get the following error.
Then whats the correct format to pass the safety settings
The text was updated successfully, but these errors were encountered: