-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Gmail functionality is not working #6653
Comments
Hey @kknono! I'm here to help you with the issue you're facing. I can assist with bug fixes, answer questions, and even guide you on becoming a contributor. Let's work on resolving this together! The error you're encountering seems to be related to the
By ensuring the |
Where can I obtain the privateKey: -----BEGIN PRIVATE KEY----- YOUR_PRIVATE_KEY_HERE -----END PRIVATE KEY-----`? |
You can obtain the
Use this const gmailParams = {
credentials: {
clientEmail: '[email protected]',
privateKey: `-----BEGIN PRIVATE KEY-----
YOUR_PRIVATE_KEY_HERE
-----END PRIVATE KEY-----`,
},
scopes: ["https://mail.google.com/"],
}; This should resolve the issue with the Gmail functionality in LangChain.js. |
I encountered an issue when using the Gmail API with LangchainJS. The following code works correctly outside of LangchainJS: const jwtClient = new google.auth.JWT({
email: credentials.client_email,
key: credentials.private_key,
scopes: ['https://www.googleapis.com/auth/gmail.readonly', 'https://www.googleapis.com/auth/cloud-platform'],
subject: '[email protected]'
});
const gmail = google.gmail({ version: 'v1', auth: jwtClient }); This code allows me to log in and query Gmail successfully. However, when I try to run similar code within LangchainJS, I encounter the following error: const model = new OpenAI({
temperature: 0,
apiKey: '',
});
const gmailParams = {
credentials: {
clientEmail: credentials.client_email,
privateKey: credentials.private_key,
subject: '[email protected]'
},
scopes: ['https://www.googleapis.com/auth/gmail.readonly',
'https://www.googleapis.com/auth/cloud-platform'],
};
const tools: StructuredTool[] = [
// new GmailCreateDraft(gmailParams),
new GmailGetMessage(gmailParams),
new GmailGetThread(gmailParams),
new GmailSearch(gmailParams),
// new GmailSendMessage(gmailParams),
];
const searchInput = `Query my last email`;
const searchResult = await gmailAgent.invoke({ input: searchInput });
const messageId = searchResult?.output?.[0]?.id;
if (!messageId) {
console.error("error");
return;
} [tool/error] [1:chain:AgentExecutor > 7:tool:GmailGetMessage] [512ms] Tool run errored with error: "Invalid id value\n\nError: Invalid id value\n at Gaxios.request (/xxx/node_modules/.pnpm/[email protected]/node_modules/gaxios/src/gaxios.ts:146:15)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async JWT.requestAsync (/xxx/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/oauth2client.js:429:18)\n at async GmailGetMessage.call (/xxxxx/node_modules/.pnpm/@langchain[email protected]@Spider-cloud[email protected]@[email protected]_opiqvsst5hqml352zh6enpkpxe/node_modules/@langchain/community/dist/tools/gmail/get_message.cjs:33:25)\n at async GmailGetMessage.call (/xxxx/node_modules/.pnpm/@langchain[email protected][email protected]/node_modules/@langchain/core/dist/tools/index.cjs:111:22)\n at async /xxxxx/node_modules/.pnpm/langchain@0.2.17_@langchain[email protected][email protected]_axios@[email protected]_d3-ds_4c7epgug2kknocuqq7fr2pruqy/node_modules/langchain/dist/agents/executor.cjs:479:27\n at async Promise.all (index 0)\n at async AgentExecutor.call (/xxxx/node_modules/.pnpm/[email protected]@langchain[email protected][email protected]_axios@[email protected]_d3-ds_4c7epgug2kknocuqq7fr2pruqy/node_modules/langchain/dist/agents/executor.cjs:471:30)\n at async AgentExecutor.invoke (/xxxx/node_modules/.pnpm/langchain@0.2.17_@langchain[email protected][email protected]_axios@[email protected]_d3-ds_4c7epgug2kknocuqq7fr2pruqy/node_modules/langchain/dist/chains/base.cjs:58:28)\n |
The "Invalid id value" error you're encountering when using the Gmail API within LangchainJS is likely due to the
By ensuring the |
The privateKey is correct, and when I call new google.auth.JWT independently, it works perfectly. |
Is there someone available to help? |
What model are you using? It feels like the model isn't following your instructions properly. Try with a better model or use OpenAI to see if your integration works. I don't think your problem is with the Gmail tool. Another thing you can try to do is to paste the error stack in ChatGPT and ask it to explain to you what the problem is. |
Checked other resources
Example Code
logs:
"tool": "gmail_get_thread",
"toolInput": {
"threadId": "unique_thread_id_string"
},
"log": " We can now use the gmail_get_thread tool to retrieve the thread ID of the first unread email message.\n\nAction:\n
json\n{\n \"action\": \"gmail_get_thread\",\n \"action_input\": {\n \"threadId\": \"unique_thread_id_string\"\n }\n}\n
\n\n\n\n\n\n"}
[tool/start] [1:chain:AgentExecutor > 46:tool:GmailGetThread] Entering Tool run with input: "{"threadId":"unique_thread_id_string"}"
[chain/end] [1:chain:AgentExecutor] [36.68s] Exiting Chain run with output: {
"output": "Agent stopped due to max iterations."
}
Error Message and Stack Trace (if applicable)
[tool/error] [1:chain:AgentExecutor > 46:tool:GmailGetThread] [2ms] Tool run errored with error: "error:1E08010C:DECODER routines::unsupported\n\nError: error:1E08010C:DECODER routines::unsupported\n at Sign.sign (node:internal/crypto/sig:128:29)\n at Object.sign (xxxxx/node_modules/.pnpm/[email protected]/node_modules/jwa/index.js:152:45)\n at Object.jwsSign [as sign] (xxxxxnode_modules/.pnpm/[email protected]/node_modules/jws/lib/sign-stream.js:32:24)\n at GoogleToken._GoogleToken_requestToken (xxxx/node_modules/.pnpm/[email protected]/node_modules/gtoken/build/src/index.js:235:27)\n at GoogleToken._GoogleToken_getTokenAsyncInner (xxxx/node_modules/.pnpm/[email protected]/node_modules/gtoken/build/src/index.js:180:97)\n at GoogleToken._GoogleToken_getTokenAsync (xxxx/node_modules/.pnpm/[email protected]/node_modules/gtoken/build/src/index.js:160:173)\n at GoogleToken.getToken (xxxx/node_modules/.pnpm/[email protected]/node_modules/gtoken/build/src/index.js:110:102)\n at JWT.refreshTokenNoCache (xxxnode_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/jwtclient.js:173:36)\n at JWT.refreshToken (xxx/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/oauth2client.js:187:24)\n at JWT.getRequestMetadataAsync (xxx/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/oauth2client.js:333:28)\n at JWT.getRequestMetadataAsync (xxxx/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/jwtclient.js:95:26)\n at JWT.requestAsync (xxxx/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/oauth2client.js:418:34)\n at JWT.request (xxxxx/node_modules/.pnpm/[email protected]/node_modules/google-auth-library/build/src/auth/oauth2client.js:412:25)\n at createAPIRequestAsync (xxxx/node_modules/.pnpm/[email protected]/node_modules/googleapis-common/build/src/apirequest.js:303:31)\n at createAPIRequest (/xxx/node_modules/.pnpm/[email protected]/node_modules/googleapis-common/build/src/apirequest.js:52:16)\n at Resource$Users$Threads.get (xxxx/node_modules/.pnpm/[email protected]/node_modules/googleapis/build/src/apis/gmail/v1.js:2574:65)"
Description
I followed the instructions on the LangChain Gmail integration documentation and set up the API key in the Gmail backend. However, I am unable to use the Gmail functionality, and I am encountering an error。
please help more
System Info
"@langchain/community": "^0.2.31",
"@langchain/core": "^0.2.30",
"@langchain/openai": "^0.2.8",
"googleapis": "^143.0.0",
platform: mac
node:20.x
The text was updated successfully, but these errors were encountered: