-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move async handling to outer loop (#71)
- [ ] I have considered whether this PR needs review, and requested a review if necessary. Fixes issue # # Notes for reviewers Reviewers can skip X, but should pay attention to Y.
- Loading branch information
1 parent
3784d73
commit 31465a9
Showing
7 changed files
with
62 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -11,7 +11,6 @@ select = [ | |
"COM", | ||
"D417", | ||
"E", | ||
"ERA", | ||
"F", | ||
"I", | ||
"ICN", | ||
|
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,25 +1,45 @@ | ||
from typing import TYPE_CHECKING, Sequence | ||
from typing import TYPE_CHECKING, Mapping, Sequence | ||
|
||
from iterpy.iter import Iter | ||
|
||
if TYPE_CHECKING: | ||
from memorymarker.document_providers.contextualized_highlight import ( | ||
ContextualizedHighlight, | ||
) | ||
from memorymarker.question_generator.highlight_to_question import ( | ||
HighlightToQuestion, | ||
) | ||
from memorymarker.question_generator.main import HighlightWithPipeline | ||
from memorymarker.question_generator.reasoned_highlight import ReasonedHighlight | ||
|
||
|
||
def run_pipelines( | ||
async def run_pipeline( | ||
pipeline_name: str, | ||
pipelinename2pipeline: Mapping[str, "HighlightToQuestion"], | ||
highlights: Sequence["ContextualizedHighlight"], | ||
) -> Iter["ReasonedHighlight"]: | ||
pipeline = pipelinename2pipeline[pipeline_name] | ||
prompts = pipeline(Iter(highlights)) | ||
return await prompts | ||
|
||
|
||
async def run_pipelines( | ||
pairs: "Iter[HighlightWithPipeline]", | ||
) -> Sequence["ReasonedHighlight"]: | ||
) -> Iter["ReasonedHighlight"]: | ||
pipelinename2pipeline = {pair.pipeline.name: pair.pipeline for pair in pairs} | ||
|
||
pipelines_with_highlights = pairs.groupby(lambda _: _.pipeline.name) | ||
|
||
examples: Sequence[ReasonedHighlight] = [] | ||
for pipeline_name, pair in pipelines_with_highlights: | ||
print(f"Creating examples for {pipeline_name}") | ||
highlights = [pair.highlight for pair in pair] | ||
pipeline = pipelinename2pipeline[pipeline_name] | ||
prompts = pipeline(Iter(highlights)) | ||
examples.extend(prompts) | ||
examples: Sequence["ReasonedHighlight"] = [] | ||
for pipeline_name, pairs_instance in pipelines_with_highlights: | ||
print(f"Running pipeline {pipeline_name}") | ||
for pair in pairs_instance: | ||
examples.extend( | ||
await run_pipeline( | ||
pipeline_name=pipeline_name, | ||
pipelinename2pipeline=pipelinename2pipeline, | ||
highlights=[pair.highlight], | ||
) | ||
) | ||
|
||
return examples | ||
return Iter(examples) |
This file contains 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