-
Notifications
You must be signed in to change notification settings - Fork 6
Updated init and scan to support functions. #52
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
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {} |
120 changes: 120 additions & 0 deletions
120
src/datacustomcode/templates/function/payload/entrypoint.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import logging | ||
| from typing import List | ||
| from uuid import uuid4 | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def chunk_text(text: str, chunk_size: int = 1000) -> List[str]: | ||
| """ | ||
| Split text into chunks of approximately chunk_size characters. | ||
| Tries to split at sentence boundaries when possible. | ||
| """ | ||
| if not text: | ||
| return [] | ||
|
|
||
| chunks = [] | ||
| current_chunk = "" | ||
|
|
||
| # Split text into sentences (simple split by period) | ||
| sentences = text.split(". ") | ||
|
|
||
| for sentence in sentences: | ||
| if len(current_chunk) + len(sentence) <= chunk_size: | ||
| current_chunk += sentence + ". " | ||
| else: | ||
| if current_chunk: | ||
| chunks.append(current_chunk.strip()) | ||
| current_chunk = sentence + ". " | ||
|
|
||
| if current_chunk: | ||
| chunks.append(current_chunk.strip()) | ||
|
|
||
| return chunks | ||
|
|
||
|
|
||
| def dc_function(request: dict) -> dict: | ||
| logger.info("Inside DC Function") | ||
| logger.info(request) | ||
|
|
||
| items = request["input"] | ||
| output_chunks = [] | ||
| current_seq_no = 1 # Start sequence number from 1 | ||
|
|
||
| for item in items: | ||
| # Item is DocElement as dict | ||
| logger.info("Processing item: ") | ||
| logger.info(item) | ||
|
|
||
| text = item.get("text", "") | ||
| metadata = item.get("metadata", {}) | ||
|
|
||
| # Create chunks from the text | ||
| text_chunks = chunk_text(text, chunk_size=100) # Using a larger chunk size | ||
|
|
||
| # Create chunk dictionaries for each text chunk | ||
| for chunk_content in text_chunks: | ||
| chunk_dict = { | ||
| "text": chunk_content, | ||
| "metadata": metadata, | ||
| "seq_no": current_seq_no, | ||
| "chunk_type": "text", | ||
| "chunk_id": str(uuid4()), | ||
| "tag_metadata": {}, | ||
| "citations": {}, | ||
| "source_record": item, | ||
| } | ||
| output_chunks.append(chunk_dict) | ||
| current_seq_no += 1 # Increment sequence number for next chunk | ||
|
|
||
| logger.info("Completed chunking") | ||
| response = { | ||
| "output": output_chunks, | ||
| "status": {"status_type": "success", "status_message": "Chunking completed"}, | ||
| } | ||
| logger.info(response) | ||
| return response | ||
|
|
||
|
|
||
| # Test the function | ||
| if __name__ == "__main__": | ||
| # Configure logging | ||
| logging.basicConfig(level=logging.INFO) | ||
|
|
||
| # Create test data with two DocElements | ||
| test_request = { | ||
| "input": [ | ||
| { | ||
| "text": ( | ||
| """This is the first sentence of the first document, which is | ||
| intentionally made longer to test chunking. """ | ||
| """Here is the second sentence of the first document, which is also | ||
| quite long and should ensure that the chunking function splits | ||
| this text into two chunks when the chunk size is set to 100.""" | ||
| ), | ||
| "metadata": {"source": "test1", "type": "document"}, | ||
| }, | ||
| { | ||
| "text": ( | ||
| """This is the first sentence of the second document, and it is | ||
| also extended to be longer than usual for testing purposes. """ | ||
| """The second sentence of the second document is similarly lengthy, | ||
| so that the chunking function will again create two chunks for | ||
| this document.""" | ||
| ), | ||
| "metadata": {"source": "test2", "type": "document"}, | ||
| }, | ||
| ] | ||
| } | ||
|
|
||
| # Run the function | ||
| result = dc_function(test_request) | ||
|
|
||
| # Print the results in a more readable format | ||
| print("\nChunking Results:") | ||
| print("----------------") | ||
| for chunk in result["output"]: | ||
| print(f"\nChunk #{chunk['seq_no']}:") | ||
| print(f"Text: {chunk['text'][:100]}...") # Print first 100 chars of each chunk | ||
| print(f"Source: {chunk['metadata']['source']}") | ||
| print(f"Chunk ID: {chunk['chunk_id']}") | ||
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
src/datacustomcode/templates/script/.devcontainer/devcontainer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "Existing Dockerfile", | ||
| "build": { | ||
| "context": "..", | ||
| "dockerfile": "../Dockerfile" | ||
| }, | ||
| "features": { | ||
| "ghcr.io/devcontainers/features/git:1": {}, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| FROM public.ecr.aws/emr-on-eks/spark/emr-7.3.0:latest | ||
|
|
||
| USER root | ||
|
|
||
| # install from dev requirements.txt | ||
| COPY requirements-dev.txt ./requirements-dev.txt | ||
| RUN pip3.11 install --no-cache-dir -r requirements-dev.txt | ||
|
|
||
| # Install from requirements.txt: | ||
| COPY requirements.txt ./requirements.txt | ||
| RUN pip3.11 install --no-cache-dir -r requirements.txt | ||
|
|
||
| # Create workspace directory | ||
| RUN mkdir /workspace | ||
|
|
||
| # Set user and working directory | ||
| USER hadoop:hadoop | ||
| WORKDIR /workspace |
11 changes: 11 additions & 0 deletions
11
src/datacustomcode/templates/script/Dockerfile.dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| FROM public.ecr.aws/emr-on-eks/spark/emr-7.3.0:latest | ||
|
|
||
| USER root | ||
|
|
||
| RUN pip3.11 install venv-pack | ||
|
|
||
| # Create workspace directory | ||
| RUN mkdir /workspace | ||
| WORKDIR /workspace | ||
|
|
||
| CMD ["./build_native_dependencies.sh"] |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.