Skip to content
Snippets Groups Projects
Commit 9fac8991 authored by Jeff Tang's avatar Jeff Tang
Browse files

gmagent v.1

parent a346e19d
No related branches found
No related tags found
No related merge requests found
MIT License
Copyright (c) 2024 Jeff Tang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This diff is collapsed.
python main.py
Hello! I'm Gmagent, your friendly Gmail assistant. I'm here to help you with any Gmail-related tasks. What can I do for you today? Do you need help checking email, composing a new message, or perhaps something else?
Your ask: do i have any emails with attachments?
-------------------------
Calling Llama...
Llama returned: {'function_name': 'list_emails', 'parameters': {'query': 'has:attachment'}}.
Calling tool to access Gmail API: list_emails, {'query': 'has:attachment'}...
Tool calling returned: [{'message_id': '1936ef72ad3f30e8', 'sender': 'gmagent_tester1@gmail.com', 'subject': 'Fwd: papers to read', 'received_time': '2024-11-27 10:51:51 PST'}, {'message_id': '1936b819706a4923', 'sender': 'Jeff Tang <gmagent_tester2@gmail.com>', 'subject': 'papers to read', 'received_time': '2024-11-26 18:44:19 PST'}, {'message_id': '18fa7f38f83197d3', 'sender': 'LangSmith <noreply@langchain.com>', 'subject': 'New Data Retention policy for LangSmith', 'received_time': '2024-05-23 17:14:22 PDT'}]
-------------------------
Gmagent: I found 3 emails matching your query:
1. From: gmagent_tester1@gmail.com, Subject: Fwd: papers to read, Received on: 2024-11-27 10:51:51 PST
2. From: Jeff Tang <gmagent_tester2@gmail.com>, Subject: papers to read, Received on: 2024-11-26 18:44:19 PST
3. From: LangSmith <noreply@langchain.com>, Subject: New Data Retention policy for LangSmith, Received on: 2024-05-23 17:14:22 PDT
Your ask: what's the content of the email from LangSmith
-------------------------
Calling Llama...
Llama returned: {'function_name': 'get_email_detail', 'parameters': {'detail': 'body', 'which': 'from <sender info>'}}.
Calling tool to access Gmail API: get_email_detail, {'detail': 'body', 'which': '18fa7f38f83197d3'}...
Tool calling returned: New Data Retention policy for LangSmith
Hi Jeff,
You are receiving this email because you have an active account on LangSmith. We are transitioning to a new data retention strategy that limits the length of time trace data is stored in LangSmith.
Effective with traces received on or after Wednesday, May 22, all traces stored in LangSmith now have a maximum retention of 400 days from the time of ingest.
For more information about this change please visit the LangSmith Docs.
If after visiting the docs you still have additional questions, please reach out to LangSmith Support via support@langchain.dev or, if you are an Enterprise plan customer, your dedicated Slack channel.
-------------------------
Gmagent: New Data Retention policy for LangSmith
Hi Jeff,
You are receiving this email because you have an active account on LangSmith. We are transitioning to a new data retention strategy that limits the length of time trace data is stored in LangSmith.
Effective with traces received on or after Wednesday, May 22, all traces stored in LangSmith now have a maximum retention of 400 days from the time of ingest.
For more information about this change please visit the LangSmith Docs.
If after visiting the docs you still have additional questions, please reach out to LangSmith Support via support@langchain.dev or, if you are an Enterprise plan customer, your dedicated Slack channel.
Unsubscribe
Your ask: do i have emails with attachment larger than 1mb?
-------------------------
Calling Llama...
Llama returned: {'function_name': 'list_emails', 'parameters': {'query': 'has:attachment larger:1mb'}}.
Calling tool to access Gmail API: list_emails, {'query': 'has:attachment larger:1mb'}...
Tool calling returned: [{'message_id': '1936ef72ad3f30e8', 'sender': 'gmagent_tester1@gmail.com', 'subject': 'Fwd: papers to read', 'received_time': '2024-11-27 10:51:51 PST'}, {'message_id': '1936b819706a4923', 'sender': 'Jeff Tang <gmagent_tester2@gmail.com>', 'subject': 'papers to read', 'received_time': '2024-11-26 18:44:19 PST'}]
-------------------------
Gmagent: I found 2 emails matching your query:
1. From: gmagent_tester1@gmail.com, Subject: Fwd: papers to read, Received on: 2024-11-27 10:51:51 PST
2. From: Jeff Tang <gmagent_tester2@gmail.com>, Subject: papers to read, Received on: 2024-11-26 18:44:19 PST
Your ask: what kind of attachments for the email with subject papers to read?
-------------------------
Calling Llama...
Llama returned: {'function_name': 'get_email_detail', 'parameters': {'detail': 'attachment', 'which': 'subject papers to read'}}.
Calling tool to access Gmail API: get_email_detail, {'detail': 'attachment', 'which': '1936b819706a4923'}...
Tool calling returned: thinking_llm.pdf - 1115430 bytes
logic-of-thought.pdf - 1719126 bytes
-------------------------
Gmagent: thinking_llm.pdf - 1115430 bytes
logic-of-thought.pdf - 1719126 bytes
Your ask: give me a summary of the pdf thinking_llm.pdf
-------------------------
Calling Llama...
Llama returned: {'function_name': 'get_pdf_summary', 'parameters': {'file_name': 'thinking_llm.pdf'}}.
Calling tool to access Gmail API: get_pdf_summary, {'file_name': 'thinking_llm.pdf'}...
PDF text length: 80464
Calling Llama 31 to generate a summary...
Tool calling returned: It appears that you've provided several examples of responses generated by a model, along with some analysis and comparisons.
From what I can see, these examples illustrate various aspects of model performance, including:
1. **Inconsistent or incorrect outputs**: In some cases, the model generates responses that are not accurate or consistent (e.g., Examples 17-19).
2. **Self-correction in math tasks**: The model sometimes makes mistakes but then corrects them based on further thought and analysis (e.g., Example 20).
3. **Improved performance with specific prompts**: Using specific prompts can help the model generate more accurate or helpful responses, especially in cases where it initially made a mistake (e.g., Examples 17-19).
4. **Comparison to direct models**: The TPO model's ability to correct its own mistakes and generate more accurate responses is highlighted through comparisons with direct models (e.g., Example 20).
These examples are likely from the report you mentioned, which explores the performance of a sequence-to-sequence model for generating natural language responses.
If you'd like to discuss any specific points or ask questions about these examples, I'm here to help!
-------------------------
Gmagent: It appears that you've provided several examples of responses generated by a model, along with some analysis and comparisons.
From what I can see, these examples illustrate various aspects of model performance, including:
1. **Inconsistent or incorrect outputs**: In some cases, the model generates responses that are not accurate or consistent (e.g., Examples 17-19).
2. **Self-correction in math tasks**: The model sometimes makes mistakes but then corrects them based on further thought and analysis (e.g., Example 20).
3. **Improved performance with specific prompts**: Using specific prompts can help the model generate more accurate or helpful responses, especially in cases where it initially made a mistake (e.g., Examples 17-19).
4. **Comparison to direct models**: The TPO model's ability to correct its own mistakes and generate more accurate responses is highlighted through comparisons with direct models (e.g., Example 20).
These examples are likely from the report you mentioned, which explores the performance of a sequence-to-sequence model for generating natural language responses.
If you'd like to discuss any specific points or ask questions about these examples, I'm here to help!
Your ask: Draft an email to jeffxtang@meta.com saying working on it and will keep you updated. thanks for your patience.
-------------------------
Calling Llama...
Llama returned: {'function_name': 'create_draft', 'parameters': {'action': 'new', 'to': 'jeffxtang@meta.com', 'subject': 'Update on [Your Project]', 'body': 'Hi Jeff,\\n\\nI wanted to touch base with you regarding [Your Project]. I am currently working on it and will keep you updated. Thank you for your patience.\\n\\nBest regards,'}}.
Calling tool to access Gmail API: create_draft, {'action': 'new', 'to': 'jeffxtang@meta.com', 'subject': 'Update on [Your Project]', 'body': 'Hi Jeff,\\n\\nI wanted to touch base with you regarding [Your Project]. I am currently working on it and will keep you updated. Thank you for your patience.\\n\\nBest regards,'}...
Draft created with ID: r5930232887125763038
Tool calling returned: r5930232887125763038
-------------------------
Gmagent: Draft created.
Your ask: send the draft
-------------------------
Calling Llama...
Llama returned: {'function_name': 'send_draft', 'parameters': {'id': '...'}}.
Calling tool to access Gmail API: send_draft, {'id': 'r5930232887125763038'}...
Tool calling returned: Draft sent with email ID: 1936fc3db1993629
-------------------------
Gmagent: Draft sent with email ID: 1936fc3db1993629
Your ask: do i have any emails with attachment larger than 10mb?
-------------------------
Calling Llama...
Llama returned: {'function_name': 'list_emails', 'parameters': {'query': 'has:attachment larger:10mb'}}.
Calling tool to access Gmail API: list_emails, {'query': 'has:attachment larger:10mb'}...
Tool calling returned: []
-------------------------
Gmagent: I couldn't find any such emails. What else would you like to do?
Your ask: how about 5mb
-------------------------
Calling Llama...
Llama returned: {'function_name': 'list_emails', 'parameters': {'query': 'has:attachment larger:5mb'}}.
Calling tool to access Gmail API: list_emails, {'query': 'has:attachment larger:5mb'}...
Tool calling returned: [{'message_id': '1936fce85e88a3ef', 'sender': 'Jeff Tang <gmagent_tester2@gmail.com>', 'subject': 'this is an interesting paper', 'received_time': '2024-11-27 14:46:50 PST'}]
-------------------------
Gmagent: I found 1 email matching your query:
1. From: Jeff Tang <gmagent_tester2@gmail.com>, Subject: this is an interesting paper, Received on: 2024-11-27 14:46:50 PST
Your ask: reply to the email saying thanks for sharing!
-------------------------
Calling Llama...
Llama returned: {'function_name': 'send_email', 'parameters': {'action': 'reply', 'to': 'gmagent_tester2@gmail.com', 'subject': 'Re: this is an interesting paper', 'body': 'Thanks for sharing!', 'email_id': '1936fce85e88a3ef'}}.
Calling tool to access Gmail API: send_email, {'action': 'reply', 'to': 'gmagent_tester2@gmail.com', 'subject': 'Re: this is an interesting paper', 'body': 'Thanks for sharing!', 'email_id': '1936fce85e88a3ef'}...
Reply sent. Message ID: 1936fd65f9f24e70
Tool calling returned: None
-------------------------
Gmagent: Email sent.
Your ask: forward the email to jeffxtang@meta.com
-------------------------
Calling Llama...
Llama returned: {'function_name': 'send_email', 'parameters': {'action': 'forward', 'to': 'jeffxtang@meta.com', 'subject': 'this is an interesting paper', 'body': '', 'email_id': '1936fce85e88a3ef'}}.
Calling tool to access Gmail API: send_email, {'action': 'forward', 'to': 'jeffxtang@meta.com', 'subject': 'this is an interesting paper', 'body': '', 'email_id': '1936fce85e88a3ef'}...
Message forwarded successfully! Message ID: 1936fdd039c68451
Tool calling returned: None
-------------------------
Gmagent: Email sent.
Your ask:
list_emails_function = """
{
"type": "function",
"function": {
"name": "list_emails",
"description": "Return a list of emails matching an optionally specified query.",
"parameters": {
"type": "dic",
"properties": [
{
"maxResults": {
"type": "integer",
"description": "The default maximum number of emails to return is 100; the maximum allowed value for this field is 500."
}
},
{
"query": {
"type": "string",
"description": "One or more keywords in the email subject and body, or one or more filters. There can be 6 types of filters: 1) Field-specific Filters: from, to, cc, bcc, subject; 2) Date Filters: before, after, older than, newer than); 3) Status Filters: read, unread, starred, importatant; 4) Attachment Filters: has, filename or type; 5) Size Filters: larger, smaller; 6) logical operators (or, and, not)."
}
}
],
"required": []
}
}
}
"""
get_email_function = """
{
"type": "function",
"function": {
"name": "get_email_detail",
"description": "Get detailed info about a specific email",
"parameters": {
"type": "dict",
"properties": [
{
"detail": {
"type": "string",
"description": "what detail the user wants to know about - two possible values: body or attachment"
}
},
{
"which": {
"type": "string",
"description": "which email to get detail about - possible values include: 'first', 'second', ..., 'last', 'from ...', and 'subject ...'"
}
},
],
"required": ["detail", "which"]
}
}
}
"""
send_email_function = """
{
"type": "function",
"function": {
"name": "send_email",
"description": "Compose, reply, or forward email",
"parameters": {
"type": "dict",
"properties": [
{
"action": {
"type": "string",
"description": "Whether to compose, reply, or forward an email"
}
},
{
"to": {
"type": "string",
"description": "The recipient of the email"
}
},
{
"subject": {
"type": "string",
"description": "The email subject"
}
},
{
"body": {
"type": "string",
"description": "The email content"
}
},
{
"email_id": {
"type": "string",
"description": "the email id to reply or forward to"
}
}
],
"required": ["action", "to", "subject", "body"]
}
}
}
"""
get_pdf_summary_function = """
{
"type": "function",
"function": {
"name": "get_pdf_summary",
"description": "get a summary of a PDF attachment",
"parameters": {
"type": "dict",
"properties": [
{
"file_name": {
"type": "string",
"description": "The name of the PDF file"
}
},
],
"required": ["file_name"]
}
}
}
"""
create_draft_function = """
{
"type": "function",
"function": {
"name": "create_draft",
"description": "Create a new, reply, or forward email draft",
"parameters": {
"type": "dict",
"properties": [
{
"action": {
"type": "string",
"description": "Whether to draft a new, reply, or forward an email"
}
},
{
"to": {
"type": "string",
"description": "The recipient of the email"
}
},
{
"subject": {
"type": "string",
"description": "The email subject"
}
},
{
"body": {
"type": "string",
"description": "The email content"
}
},
{
"email_id": {
"type": "string",
"description": "the email id to reply or forward to, or empty if draft a new email."
}
}
],
"required": ["action", "to", "subject", "body", "email_id"]
}
}
}
"""
# for now, only allow for one draft email to be saved in a session
# to support for multiple drafts, cf how get_email_detail after list_emails is implemented.
send_draft_function = """
{
"type": "function",
"function": {
"name": "send_draft",
"description": "Send a draft email",
"parameters": {
"type": "dict",
"properties": [
{
"id": {
"type": "string",
"description": "draft id"
}
},
],
"required": ["id"]
}
}
}
"""
examples = """
{"name": "list_emails", "parameters": {"query": "has:attachment larger:5mb"}}
{"name": "list_emails", "parameters": {"query": "has:attachment"}}
{"name": "list_emails", "parameters": {"query": "newer_than:1d"}}
{"name": "list_emails", "parameters": {"query": "older_than:1d"}}
{"name": "list_emails", "parameters": {"query": "is:unread"}}
{"name": "list_emails", "parameters": {"query": "<query> is:unread"}}
{"name": "list_emails", "parameters": {"query": "<query> is:read"}}
{"name": "get_email_detail", "parameters": {"detail": "body", "which": "first"}}
{"name": "get_email_detail", "parameters": {"detail": "body", "which": "last"}}
{"name": "get_email_detail", "parameters": {"detail": "body", "which": "second"}}
{"name": "get_email_detail", "parameters": {"detail": "body", "which": "subject <subject info>"}}
{"name": "get_email_detail", "parameters": {"detail": "attachment", "which": "from <sender info>"}}
{"name": "get_email_detail", "parameters": {"detail": "attachment", "which": "first"}}
{"name": "get_email_detail", "parameters": {"detail": "attachment", "which": "last"}}
{"name": "get_email_detail", "parameters": {"detail": "attachment", "which": "<email id>"}}
{"name": "send_email", "parameters": {"action": "compose", "to": "jeffxtang@meta.com", "subject": "xxxxx", "body": "xxxxx"}}
{"name": "send_email", "parameters": {"action": "reply", "to": "", "subject": "xxxxx", "body": "xxxxx", "email_id": "xxxxx"}}
{"name": "send_email", "parameters": {"action": "forward", "to": "jeffxtang@meta.com", "subject": "xxxxx", "body": "xxxxx", "email_id": "xxxxx"}}
{"name": "create_draft", "parameters": {"action": "new", "to": "jeffxtang@meta.com", "subject": "xxxxx", "body": "xxxxx", "email_id": ""}}
{"name": "create_draft", "parameters": {"action": "reply", "to": "", "subject": "xxxxx", "body": "xxxxx", "email_id": "xxxxx"}}
{"name": "create_draft", "parameters": {"action": "forward", "to": "jeffxtang@meta.com", "subject": "xxxxx", "body": "xxxxx", "email_id": "xxxxx"}}
{"name": "send_draft", "parameters": {"id": "..."}}
{"name": "get_pdf_summary", "parameters": {"file_name": "..."}}
"""
system_prompt = f"""
Environment: ipython
Cutting Knowledge Date: December 2023
Today Date: 1 December 2024
Your name is Gmagent, an assistant that can perform all Gmail related tasks for your user.
Respond to the user's ask by making use of the following functions if needed.
If no available functions can be used, just say "I don't know" and don't make up facts.
Here is a list of available functions in JSON format:
{list_emails_function}
{get_email_function}
{send_email_function}
{get_pdf_summary_function}
{create_draft_function}
{send_draft_function}
Example responses:
{examples}
"""
import argparse
import gmagent
from gmagent import *
from functions_prompt import system_prompt
def main():
parser = argparse.ArgumentParser(description="Set email address")
parser.add_argument("--user_email", type=str, required=True, help="Your Gmail address")
args = parser.parse_args()
gmagent.set_email_service(args.user_email)
greeting = llama31("hello", "Your name is Gmagent, an assistant that can perform all Gmail related tasks for your user.")
agent_response = f"{greeting}\n\nYour ask: "
agent = Agent(system_prompt)
while True:
ask = input(agent_response)
if ask == "bye":
print(llama31("bye"))
break
print("\n-------------------------\nCalling Llama...")
agent(ask)
agent_response = "Your ask: "
if __name__ == "__main__":
main()
google-auth==2.27.0
google-auth-oauthlib==0.4.6
google-auth-httplib2==0.1.0
google-api-python-client==2.34.0
pytz
beautifulsoup4
ollama
pypdf
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment