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: updating aiplatform #827

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lgesuellip
Copy link
Contributor

PR Description

Hey team,

The current version of aiplatform doesn’t support Google Search via the v1 endpoint. This PR updates the library version to enable that support through tools.

https://github.com/googleapis/python-aiplatform/blob/v1.86.0/google/cloud/aiplatform_v1/types/tool.py#L78

🆕 New Feature
✅ Test

Testing

I tested it using the following code:

import asyncio
import google.cloud.aiplatform_v1beta1.types as vertex_types
from langchain_google_vertexai import ChatVertexAI
from langchain_core.messages import SystemMessage, HumanMessage


async def company_research_with_search_grounding(ticker: str, cik: str) -> str:
    """Research a company using Gemini with Google Search grounding.
    
    Args:
        ticker: The stock ticker symbol
        cik: The SEC's Central Index Key number
        
    Returns:
        Detailed company information including name and domain
    """
    # Initialize the chat model
    llm = ChatVertexAI(
        project="",
        location="us-central1",
        model="gemini-2.0-flash-exp",
        endpoint_version="v1"
    )

    # System message to guide the model's behavior
    messages = [
        SystemMessage(content="You are a helpful AI assistant specializing in Company Research."),
    ]
    
    # Human query with structured data
    human_message = HumanMessage(
        content=f"""Given the following ticker from US market and the CIK of the company, 
        please provide:
        1. The company's full legal name
        2. The company's primary domain/website
        3. A brief description of their business
        
        ticker: {ticker}
        cik: {cik}
        """
    )
    
    # Create a Tool with Google Search
    google_search_tool = vertex_types.Tool(google_search={})

    # Invoke the model with the search tool
    response = await llm.ainvoke(
        messages + [human_message],
        tools=[google_search_tool],
    )
    
    return response


async def main():
    # Example usage
    result = await company_research_with_search_grounding("AAPL", "320193")
    print(result)
    
    # You can easily research multiple companies asynchronously
    companies = [
        ("AAPL", "320193"),
    ]
    
    results = await asyncio.gather(
        *[company_research_with_search_grounding(ticker, cik) for ticker, cik in companies]
    )
    
    for ticker, result in zip([c[0] for c in companies], results):
        print(f"\n--- {ticker} Research Results ---")
        print(result.content)


if __name__ == "__main__":
    asyncio.run(main())

Note

I think that in a future PR, we should also adapt the types in function_utils to support both versions.
In this case, though, it seems to work fine using the beta type (google.cloud.aiplatform_v1beta1.types as vertex_types) with the v1 endpoint.

What do you think? @lkuligin

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant