langchain-ai / langchain-google

MIT License
106 stars 132 forks source link

Raise Warning for Incorrect Keyword Arguments in VertexAI #556

Open Itaymanes opened 1 week ago

Itaymanes commented 1 week ago

When initializing a class such as VertexAI, the process completes "smoothly" even when incorrect keyword arguments are provided. For example, I encountered the following issue:

Copy code
from langchain_google_vertexai import VertexAI, HarmCategory, HarmBlockThreshold

gemini_safety_settings = {
    HarmCategory.HARM_CATEGORY_UNSPECIFIED: HarmBlockThreshold.BLOCK_NONE,
    HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE,
}
GEMINI = VertexAI(
    model="gemini-1.5-pro-002",
    temperature=0,
    safety_setting=gemini_safety_settings,
)

The code executes without any warnings, despite the fact that safety_setting is incorrect and should be written as safety_settings. This can be problematic, as it may lead to unexpected model behavior, which is difficult to diagnose.

I am raising this issue with VertexAI, but I am unsure if the same behavior occurs with other classes as well. If you agree with this problematic behavior, and you believe that it needs to be changed, I can open a PR with fixing this issue.

lkuligin commented 1 week ago

Yes, raising a warning never hurts. Please, feel free to send the PR. The problem is, that we can never be sure 100% whether this kwargs is meant for ChatVertexAI / VertexAI or not.