####################################################################################
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     https://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
####################################################################################

# Author:  Adam Paternostro
# Summary: Use Google Search along with text-bison for Langchan example

# To setup your environemtn
# python3 -m venv .venv
# source .venv/bin/activate
# pip install --only-binary :all: greenlet
# pip install langchain pip install langchain==0.0.307
# pip install google-cloud-aiplatform 
# pip install streamlit==1.27.2
# pip install python-dotenv==1.0.0
# pip install google-api-python-client==2.100.0
# pip install numexpr==2.8.6
# pip install youtube_search==2.1.2
# run it: python sample-prompt-agent-serper.py
# deactivate
# update or install the necessary libraries

 
# import libraries
import json
import langchain
from langchain.llms import VertexAI
from langchain.agents import load_tools, initialize_agent, AgentType
from langchain.callbacks import StreamlitCallbackHandler
from langchain.tools import Tool
from langchain.tools import YouTubeSearchTool
from langchain.utilities import GoogleSearchAPIWrapper
from langchain.utilities import GoogleSerperAPIWrapper
from langchain.chains import LLMMathChain
from dotenv import load_dotenv
import streamlit as st
import os

load_dotenv()


llm = VertexAI(
    model_name="text-bison@001",
    max_output_tokens=1024,
    temperature=0.25,
    top_p=0,
    top_k=1,
    verbose=True,
)

tools = load_tools(["google-serper", "llm-math"], llm=llm)

agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)

#agent.run("Who is the current presidents wfie? What is their current age raised multiplied by 5?")
agent.run("""Get a list of NYC events for tonight and return the results in the following JSON format""")
langchain.agents.initialize_agent langchain.agents.load_tools langchain.llms.VertexAI
[((1859, 1872), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (1870, 1872), False, 'from dotenv import load_dotenv\n'), ((1881, 1997), 'langchain.llms.VertexAI', 'VertexAI', ([], {'model_name': '"""text-bison@001"""', 'max_output_tokens': '(1024)', 'temperature': '(0.25)', 'top_p': '(0)', 'top_k': '(1)', 'verbose': '(True)'}), "(model_name='text-bison@001', max_output_tokens=1024, temperature=\n    0.25, top_p=0, top_k=1, verbose=True)\n", (1889, 1997), False, 'from langchain.llms import VertexAI\n'), ((2029, 2079), 'langchain.agents.load_tools', 'load_tools', (["['google-serper', 'llm-math']"], {'llm': 'llm'}), "(['google-serper', 'llm-math'], llm=llm)\n", (2039, 2079), False, 'from langchain.agents import load_tools, initialize_agent, AgentType\n'), ((2089, 2168), 'langchain.agents.initialize_agent', 'initialize_agent', (['tools', 'llm'], {'agent': '"""zero-shot-react-description"""', 'verbose': '(True)'}), "(tools, llm, agent='zero-shot-react-description', verbose=True)\n", (2105, 2168), False, 'from langchain.agents import load_tools, initialize_agent, AgentType\n')]