-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(email): Add email sender tool and update image generator tool (#…
…2579) This pull request adds a new email sender tool and updates the image generator tool.
- Loading branch information
1 parent
105a2b8
commit 01c6e7b
Showing
6 changed files
with
110 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .image_generator import ImageGeneratorTool | ||
from .web_search import WebSearchTool | ||
from .url_reader import URLReaderTool | ||
|
||
from .email_sender import EmailSenderTool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Extract and combine content recursively | ||
from typing import Dict, Optional, Type | ||
|
||
from langchain.callbacks.manager import ( | ||
AsyncCallbackManagerForToolRun, | ||
CallbackManagerForToolRun, | ||
) | ||
from langchain.pydantic_v1 import BaseModel as BaseModelV1 | ||
from langchain.pydantic_v1 import Field as FieldV1 | ||
from langchain_community.document_loaders import PlaywrightURLLoader | ||
from langchain_core.tools import BaseTool | ||
from logger import get_logger | ||
from models import BrainSettings | ||
from modules.contact_support.controller.settings import ContactsSettings | ||
from packages.emails.send_email import send_email | ||
from pydantic import BaseModel | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class EmailInput(BaseModelV1): | ||
text: str = FieldV1( | ||
..., | ||
title="text", | ||
description="text to send in HTML email format. Use pretty formating, use bold, italic, next line, etc...", | ||
) | ||
|
||
|
||
class EmailSenderTool(BaseTool): | ||
user_email: str | ||
name = "email-sender" | ||
description = "useful for when you need to send an email." | ||
args_schema: Type[BaseModel] = EmailInput | ||
brain_settings: BrainSettings = BrainSettings() | ||
contact_settings: ContactsSettings = ContactsSettings() | ||
|
||
def _run( | ||
self, text: str, run_manager: Optional[CallbackManagerForToolRun] = None | ||
) -> Dict: | ||
|
||
html_body = f""" | ||
<div style="text-align: center;"> | ||
<img src="https://quivr-cms.s3.eu-west-3.amazonaws.com/logo_quivr_white_7e3c72620f.png" alt="Quivr Logo" style="width: 100px; height: 100px; border-radius: 50%; margin: 0 auto; display: block;"> | ||
<br /> | ||
</div> | ||
""" | ||
html_body += f""" | ||
{text} | ||
""" | ||
logger.debug(f"Email body: {html_body}") | ||
logger.debug(f"Email to: {self.user_email}") | ||
logger.debug(f"Email from: {self.contact_settings.resend_contact_sales_from}") | ||
try: | ||
r = send_email( | ||
{ | ||
"sender": self.contact_settings.resend_contact_sales_from, | ||
"to": self.user_email, | ||
"reply_to": "no-reply@quivr.app", | ||
"subject": "Email from your assistant", | ||
"html": html_body, | ||
} | ||
) | ||
logger.info("Resend response", r) | ||
except Exception as e: | ||
logger.error(f"Error sending email: {e}") | ||
return {"content": "Error sending email because of error: " + str(e)} | ||
|
||
return {"content": "Email sent"} | ||
|
||
async def _arun( | ||
self, url: str, run_manager: Optional[AsyncCallbackManagerForToolRun] = None | ||
) -> Dict: | ||
"""Run the tool asynchronously.""" | ||
loader = PlaywrightURLLoader(urls=[url], remove_selectors=["header", "footer"]) | ||
data = loader.load() | ||
|
||
extracted_content = "" | ||
for page in data: | ||
extracted_content += page.page_content | ||
|
||
return {"content": extracted_content} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters