Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add Andis link for init prompt and fix regex expression #245

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/backend/RAG/LangChain_Implementation/get_google_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
from googleapiclient.discovery import build
from googleapiclient.http import MediaIoBaseDownload


def extract_document_id_from_url(url):
pattern = r'[A-Za-z0-9]*'
pattern = r'/d/([a-zA-Z0-9-_]+)'
matches = re.findall(pattern, url)
document_id = max(matches, key=len)
return document_id


def authenticate(credentials, scopes):
"""Obtaining auth with needed apis"""
creds = None
Expand Down Expand Up @@ -63,14 +65,19 @@ def download_file(file_id, credentials_path, file_name):


# Example usage
document_id = extract_document_id_from_url("https://docs.google.com/document/d/1xrfrwyRCTrxiCupiKSSFgKUxiCTXgr45gPJYybnY23w/edit")
document_id = extract_document_id_from_url(
'https://docs.google.com/document/d/1GtLyBqhk-cu8CSo4A15WTgGDbMbL4B9LLjdvBoU3234/edit'
)
# print("Document id: ", document_id)
credentials_json = 'credentials.json'

# Define the file path in a cross-platform manner
file_name = Path('data') / 'google_docs_content.txt'
file_name.parent.mkdir(parents=True, exist_ok=True)

# TODO: make this callable from typescript with url

content = download_file(document_id, credentials_json, file_name)
print(content)
try:
content = download_file(document_id, credentials_json, file_name)
print(content)
except Exception as e:
print(f'An error occurred: {e}')
Loading