Skip to content
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

vertexai[patch]: support model param #81

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libs/vertexai/langchain_google_vertexai/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class _VertexAIBase(BaseModel):
model_name: Optional[str] = None
"Underlying model name."

@root_validator(pre=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add an @property for model as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know any use case when it's actually consumed by any chaiins or other "external" instances?
if model property is commonly used outside the LLM/ChatModel itself, maybe we should actually deprecate model_name then.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know any use case when it's actually consumed by any chaiins or other "external" instances? if model property is commonly used outside the LLM/ChatModel itself, maybe we should actually deprecate model_name then.

I think we should use model_name to stay consistent with other provider.
See this issue
#81
@lkuligin @efriis

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this one as is then, and we can add another property later if we decide so.

def validate_params(cls, values: dict) -> dict:
if "model" in values and "model_name" not in values:
values["model_name"] = values.pop("model")
return values


class _VertexAICommon(_VertexAIBase):
client_preview: Any = None #: :meta private:
Expand Down
6 changes: 6 additions & 0 deletions libs/vertexai/langchain_google_vertexai/llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ class _VertexAIBase(BaseModel):
model_name: Optional[str] = None
"Underlying model name."

@root_validator(pre=True)
def validate_params(cls, values: dict) -> dict:
if "model" in values and "model_name" not in values:
values["model_name"] = values.pop("model")
return values


class _VertexAICommon(_VertexAIBase):
client: Any = None #: :meta private:
Expand Down
11 changes: 11 additions & 0 deletions libs/vertexai/tests/unit_tests/test_chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
)


def test_model_name() -> None:
llm = ChatVertexAI()
assert llm.model_name == "chat-bison"

for llm in [
ChatVertexAI(model_name="gemini-pro"),
ChatVertexAI(model="gemini-pro"), # type: ignore[call-arg]
]:
assert llm.model_name == "gemini-pro"


def test_parse_examples_correct() -> None:
text_question = (
"Hello, could you recommend a good movie for me to watch this evening, please?"
Expand Down
11 changes: 11 additions & 0 deletions libs/vertexai/tests/unit_tests/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
from langchain_google_vertexai.llms import VertexAI


def test_model_name() -> None:
llm = VertexAI()
assert llm.model_name == "text-bison"

for llm in [
VertexAI(model_name="text-bison@001"),
VertexAI(model="text-bison@001"), # type: ignore[call-arg]
]:
assert llm.model_name == "text-bison@001"


def test_vertexai_args_passed() -> None:
response_text = "Goodbye"
user_prompt = "Hello"
Expand Down
Loading