Skip to content

Commit

Permalink
Create get_credentials function to handle oauth google
Browse files Browse the repository at this point in the history
  • Loading branch information
DEENUU1 committed Jan 24, 2024
1 parent 8c3d6d0 commit a63e11a
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 168 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ app/media/
credentials.json
app/credentials.json
app/token.pickle
app/token.json

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
68 changes: 0 additions & 68 deletions app/ai/integration/google_calendar.py

This file was deleted.

19 changes: 0 additions & 19 deletions app/ai/tools/google_calendar.py
Original file line number Diff line number Diff line change
@@ -1,19 +0,0 @@
from typing import Union, Dict, Tuple
from langchain_core.tools import BaseTool
from ai.integration.google_calendar import Calendar


class GoogleCalendarListEventTool(BaseTool):
name = "google_calendar_list_event_tool"
description = "Useful for when you need to answer questions about events from Google calendar"

def _to_args_and_kwargs(self, tool_input: Union[str, Dict]) -> Tuple[Tuple, Dict]:
return (), {}

def _run(self) -> str:
calendar = Calendar()
return calendar.get_all_events()

async def _arun(self) -> str:
"""Use the tool asynchronously."""
raise NotImplementedError("custom_search does not support async")
70 changes: 0 additions & 70 deletions app/google_auth.py

This file was deleted.

File renamed without changes.
17 changes: 17 additions & 0 deletions app/integration/google_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os.path
from google_auth_oauthlib.flow import InstalledAppFlow
from google.oauth2.credentials import Credentials


SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"]


def get_credentials() -> None | Credentials:
if os.path.exists("credentials.json"):
flow = InstalledAppFlow.from_client_secrets_file("credentials.json", SCOPES)
creds = flow.run_local_server(port=0)
with open("token.json", "w") as token:
token.write(creds.to_json())
return Credentials.from_authorized_user_file("token.json", SCOPES)
else:
print("Credentials were not provided")
File renamed without changes.
11 changes: 2 additions & 9 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

from config.settings import settings
from routers import health, chat, media
import google_auth

from integration.google_auth import get_credentials
# from config.database import engine, Base
# Base.metadata.create_all(bind=engine)

Expand All @@ -16,6 +15,7 @@
title=settings.TITLE,
)

get_credentials()
app.include_router(health.router)
app.include_router(chat.router)
app.include_router(media.router)
Expand All @@ -34,15 +34,8 @@
def startup_event() -> None:
"""
On app start check if 'media' directory exists and if not create it
Create credentials.json file
"""
if not os.path.exists("media"):
print("Create media directory")
os.mkdir("media")
print("Media directory created")


@app.get("/")
def root():
google_auth.main()
return {"message": "Hello World"}
3 changes: 1 addition & 2 deletions app/routers/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
from fastapi import File, UploadFile
from fastapi import Response

from ai.integration.notion import notion, get_map_category
from integration.notion import notion, get_map_category
from ai.sql_chat_history import get_all_conversations
from ai.vector import save_to_pinecone
from ai.vector import split_files
from config.settings import settings
from schemas.media import FileCategory

import os

Expand Down

0 comments on commit a63e11a

Please sign in to comment.