メインコンテンツまでスキップ

Google Drive

Use documents and folders from your Google Drive as context for your Squid AI agent.

(Google Driveのドキュメントやフォルダを、Squid AIエージェントのコンテキストとして使用します。)

The Google Drive connector allows you to let users choose files or folders from their Google Drive to upload as context for their Squid AI agent. An AI agent can then respond to client prompts using the selected files as sources of information. For more information on creating custom AI agents, view the AI agent documentation. (Google Driveコネクタを使用すると、ユーザーがGoogle Driveからファイルまたはフォルダを選択してSquid AIエージェントへのコンテキストとしてアップロードすることができます。選択されたファイルを情報源として、AIエージェントがクライアントのプロンプトに応答します。カスタムAIエージェントの作成方法の詳細については、AI agent documentationを参照してください。)

Using the Google Drive connector requires a Google Cloud project and some configuration steps for Google Cloud. The required steps are outlined in this documentation along with links to relevant Google documentation. (Google Driveコネクタを使用するには、Google CloudプロジェクトとGoogle Cloudのいくつかの設定ステップが必要です。必要な手順は、このドキュメント内で関連するGoogleのドキュメントへのリンクとともに説明されています。)

Enable Google Drive APIs

To get started with this Google Drive connector, first enable the required Google APIs on your Google Cloud project. (このGoogle Driveコネクタを始めるには、まずGoogle Cloudプロジェクトで必要なGoogle APIを有効にしてください。)

  1. In the Google Cloud Console, select a project for your application or create a new project. (Google Cloud Consoleで、アプリケーション用のプロジェクトを選択するか、新しいプロジェクトを作成します。)

  2. Follow the Set up your environment steps in the Google Cloud documentation to enable the Google Drive API and create the necessary credentials. You will need your API key, client ID, and client secret. (Google Cloud documentationSet up your environmentの手順に従い、Google Drive APIを有効にし、必要な認証情報を作成してください。API keyclient ID、およびclient secretが必要です。)

  3. In the Google Cloud Console, enable the Google Picker API. (Google Cloud Consoleで、Google Picker APIを有効にします。)

Add the connector

  1. In the Squid Console, navigate to the Connectors tab. (Squid Consoleで、Connectorsタブに移動します。)

  2. Provide the following details: (以下の詳細を入力してください:)

Connector ID: A unique identifier for the connector. Use this as a reference to the connector in your code. (Connector ID:コネクタの一意な識別子です。コード内でコネクタの参照として使用します。)

Client ID: Your Google OAuth 2.0 Client ID you created in the Google Cloud Console. The client ID ends with 'apps.googleusercontent.com'. (Client ID:Google Cloud Consoleで作成したGoogle OAuth 2.0のClient IDです。Client IDは「apps.googleusercontent.com」で終わります。)

Redirect URI: For use with requests from a web server. Do not include a trailing slash. (Redirect URI:Webサーバーからのリクエストで使用するためのものです。末尾のスラッシュは含めないでください。)

Client Secret: Your Google OAuth 2.0 Client Secret. This is only required when managing your OAuth in the backend. Stored securely using Squid Secrets. (Client Secret:Google OAuth 2.0のClient Secretです。これはバックエンドでOAuthを管理する際にのみ必要です。Squid Secretsを使用して安全に保存されます。)

  1. Click Test Connection to verify the connection is successful. If an error appears, check your Client ID and Client Secret values. (Test Connectionをクリックして接続が成功しているか確認します。エラーが表示された場合は、Client IDとClient Secretの値を確認してください。)

  2. When the connection is successful, click Add connector to save. (接続が成功したら、Add connectorをクリックして保存します。)

Using the connector

Note

The personal storage methods of the Squid SDK require access to your Squid API key. The API key enables admin access, so only use personal storage in a secure admin environment like the Squid backend.

(:::note 注意 Squid SDKのpersonal storageメソッドは、Squid API keyへのアクセスを必要とします。API keyは管理者アクセスを有効にするため、personal storageはSquidバックエンドのような安全な管理環境でのみ使用してください。 :::)

Initializing the personal storage client

To initialize the connection to Google Drive, use the personalStorage method, passing the connector ID for your Drive connection: (Google Driveへの接続を初期化するには、Drive接続用のConnector IDを引数としてpersonalStorageメソッドを使用します:)

Backend code
const driveClient = this.squid.personalStorage('CONNECTOR_ID');

Getting a Google API authorization code

To permit Squid AI to access files, you must provide a Google API authorization code. This code is generated using OAuth 2.0. To view the JavaScript API for creating the authorization code, check out the Google Developers Identity API reference. To learn more about Google OAuth 2.0 authentication and authorization, view the Google Developers documentation. (Squid AIがファイルにアクセスできるようにするため、Google APIのauthorization codeを提供する必要があります。このコードはOAuth 2.0を使用して生成されます。authorization codeの生成に関するJavaScript APIについては、Google Developers Identity API referenceを確認してください。また、Google OAuth 2.0の認証と認可の詳細については、Google Developers documentationを参照してください。)

Passing the authorization code to Squid

Once you have your authorization code, provide it to Squid using the saveAuthCode method, passing the Google authorization code and a custom string to uniquely identify the Google Drive connection. (authorization codeを取得したら、saveAuthCodeメソッドを使用して、Googleのauthorization codeとGoogle Drive接続を一意に識別するカスタム文字列をSquidに渡してください。)

Backend code
const driveClient = this.squid.personalStorage('CONNECTOR_ID');
const response = await driveClient.saveAuthCode(
'GOOGLE_ACCESS_CODE',
'CUSTOM_IDENTIFIER'
);
console.log(response.accessToken); // ya29.a1BcD234e...

This function returns a promise that resolves to an access token to use with the Google Picker API. (この関数は、Google Picker APIで使用するaccess tokenを返すpromiseを返します。)

Save the custom identifier for your reference. A user ID can be a useful custom identifier, for example. You only need to run this function once per custom identifier. Once the function has been run once, users can access the Google Picker using an access token managed by Squid. (参照用にカスタム識別子を保存してください。例えば、ユーザーIDは有用なカスタム識別子となり得ます。この関数はカスタム識別子ごとに一度だけ実行すれば良く、一度実行されると、ユーザーはSquidが管理するaccess tokenを使用してGoogle Pickerにアクセスできます。)

Retrieving an access token

By saving your authorization code using the saveAuthCode method, Squid automatically handles generating access tokens for you. (saveAuthCodeメソッドを使用してauthorization codeを保存することで、Squidは自動的にaccess tokenの生成を管理します。)

Backend code
const driveClient = this.squid.personalStorage('CONNECTOR_ID');
const response = await driveClient.getAccessToken('CUSTOM_IDENTIFIER');
console.log(response.accessToken); // ya29.a1BcD234e...

Passing the token to the Google Picker API

To allow users to select files to save as context, use the Google Picker API. Follow the steps provided in the Google documentation to load and display the Google Picker, passing the access token generated by your Squid personal storage instance as the value for accessToken. (ユーザーがコンテキストとして保存するためのファイルを選択できるようにするには、Google Picker APIを使用します。Googleのドキュメントに記載されている手順に従い、Google Pickerを読み込み表示し、Squidのpersonal storageインスタンスで生成されたaccess tokenをaccessTokenの値として渡してください。)

Client code
const showPicker = () => {
// TODO(developer): Replace with your API key
const picker = new google.picker.PickerBuilder()
.addView(google.picker.ViewId.DOCS)
.setOAuthToken(accessToken) // From Squid
.setDeveloperKey('API_KEY')
.setCallback(pickerCallback)
.setAppId(APP_ID)
.build();
picker.setVisible(true);
};

Refer to the Google Picker documentation for the most up-to-date information on implementation. (実装に関する最新情報については、Google Picker documentationを参照してください。)

Adding chosen files as context

Once a client selects files or folders to use as context, pass the array to your secure environment, and then use the indexDocumentOrFolder method to add the selections as context. (クライアントがコンテキストとして使用するファイルまたはフォルダを選択したら、その配列を安全な環境に渡し、さらにindexDocumentOrFolderメソッドを使用して選択されたものをコンテキストとして追加します。)

The simplest way to securely pass information to the Squid backend is through Squid Executables. The following code uses a Squid Executable to pass the array to the Squid backend: (Squidバックエンドに情報を安全に渡す最も簡単な方法は、Squid Executablesを経由することです。以下のコードは、SquidのExecutableを使用して配列をSquidバックエンドに渡す例です:)

Client code
function pickerCallback(data) {
if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) {
const docs = data[google.picker.Response.DOCUMENTS];
squid.executeFunction('addToStorage', docs);
}
}

To add a document to a Squid AI agent, use the indexDocumentOrFolder method, passing the ID of the document obtained from the Google Picker, the custom identifier for the user's personal storage and the ID of the AI agent. (Squid AIエージェントにドキュメントを追加するには、Google Pickerで取得したドキュメントのID、ユーザーのpersonal storageのカスタム識別子、そしてAIエージェントのIDを引数としてindexDocumentOrFolderメソッドを使用します。)

The following example shows using a Squid Executable to iterate through the results obtained from the Google Picker and add them as context to the given AI agent profile: (以下の例は、SquidのExecutableを使用して、Google Pickerで取得した結果を反復処理し、指定したAIエージェントプロファイルにコンテキストとして追加する方法を示しています:)

Backend code
@executable()
async addToStorage(docs: any[]): Promise<string | any> {
try {
docs.map(async (doc) => {
await this.squid
.personalStorage('CONNECTOR_ID')
.indexDocumentOrFolder(
doc.id,
'CUSTOM_IDENTIFIER',
'AGENT_ID',
'ai_agents',
);
})
return 'success';
} catch (error) {
console.error(error);
return error;
}

Next steps

To learn how to implement your AI agent, view the AI agent documentation. (AIエージェントの実装方法について学ぶには、AI agent documentationを参照してください。)