A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://python.langchain.com/docs/integrations/tools/google_drive below:

Google Drive | 🦜️🔗 LangChain

Google Drive

This notebook walks through connecting a LangChain to the Google Drive API.

Prerequisites
  1. Create a Google Cloud project or use an existing project
  2. Enable the Google Drive API
  3. Authorize credentials for desktop app
  4. pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
Instructions for retrieving your Google Docs data

By default, the GoogleDriveTools and GoogleDriveWrapper expects the credentials.json file to be ~/.credentials/credentials.json, but this is configurable by setting the GOOGLE_ACCOUNT_FILE environment variable to your custom/path/to/credentials.json. The location of token.json use the same directory (or use the parameter token_path). Note that token.json will be created automatically the first time you use the tool.

GoogleDriveSearchTool can retrieve a selection of files with some requests.

By default, If you use a folder_id, all the files inside this folder can be retrieved to Document, if the name match the query.

%pip install --upgrade --quiet  google-api-python-client google-auth-httplib2 google-auth-oauthlib langchain-community

You can obtain your folder and document id from the URL:

The special value root is for your personal home.

By default, all files with these mime-type can be converted to Document.

It's possible to update or customize this. See the documentation of GoogleDriveAPIWrapper.

But, the corresponding packages must installed.

%pip install --upgrade --quiet  unstructured langchain-googledrive
import os

from langchain_googledrive.tools.google_drive.tool import GoogleDriveSearchTool
from langchain_googledrive.utilities.google_drive import GoogleDriveAPIWrapper

os.environ["GOOGLE_ACCOUNT_FILE"] = "custom/path/to/credentials.json"


tool = GoogleDriveSearchTool(
api_wrapper=GoogleDriveAPIWrapper(
folder_id=folder_id,
num_results=2,
template="gdrive-query-in-folder",
)
)
import logging

logging.basicConfig(level=logging.INFO)
tool.run("machine learning")
"A wrapper around Google Drive Search. Useful for when you need to find a document in google drive. The input should be formatted as a list of entities separated with a space. As an example, a list of keywords is 'hello word'."

In order to create an agent that uses the Google Jobs tool install Langgraph

%pip install --upgrade --quiet langgraph langchain-openai

and use the create_react_agent functionality to initialize a ReAct agent. You will also need to set up your OPEN_API_KEY (visit https://platform.openai.com) in order to access OpenAI's chat models.

import os

from langchain.chat_models import init_chat_model
from langgraph.prebuilt import create_react_agent

os.environ["OPENAI_API_KEY"] = "your-openai-api-key"


llm = init_chat_model("gpt-4o-mini", model_provider="openai", temperature=0)
agent = create_react_agent(llm, tools=[tool])

events = agent.stream(
{"messages": [("user", "Search in google drive, who is 'Yann LeCun' ?")]},
stream_mode="values",
)
for event in events:
event["messages"][-1].pretty_print()

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4