-
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: add wikilinks to question output (#135)
- Loading branch information
1 parent
c303b31
commit 710d1db
Showing
4 changed files
with
69 additions
and
3 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
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
42 changes: 42 additions & 0 deletions
42
memorymarker/question_generator/steps/question_wikilinker.py
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import asyncio | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING | ||
|
||
from memorymarker.question_generator.steps.step import FlowStep | ||
|
||
if TYPE_CHECKING: | ||
from memorymarker.question_generator.completers.completer import Completer | ||
from memorymarker.question_generator.qa_responses import QAPrompt | ||
from memorymarker.question_generator.reasoned_highlight import Highlights | ||
|
||
|
||
@dataclass(frozen=True) | ||
class QuestionWikilinkerStep(FlowStep): | ||
completer: "Completer" | ||
prompt = """In the following, identify the important, domain-specific terms. Then, capitalise them, and surround them with wikilinks. There can be more than one important term. Identify terms as you would in a wikipedia article. | ||
E.g.: | ||
When working with version control, why is the git amend command misleading? | ||
Turns into: | ||
When working with [[Version control]], why is the [[Git amend]] command misleading? | ||
Here is the question: | ||
{question} | ||
""" | ||
|
||
def identity(self) -> str: | ||
return f"{self.__class__.__name__}_{self.completer.identity()}" | ||
|
||
async def _wikilink_prompt(self, question: "QAPrompt") -> "QAPrompt": | ||
prompt = self.prompt.format(question=question.question) | ||
response = await self.completer(prompt) # type: ignore | ||
question.question = response | ||
return question | ||
|
||
async def __call__(self, highlight: "Highlights") -> "Highlights": | ||
prompts = highlight.question_answer_pairs | ||
wikilinked_prompts = await asyncio.gather( | ||
*[self._wikilink_prompt(prompt) for prompt in prompts] | ||
) | ||
highlight.question_answer_pairs = wikilinked_prompts | ||
return highlight |