-
Notifications
You must be signed in to change notification settings - Fork 12
Add Reactome user guide Q&A with intent-based routing. #166
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
Open
heliamoh
wants to merge
4
commits into
main
Choose a base branch
from
feature/userguide-qa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| from typing import Literal | ||
|
|
||
| from langchain_core.language_models.chat_models import BaseChatModel | ||
| from langchain_core.prompts import ChatPromptTemplate | ||
| from langchain_core.runnables import Runnable | ||
| from pydantic import BaseModel, Field | ||
|
|
||
| SourceName = Literal["reactome", "userguide"] | ||
|
|
||
| intent_classifier_message = """ | ||
| You route user questions for the React-to-Me assistant to the correct knowledge source. | ||
|
|
||
| Choose exactly one source: | ||
|
|
||
| - **reactome**: Questions about biology, molecular mechanisms, pathways, reactions, proteins, genes, | ||
| diseases, and other scientific content in the Reactome Knowledgebase. | ||
| Examples: "What is apoptosis?", "Which pathways involve TP53?", "What does CDK5 do?" | ||
|
|
||
| - **userguide**: Questions about how to use the Reactome **website**, tools, or interface. | ||
| Examples: "How do I use the pathway browser?", "How do I search Reactome?", | ||
| "How do I run gene list analysis?", "What is the Details Panel?" | ||
|
|
||
| Rules: | ||
| - If the user asks how to perform a task in Reactome or about UI features, choose **userguide**. | ||
| - If the user asks about biological facts or pathway content, choose **reactome**. | ||
| - When unsure, prefer **reactome** for science content and **userguide** for clear how-to or UI questions. | ||
| """ | ||
|
|
||
| intent_classifier_prompt = ChatPromptTemplate.from_messages( | ||
| [ | ||
| ("system", intent_classifier_message), | ||
| ("human", "User question:\n\n{rephrased_input}"), | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| class QueryIntent(BaseModel): | ||
| source: SourceName = Field( | ||
| description="The knowledge source that should answer this question: 'reactome' or 'userguide'." | ||
| ) | ||
|
|
||
|
|
||
| _FALLBACK_ORDER: tuple[SourceName, ...] = ("reactome", "userguide") | ||
|
|
||
|
|
||
| def resolve_active_sources( | ||
| source: SourceName, | ||
| available_sources: frozenset[SourceName], | ||
| ) -> list[SourceName]: | ||
| if not available_sources: | ||
| raise ValueError("available_sources must not be empty") | ||
| if source in available_sources: | ||
| return [source] | ||
| for fallback in _FALLBACK_ORDER: | ||
| if fallback in available_sources: | ||
| return [fallback] | ||
| return [next(iter(available_sources))] | ||
|
|
||
|
|
||
| def create_intent_classifier(llm: BaseChatModel) -> Runnable: | ||
| return intent_classifier_prompt | llm.with_structured_output(QueryIntent) |
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
Oops, something went wrong.
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.