Spaces:
Running
Running
Refactor Dockerfile permissions and remove unnecessary print statements; update email parameter in collect function
Browse files- Dockerfile +2 -2
- app/models/mails/__init__.py +0 -1
- app/retriever/__init__.py +0 -1
- app/router/auth.py +21 -1
- app/router/mail.py +3 -4
- app/utils.py +1 -1
Dockerfile
CHANGED
@@ -8,9 +8,9 @@ COPY . .
|
|
8 |
WORKDIR /app
|
9 |
|
10 |
# Create a cache directory and set permissions
|
11 |
-
RUN chmod -R 777 /app
|
12 |
RUN mkdir -p /app/cache && chmod -R 777 /app/cache
|
13 |
-
RUN mkdir -p /app/nltk_data && chmod -R 777 /app/nltk_data
|
14 |
|
15 |
# Install requirements.txt
|
16 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|
|
8 |
WORKDIR /app
|
9 |
|
10 |
# Create a cache directory and set permissions
|
11 |
+
# RUN chmod -R 777 /app
|
12 |
RUN mkdir -p /app/cache && chmod -R 777 /app/cache
|
13 |
+
# RUN mkdir -p /app/nltk_data && chmod -R 777 /app/nltk_data
|
14 |
|
15 |
# Install requirements.txt
|
16 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
app/models/mails/__init__.py
CHANGED
@@ -30,7 +30,6 @@ def build_gmail_service():
|
|
30 |
if os.path.exists("token.pickle"):
|
31 |
with open("token.pickle", "rb") as token:
|
32 |
creds = pickle.load(token)
|
33 |
-
print(creds.to_json())
|
34 |
if not creds or not creds.valid:
|
35 |
if creds and creds.expired and creds.refresh_token:
|
36 |
creds.refresh(Request())
|
|
|
30 |
if os.path.exists("token.pickle"):
|
31 |
with open("token.pickle", "rb") as token:
|
32 |
creds = pickle.load(token)
|
|
|
33 |
if not creds or not creds.valid:
|
34 |
if creds and creds.expired and creds.refresh_token:
|
35 |
creds.refresh(Request())
|
app/retriever/__init__.py
CHANGED
@@ -62,7 +62,6 @@ class DocRetriever(BaseRetriever):
|
|
62 |
# # # "source": "Finfast"
|
63 |
# # }
|
64 |
# ))
|
65 |
-
# print(doc_lst)
|
66 |
return retrieved_docs
|
67 |
except RuntimeError as e:
|
68 |
logger.error("Error retrieving documents: %s", e)
|
|
|
62 |
# # # "source": "Finfast"
|
63 |
# # }
|
64 |
# ))
|
|
|
65 |
return retrieved_docs
|
66 |
except RuntimeError as e:
|
67 |
logger.error("Error retrieving documents: %s", e)
|
app/router/auth.py
CHANGED
@@ -45,6 +45,27 @@ async def get_auth_url():
|
|
45 |
|
46 |
@router.get("/auth/google/callback")
|
47 |
async def google_callback(code: str, request: Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
flow = InstalledAppFlow.from_client_config(CLIENT_CONFIG, SCOPES)
|
49 |
flow.redirect_uri = REDIRECT_URI
|
50 |
flow.fetch_token(code=code)
|
@@ -69,7 +90,6 @@ async def google_callback(code: str, request: Request):
|
|
69 |
# ))
|
70 |
service = build("gmail", "v1", credentials=credentials)
|
71 |
profile = service.users().getProfile(userId="me").execute()
|
72 |
-
print(({"profile": profile}))
|
73 |
with open(f"{profile['emailAddress']}.pickle", "wb") as token:
|
74 |
pickle.dump(credentials, token)
|
75 |
return JSONResponse(profile)
|
|
|
45 |
|
46 |
@router.get("/auth/google/callback")
|
47 |
async def google_callback(code: str, request: Request):
|
48 |
+
"""
|
49 |
+
Handles the Google OAuth2 callback by exchanging the authorization code for credentials,
|
50 |
+
retrieving the user's Gmail profile, and saving the credentials to a file.
|
51 |
+
|
52 |
+
Args:
|
53 |
+
code (str): The authorization code returned by Google's OAuth2 server.
|
54 |
+
request (Request): The incoming HTTP request object.
|
55 |
+
|
56 |
+
Returns:
|
57 |
+
JSONResponse: A JSON response containing the user's Gmail profile information.
|
58 |
+
|
59 |
+
Side Effects:
|
60 |
+
- Saves the user's credentials to a pickle file named after their email address.
|
61 |
+
- Stores the credentials in the session state of the request.
|
62 |
+
|
63 |
+
Dependencies:
|
64 |
+
- google_auth_oauthlib.flow.InstalledAppFlow: Used to handle the OAuth2 flow.
|
65 |
+
- googleapiclient.discovery.build: Used to build the Gmail API service.
|
66 |
+
- json: Used to serialize and deserialize credentials.
|
67 |
+
- pickle: Used to save credentials to a file.
|
68 |
+
"""
|
69 |
flow = InstalledAppFlow.from_client_config(CLIENT_CONFIG, SCOPES)
|
70 |
flow.redirect_uri = REDIRECT_URI
|
71 |
flow.fetch_token(code=code)
|
|
|
90 |
# ))
|
91 |
service = build("gmail", "v1", credentials=credentials)
|
92 |
profile = service.users().getProfile(userId="me").execute()
|
|
|
93 |
with open(f"{profile['emailAddress']}.pickle", "wb") as token:
|
94 |
pickle.dump(credentials, token)
|
95 |
return JSONResponse(profile)
|
app/router/mail.py
CHANGED
@@ -11,7 +11,7 @@ from googleapiclient.discovery import build
|
|
11 |
router = APIRouter(prefix="/mail", tags=["mail"])
|
12 |
|
13 |
@router.post("")
|
14 |
-
def collect(
|
15 |
"""
|
16 |
Handles the chat POST request.
|
17 |
|
@@ -21,9 +21,8 @@ def collect(emailAddress: str, request: Request):
|
|
21 |
Returns:
|
22 |
str: The generated response from the chat function.
|
23 |
"""
|
24 |
-
|
25 |
-
|
26 |
-
with open(f"{emailAddress}.pickle", "rb") as token:
|
27 |
credentials = pickle.load(token)
|
28 |
else:
|
29 |
cred_dict = request.state.session.get("credential")
|
|
|
11 |
router = APIRouter(prefix="/mail", tags=["mail"])
|
12 |
|
13 |
@router.post("")
|
14 |
+
def collect(email: str, request: Request):
|
15 |
"""
|
16 |
Handles the chat POST request.
|
17 |
|
|
|
21 |
Returns:
|
22 |
str: The generated response from the chat function.
|
23 |
"""
|
24 |
+
if os.path.exists(f"{email}.pickle"):
|
25 |
+
with open(f"{email}.pickle", "rb") as token:
|
|
|
26 |
credentials = pickle.load(token)
|
27 |
else:
|
28 |
cred_dict = request.state.session.get("credential")
|
app/utils.py
CHANGED
@@ -34,4 +34,4 @@ async def generate(req: ReqData):
|
|
34 |
yield "event: context\n"
|
35 |
yield f"data: {json.dumps({'context': context.metadata})}\n\n"
|
36 |
yield "event: questions\n"
|
37 |
-
yield f"data: {json.dumps({'questions': followUpChain.invoke(req.query, contexts)})}\n\n"
|
|
|
34 |
yield "event: context\n"
|
35 |
yield f"data: {json.dumps({'context': context.metadata})}\n\n"
|
36 |
yield "event: questions\n"
|
37 |
+
yield f"data: {json.dumps({'questions': followUpChain.invoke(req.query, contexts)})}\n\n"
|