T7yrttrd commited on
Commit
ef8df51
·
verified ·
1 Parent(s): 118790f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -12
app.py CHANGED
@@ -814,18 +814,36 @@ async def auth_callback(request: Request):
814
 
815
  cfg = OAUTH_CONFIGS.get(service, OAUTH_CONFIGS["google"])
816
  token_url = cfg["token_url"]
817
- payload = {
818
- "client_id": cfg["client_id"],
819
- "client_secret": cfg["client_secret"],
820
- "code": code,
821
- "grant_type": "authorization_code",
822
- "redirect_uri": REDIRECT_URI
823
- }
824
- headers = {"Accept": "application/json"}
825
 
826
- async with httpx.AsyncClient() as client:
827
- res = await client.post(token_url, data=payload, headers=headers)
828
- token_data = res.json()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
829
 
830
  if "access_token" in token_data or "token" in token_data:
831
  await save_token_to_supabase(user_id, service, token_data)
@@ -914,7 +932,7 @@ async def generate(request: Request):
914
 
915
  if content and not has_tool_call:
916
  yield json.dumps({"answer": content}) + "\n"
917
- except json.JSONDecodeError:
918
  continue
919
 
920
  if has_tool_call and tool_calls_acc:
 
814
 
815
  cfg = OAUTH_CONFIGS.get(service, OAUTH_CONFIGS["google"])
816
  token_url = cfg["token_url"]
 
 
 
 
 
 
 
 
817
 
818
+ if service == "notion":
819
+ auth_str = f"{cfg['client_id']}:{cfg['client_secret']}"
820
+ encoded_auth = base64.b64encode(auth_str.encode()).decode()
821
+ headers = {
822
+ "Authorization": f"Basic {encoded_auth}",
823
+ "Content-Type": "application/json",
824
+ "Notion-Version": "2022-06-28"
825
+ }
826
+ payload = {
827
+ "grant_type": "authorization_code",
828
+ "code": code,
829
+ "redirect_uri": REDIRECT_URI
830
+ }
831
+ async with httpx.AsyncClient() as client:
832
+ res = await client.post(token_url, json=payload, headers=headers)
833
+ token_data = res.json()
834
+ else:
835
+ payload = {
836
+ "client_id": cfg["client_id"],
837
+ "client_secret": cfg["client_secret"],
838
+ "code": code,
839
+ "grant_type": "authorization_code",
840
+ "redirect_uri": REDIRECT_URI
841
+ }
842
+ headers = {"Accept": "application/json"}
843
+
844
+ async with httpx.AsyncClient() as client:
845
+ res = await client.post(token_url, data=payload, headers=headers)
846
+ token_data = res.json()
847
 
848
  if "access_token" in token_data or "token" in token_data:
849
  await save_token_to_supabase(user_id, service, token_data)
 
932
 
933
  if content and not has_tool_call:
934
  yield json.dumps({"answer": content}) + "\n"
935
+ me:
936
  continue
937
 
938
  if has_tool_call and tool_calls_acc: