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

Feat: Hivemind include url for documents #330

Merged
merged 15 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def prepare_document(
reactions = message["reactions"]
raw_content = message["content"]

message_id = message["messageId"]
channel_id = message["channelId"]
thread_id = message["threadId"]

reaction_ids = prepare_raction_ids(reactions)

mention_names: list[str]
Expand Down Expand Up @@ -161,10 +165,16 @@ def prepare_document(
# always has length 1
assert len(author_name) == 1, "Either None or multiple authors!"

if thread_id is None:
url = f"https://discord.com/channels/{guild_id}/{channel_id}/{message_id}"
else:
url = f"https://discord.com/channels/{guild_id}/{thread_id}/{message_id}"

amindadgar marked this conversation as resolved.
Show resolved Hide resolved
msg_meta_data = {
"channel": message["channelName"],
"date": message["createdDate"].strftime(DATE_FORMAT),
"author_username": author_name[0],
"url": url,
# always including the thread_name, if `None`, then it was a channel message
"thread": message["threadName"],
}
Expand Down Expand Up @@ -234,6 +244,7 @@ def prepare_document(
"replier_global_name",
"replier_nickname",
"role_mentions",
"url",
]
doc.excluded_llm_metadata_keys = [
"author_nickname",
Expand All @@ -250,6 +261,7 @@ def prepare_document(
"replier_global_name",
"replier_nickname",
"role_mentions",
"url",
]
else:
doc = Document(text=content_url_updated)
Expand Down
2 changes: 1 addition & 1 deletion dags/hivemind_etl_helpers/src/db/github/extract/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _fetch_raw_commits(
user_commiter.login AS committer_name,
co.`commit.message` AS message,
co.`commit.url` AS api_url,
co.`parents.0.html_url` AS html_url,
co.`parents.0.html_url` AS url,
co.repository_id AS repository_id,
repo.full_name AS repository_name,
co.sha AS sha,
Expand Down
8 changes: 4 additions & 4 deletions dags/hivemind_etl_helpers/src/db/github/schema/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def __init__(
committer_name: str,
message: str,
api_url: str,
html_url: str,
url: str,
repository_id: int,
repository_name: str,
sha: str,
Expand All @@ -26,7 +26,7 @@ def __init__(
self.committer_name = committer_name
self.message = message
self.api_url = api_url
self.html_url = html_url
self.url = url
self.repository_id = repository_id
self.repository_name = repository_name
self.sha = sha
Expand All @@ -42,7 +42,7 @@ def from_dict(cls, data: dict[str, str | int | None]) -> "GitHubCommit":
committer_name=data["committer_name"], # type: ignore
message=data["message"], # type: ignore
api_url=data["api_url"], # type: ignore
html_url=data["html_url"], # type: ignore
url=data["url"], # type: ignore
repository_id=data["repository_id"], # type: ignore
repository_name=data["repository_name"], # type: ignore
sha=data["sha"], # type: ignore
Expand All @@ -58,7 +58,7 @@ def to_dict(self) -> dict[str, str | int | None]:
"committer_name": self.committer_name,
"message": self.message,
"api_url": self.api_url,
"html_url": self.html_url,
"url": self.url,
"repository_id": self.repository_id,
"repository_name": self.repository_name,
"sha": self.sha,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def transform_commits(data: list[GitHubCommit]) -> list[Document]:
metadata=metadata,
# all metadata to be excluded from embedding model
excluded_embed_metadata_keys=list(metadata.keys()),
excluded_llm_metadata_keys=["sha", "api_url", "html_url", "verification"],
excluded_llm_metadata_keys=["sha", "api_url", "url", "verification"],
)
transformed_commits.append(document)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def test_transform_two_data(self):
"author_username": "user1",
"author_global_name": "user1_GlobalName",
"author_nickname": "user1_nickname",
"url": f"https://discord.com/channels/{guild_id}/1313130/1111111110",
"thread": None,
}

Expand All @@ -180,6 +181,7 @@ def test_transform_two_data(self):
"mention_global_names": ["user3_GlobalName", "user4_GlobalName"],
"replier_username": "user4",
"replier_global_name": "user4_GlobalName",
"url": f"https://discord.com/channels/{guild_id}/1313131/1111111111",
"thread": None,
}

Expand All @@ -192,6 +194,7 @@ def test_transform_two_data(self):
"mention_global_names": ["user3_GlobalName", "user4_GlobalName"],
"replier_username": "user4",
"replier_global_name": "user4_GlobalName",
"url": f"https://discord.com/channels/{guild_id}/88888/1111111112",
"thread": "example_thread1",
"role_mentions": ["role1"],
}
Expand All @@ -203,6 +206,7 @@ def test_transform_two_data(self):
"author_global_name": "user1_GlobalName",
"author_nickname": "user1_nickname",
"url_reference": {"[URL0]": "https://www.google.com"},
"url": f"https://discord.com/channels/{guild_id}/1313133/1111111113",
"thread": None,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_get_single_commit_single_repo_no_from_date(self):
self.assertEqual(commits[0].committer_name, "author #1")
self.assertEqual(commits[0].message, "Issue #1 is resolved!")
self.assertEqual(commits[0].api_url, "https://api.sample_url_for_commit.html")
self.assertEqual(commits[0].html_url, "https://sample_url_for_commit.html")
self.assertEqual(commits[0].url, "https://sample_url_for_commit.html")
amindadgar marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(commits[0].repository_id, 123)
self.assertEqual(commits[0].repository_name, "Org/SampleRepo")
self.assertEqual(commits[0].sha, "sha#1111")
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_get_single_commit_single_repo_no_from_date_no_commiter(self):
self.assertEqual(commits[0].committer_name, None)
self.assertEqual(commits[0].message, "Issue #1 is resolved!")
self.assertEqual(commits[0].api_url, "https://api.sample_url_for_commit.html")
self.assertEqual(commits[0].html_url, "https://sample_url_for_commit.html")
self.assertEqual(commits[0].url, "https://sample_url_for_commit.html")
self.assertEqual(commits[0].repository_id, 123)
self.assertEqual(commits[0].repository_name, "Org/SampleRepo")
self.assertEqual(commits[0].sha, "sha#1111")
Expand Down Expand Up @@ -150,7 +150,7 @@ def test_get_single_commit_single_repo_with_from_date(self):
self.assertEqual(commits[0].author_name, "author #2")
self.assertEqual(commits[0].message, "Issue #1 is resolved!")
self.assertEqual(commits[0].api_url, "https://api.sample_url_for_commit.html")
self.assertEqual(commits[0].html_url, "https://sample_url_for_commit.html")
self.assertEqual(commits[0].url, "https://sample_url_for_commit.html")
self.assertEqual(commits[0].repository_id, 123)
self.assertEqual(commits[0].repository_name, "Org/SampleRepo2")
self.assertEqual(commits[0].sha, "sha#1111")
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_get_multiple_commit_multi_repo_with_from_date_filter(self):
self.assertEqual(commits[0].committer_name, "author #1")
self.assertEqual(commits[0].message, "Issue #1 is resolved!")
self.assertEqual(commits[0].api_url, "https://api.sample_url_for_commit.html")
self.assertEqual(commits[0].html_url, "https://sample_url_for_commit.html")
self.assertEqual(commits[0].url, "https://sample_url_for_commit.html")
self.assertEqual(commits[0].repository_id, 123)
self.assertEqual(commits[0].repository_name, "Org/SampleRepo2")
self.assertEqual(commits[0].sha, "sha#1111")
Expand Down Expand Up @@ -272,7 +272,7 @@ def test_fetch_commit_no_related_pr(self):
self.assertEqual(commits[0].committer_name, None)
self.assertEqual(commits[0].message, "Issue #1 is resolved!")
self.assertEqual(commits[0].api_url, "https://api.sample_url_for_commit.html")
self.assertEqual(commits[0].html_url, "https://sample_url_for_commit.html")
self.assertEqual(commits[0].url, "https://sample_url_for_commit.html")
self.assertEqual(commits[0].repository_id, 123)
self.assertEqual(commits[0].repository_name, "Org/SampleRepo")
self.assertEqual(commits[0].sha, "sha#1111")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_commit_transformation(self):
sha="sha#1000000",
created_at=datetime(2023, 11, 1).strftime("%Y-%m-%dT%H:%M:%SZ"),
latest_saved_at=datetime(2023, 12, 1, 1).strftime("%Y-%m-%dT%H:%M:%SZ"),
html_url="https://github.com/repo/commit/1",
url="https://github.com/repo/commit/1",
api_url="https://api.github.com/repo/commit/1",
repository_id=123,
repository_name="SampleRepo",
Expand All @@ -104,7 +104,7 @@ def test_commit_transformation(self):
"sha": "sha#1000000",
"created_at": "2023-11-01 00:00:00",
"latest_saved_at": "2023-12-01 01:00:00",
"html_url": "https://github.com/repo/commit/1",
"url": "https://github.com/repo/commit/1",
"api_url": "https://api.github.com/repo/commit/1",
"repository_id": 123,
"repository_name": "SampleRepo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_github_single_document(self):
sha="sha#1000000",
created_at=datetime(2023, 11, 1).strftime("%Y-%m-%dT%H:%M:%SZ"),
latest_saved_at=datetime(2023, 12, 1, 1).strftime("%Y-%m-%dT%H:%M:%SZ"),
html_url="https://github.com/repo/commit/1",
url="https://github.com/repo/commit/1",
api_url="https://api.github.com/repo/commit/1",
repository_id=123,
repository_name="SampleRepo",
Expand All @@ -42,7 +42,7 @@ def test_github_single_document(self):
"sha": "sha#1000000",
"created_at": "2023-11-01 00:00:00",
"latest_saved_at": "2023-12-01 01:00:00",
"html_url": "https://github.com/repo/commit/1",
"url": "https://github.com/repo/commit/1",
"api_url": "https://api.github.com/repo/commit/1",
"repository_id": 123,
"repository_name": "SampleRepo",
Expand All @@ -61,7 +61,7 @@ def test_multiple_documents(self):
sha="sha#1000000",
created_at=datetime(2023, 11, 1).strftime("%Y-%m-%dT%H:%M:%SZ"),
latest_saved_at=datetime(2023, 12, 1, 1).strftime("%Y-%m-%dT%H:%M:%SZ"),
html_url="https://github.com/repo/commit/1",
url="https://github.com/repo/commit/1",
api_url="https://api.github.com/repo/commit/1",
repository_id=123,
repository_name="SampleRepo",
Expand All @@ -75,7 +75,7 @@ def test_multiple_documents(self):
sha="sha#1000001",
created_at=datetime(2023, 11, 2).strftime("%Y-%m-%dT%H:%M:%SZ"),
latest_saved_at=datetime(2023, 12, 2, 1).strftime("%Y-%m-%dT%H:%M:%SZ"),
html_url="https://github.com/repo/commit/2",
url="https://github.com/repo/commit/2",
api_url="https://api.github.com/repo/commit/2",
repository_id=123,
repository_name="SampleRepo",
Expand All @@ -88,7 +88,7 @@ def test_multiple_documents(self):
sha="sha#1000002",
created_at=datetime(2023, 11, 3).strftime("%Y-%m-%dT%H:%M:%SZ"),
latest_saved_at=datetime(2023, 12, 3, 1).strftime("%Y-%m-%dT%H:%M:%SZ"),
html_url="https://github.com/repo/commit/3",
url="https://github.com/repo/commit/3",
api_url="https://api.github.com/repo/commit/3",
repository_id=126,
repository_name="SampleRepo#6",
Expand All @@ -114,7 +114,7 @@ def test_multiple_documents(self):
"sha": "sha#1000000",
"created_at": "2023-11-01 00:00:00",
"latest_saved_at": "2023-12-01 01:00:00",
"html_url": "https://github.com/repo/commit/1",
"url": "https://github.com/repo/commit/1",
"api_url": "https://api.github.com/repo/commit/1",
"repository_id": 123,
"repository_name": "SampleRepo",
Expand All @@ -132,7 +132,7 @@ def test_multiple_documents(self):
"sha": "sha#1000001",
"created_at": "2023-11-02 00:00:00",
"latest_saved_at": "2023-12-02 01:00:00",
"html_url": "https://github.com/repo/commit/2",
"url": "https://github.com/repo/commit/2",
"api_url": "https://api.github.com/repo/commit/2",
"repository_id": 123,
"repository_name": "SampleRepo",
Expand All @@ -150,7 +150,7 @@ def test_multiple_documents(self):
"sha": "sha#1000002",
"created_at": "2023-11-03 00:00:00",
"latest_saved_at": "2023-12-03 01:00:00",
"html_url": "https://github.com/repo/commit/3",
"url": "https://github.com/repo/commit/3",
"api_url": "https://api.github.com/repo/commit/3",
"repository_id": 126,
"repository_name": "SampleRepo#6",
Expand Down
Loading