langchain-ai / langchain-google

MIT License
104 stars 121 forks source link

Request: Add support for access_token for ChatAnthropic Vertex (code included) #211

Closed dvideby0 closed 4 months ago

dvideby0 commented 5 months ago

Can you add the access_token parameter to the class and pass it to the Anthropic classes in libs/vertexai/langchain_google_vertexai/model_garden.py


    async_client: Any = None  #: :meta private:
    model_name: Optional[str] = Field(default=None, alias="model")  # type: ignore[assignment]
    "Underlying model name."
    max_output_tokens: int = Field(default=1024, alias="max_tokens")
    access_token: Optional[str] = None

    class Config:
        """Configuration for this pydantic object."""

        allow_population_by_field_name = True

    @root_validator()
    def validate_environment(cls, values: Dict) -> Dict:
        from anthropic import (  # type: ignore[import-not-found]
            AnthropicVertex,
            AsyncAnthropicVertex,
        )

        values["client"] = AnthropicVertex(
            project_id=values["project"],
            region=values["location"],
            max_retries=values["max_retries"],
            access_token=values["access_token"],
        )
        values["async_client"] = AsyncAnthropicVertex(
            project_id=values["project"],
            region=values["location"],
            max_retries=values["max_retries"],
            access_token=values["access_token"],
        )
        return values
lkuligin commented 5 months ago

@dvideby0 thanks for the feature request and a code sample. Do you mind raising a PR, pleease?

dvideby0 commented 5 months ago

PR: https://github.com/langchain-ai/langchain-google/pull/212

lkuligin commented 4 months ago

thanks a lot for your contribution!