Skip to content

Commit

Permalink
[feat]
Browse files Browse the repository at this point in the history
  • Loading branch information
keenborder786 committed Sep 29, 2023
1 parent 302bf1c commit cbb3168
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 8 deletions.
87 changes: 84 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pip install inarrator
- Chat-GPT Example

```python
from inarrator.email import Gmail
from inarrator.summarizer.gpt import GPTModel

gmail = Gmail()
gmail.authenticate(
Expand All @@ -46,8 +48,7 @@ pip install inarrator
gmail_filters="from:(-noreply -no-reply) is:unread -category:social -category:promotions -unsubscribe", #
gmail_max_emails="30",
)
os.environ['OPENAI_API_KEY'] = ''
model = GPTModel(model_name = 'gpt-3.5-turbo-16k')
model = GPTModel(model_name = 'gpt-3.5-turbo-16k',api_token = "") # OPENAI_API_KEY
documents = []
for email in emails:
documents.append(email)
Expand All @@ -59,6 +60,10 @@ pip install inarrator

```python

from inarrator.email import Gmail
from inarrator.summarizer import HuggingFaceModel


gmail = Gmail()
gmail.authenticate(
credentials_path="gmail_credentials.json",
Expand All @@ -68,7 +73,7 @@ pip install inarrator
gmail_filters="from:(-noreply -no-reply) is:unread -category:social -category:promotions -unsubscribe",
gmail_max_emails="30",
)
model = HuggingFaceModel(api_token="",model_name="tuner007/pegasus_summarizer")
model = HuggingFaceModel(model_name="tuner007/pegasus_summarizer", api_token="") # HF_HUB_TOKEN
print(model.summarize(emails[0])) # Hugging Face Hub Models currently can summarize one email at a time.
```

Expand All @@ -77,3 +82,79 @@ pip install inarrator
### Outlook


1. Create a New App [Registration](https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade)
![](https://github.com/keenborder786/INarrator/blob/main/assets/Image_1_Outlook.png)

2. Request API permissions (Only Mail.Read)

![](https://github.com/keenborder786/INarrator/blob/main/assets/Image_3_Outlook.png)


3. Configure the Platform

- Add a Mobile and Desktop Application
![](https://github.com/keenborder786/INarrator/blob/main/assets/Image_4_Outlook.png)
- Choose the Following Configuration
![](https://github.com/keenborder786/INarrator/blob/main/assets/Image_5_Outlook.png)


4. Create a new client secret

- Click on `+ New client secret`.
![](https://github.com/keenborder786/INarrator/blob/main/assets/Image_2_Outlook.png)
- Now create the following JSON and name it `outlook_credentials.json`. You can get `Application (client) ID` & `Directory (tenant) ID` from overview of your App.
```json
{"application_id":"Application (client) ID",
"authority_url":"https://login.microsoftonline.com/{Directory (tenant) ID}",
"outlook_scope":["Mail.Read"]}
```
5. Since OAuth only work https but our redirect URI is localhost, we would have to make the following environment variable

```console
export OAUTHLIB_INSECURE_TRANSPORT=1
```

5. Use the inarrator

- Chat-GPT Example

```python
from inarrator.email import OutLook
from inarrator.summarizer.gpt import GPTModel

outlook = OutLook()
outlook.authenticate(
credentials_path="outlook_credentials.json",
outlook_scope=["Mail.Read"],
)
emails = outlook.get_latest_emails(
outlook_max_emails=5,
)
model = GPTModel(model_name = 'gpt-3.5-turbo-16k',api_token = "") # OPENAI_API_KEY
documents = []
for email in emails:
documents.append(email)
print(model.summarize(documents))

```

- Hugging Face Hub Example

```python

from inarrator.email import OutLook
from inarrator.summarizer.huggingface import HuggingFaceModel


outlook = OutLook()
outlook.authenticate(
credentials_path="outlook_credentials.json",
outlook_scope=["Mail.Read"],
)
emails = outlook.get_latest_emails(
outlook_max_emails=5,
)
model = HuggingFaceModel(model_name="tuner007/pegasus_summarizer", api_token="") # HF_HUB_TOKEN
print(model.summarize(emails[0])) # Hugging Face Hub Models currently can summarize one email at a time.

```
Binary file added assets/Image_5_Outlook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions inarrator/email/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# ruff: noqa: D104
from inarrator.email.email import Gmail # noqa
from inarrator.email.user import User # noqa
# ruff: noqa: F401, D104
from inarrator.email.email import Gmail, OutLook
from inarrator.email.user import User
4 changes: 3 additions & 1 deletion inarrator/email/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ def _token(self, **kwargs: Any) -> Dict:
credentials_json = json.load(f)
f.close()
client_instance = msal.PublicClientApplication(
client_id=credentials_json.get("application_id"), authority=kwargs.get("authority_url")
client_id=credentials_json.get("application_id"),
authority=credentials_json.get("authority_url"),
)
result = client_instance.acquire_token_interactive(scopes=kwargs.get("outlook_scope"))
print(result)
if "access_token" not in result:
raise ValueError("Authentication Error for Outlook Client")
return result
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "inarrator"
version = "0.0.1"
version = "0.0.3"
description = "Summarize and Narrate your emails through power of LLMs."
authors = ["keenborder786 <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit cbb3168

Please sign in to comment.