Skip to content

Commit b727eaa

Browse files
strickvlCopilotClaude
authored
Add missing type hints (#210)
* Add type hints to various functions * Update zencoder/steps/deployment.py Co-authored-by: Copilot <[email protected]> * Fix dead link in PR template Corrected the path to CONTRIBUTING.md in the PR template by changing it from a relative path (CONTRIBUTING.md) to a path that goes up one directory (../CONTRIBUTING.md). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent 54dbfa0 commit b727eaa

File tree

7 files changed

+50
-23
lines changed

7 files changed

+50
-23
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Please provide a short summary explaining the motivation behind these changes.
44

55
# Checklist
6-
- [ ] I have read the [contributing guidelines](CONTRIBUTING.md).
6+
- [ ] I have read the [contributing guidelines](../CONTRIBUTING.md).
77
- [ ] I have run the necessary tests and linters.
88
- [ ] I have updated relevant documentation where applicable.
99

end-to-end-computer-vision/utils/dataset_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
logger = get_logger(__name__)
3232

3333

34-
def load_images_from_folder(folder):
35-
images = []
34+
def load_images_from_folder(folder: str) -> List[Image.Image]:
35+
images: List[Image.Image] = []
3636
for filename in os.listdir(folder):
3737
if (
3838
filename.endswith(".png")
@@ -45,7 +45,9 @@ def load_images_from_folder(folder):
4545
return images
4646

4747

48-
def load_images_from_source(data_source, download_dir, filenames):
48+
def load_images_from_source(
49+
data_source: str, download_dir: str, filenames: List[str]
50+
) -> None:
4951
total_images = len(filenames)
5052
for index, filename in enumerate(filenames):
5153
src_path = f"{data_source}/{filename}.png"

llm-complete-guide/most_basic_rag_pipeline.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,26 @@
1717

1818
import re
1919
import string
20+
from typing import List
2021

2122
from openai import OpenAI
2223
from utils.openai_utils import get_openai_api_key
2324

2425

25-
def preprocess_text(text):
26+
def preprocess_text(text: str) -> str:
2627
text = text.lower()
2728
text = text.translate(str.maketrans("", "", string.punctuation))
2829
text = re.sub(r"\s+", " ", text).strip()
2930
return text
3031

3132

32-
def tokenize(text):
33+
def tokenize(text: str) -> List[str]:
3334
return preprocess_text(text).split()
3435

3536

36-
def retrieve_relevant_chunks(query, corpus, top_n=2):
37+
def retrieve_relevant_chunks(
38+
query: str, corpus: List[str], top_n: int = 2
39+
) -> List[str]:
3740
query_tokens = set(tokenize(query))
3841
similarities = []
3942
for chunk in corpus:
@@ -46,7 +49,7 @@ def retrieve_relevant_chunks(query, corpus, top_n=2):
4649
return [chunk for chunk, _ in similarities[:top_n]]
4750

4851

49-
def answer_question(query, corpus, top_n=2):
52+
def answer_question(query: str, corpus: List[str], top_n: int = 2) -> str:
5053
relevant_chunks = retrieve_relevant_chunks(query, corpus, top_n)
5154
if not relevant_chunks:
5255
return "I don't have enough information to answer the question."

nightwatch-ai/src/pipelines/supabase_summary.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@
1313
# permissions and limitations under the License.
1414

1515

16+
from typing import Any, Callable
17+
1618
from zenml.pipelines import pipeline
1719

1820
pipeline_name = "daily_supabase_summary"
1921

2022

2123
@pipeline(name=pipeline_name)
22-
def daily_supabase_summary(get_latest_data, generate_summary, report_summary):
24+
def daily_supabase_summary(
25+
get_latest_data: Callable[[], Any],
26+
generate_summary: Callable[[Any], Any],
27+
report_summary: Callable[[Any], Any],
28+
) -> None:
2329
"""Generates a summary of the latest data.
2430
2531
Args:

nightwatch-ai/src/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from zenml.client import Client
2222

2323

24-
def main():
24+
def main() -> None:
2525
if Client().active_stack.alerter is None:
2626
# we use a print alerter
2727
alerter = print_alerter()

zencoder/steps/deployment.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, Optional, cast
1+
from typing import Dict, Optional, Tuple, cast
22

33
from zenml import get_step_context, step
44
from zenml.client import Client
@@ -14,7 +14,23 @@
1414
logger = get_logger(__name__)
1515

1616

17-
def parse_huggingface_url(url):
17+
def parse_huggingface_url(url: str) -> Tuple[str, str, str]:
18+
"""
19+
Parses a Hugging Face Hub URL to extract the namespace, repository, and revision.
20+
21+
Args:
22+
url: The Hugging Face Hub URL to parse. Expected format:
23+
"https://huggingface.co/{namespace}/{repository}/tree/{revision}".
24+
25+
Returns:
26+
A tuple containing:
27+
- namespace: The owner or organization of the repository.
28+
- repository: The name of the repository.
29+
- revision: The specific commit hash or branch name.
30+
31+
Raises:
32+
ValueError: If the URL does not match the expected format.
33+
"""
1834
# Split the URL into parts
1935
parts = url.split("/")
2036

zencoder/steps/trainer.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import functools
99
import os
1010
import random
11-
from typing import Optional, Tuple
11+
from typing import List, Optional, Tuple
1212

1313
import numpy as np
1414
import torch
@@ -66,16 +66,16 @@ def get_fim_token_ids(tokenizer):
6666

6767
## Adapted from https://github.com/bigcode-project/Megatron-LM/blob/6c4bf908df8fd86b4977f54bf5b8bd4b521003d1/megatron/data/gpt_dataset.py
6868
def permute(
69-
sample,
70-
np_rng,
71-
suffix_tok_id,
72-
prefix_tok_id,
73-
middle_tok_id,
74-
pad_tok_id,
75-
fim_rate=0.5,
76-
fim_spm_rate=0.5,
77-
truncate_or_pad=False,
78-
):
69+
sample: List[int],
70+
np_rng: np.random.RandomState,
71+
suffix_tok_id: Optional[int],
72+
prefix_tok_id: Optional[int],
73+
middle_tok_id: Optional[int],
74+
pad_tok_id: Optional[int],
75+
fim_rate: float = 0.5,
76+
fim_spm_rate: float = 0.5,
77+
truncate_or_pad: bool = False,
78+
) -> Tuple[List[int], np.random.RandomState]:
7979
"""
8080
Take in a sample (list of tokens) and perform a FIM transformation on it with a probability of fim_rate, using two FIM modes:
8181
PSM and SPM (with a probability of fim_spm_rate).

0 commit comments

Comments
 (0)