-
Notifications
You must be signed in to change notification settings - Fork 37
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
Feature/semantic routing #540
Merged
+664
−68
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6cabf3a
[Semantic routing] AS | Update dependencies to include semantic routing
andy-symonds 39d3f1a
[Semantic-router] | AS | Adding semantic-router to pyproject.toml and…
andy-symonds 3c996dc
Merge branch 'main' into feature/semantic-routing
andy-symonds 5b0f1bc
patch
andy-symonds 6cca775
[semantic-router] | AS | Notebook with routes for info, gratitude, su…
andy-symonds ee1b83d
[semantic-router] | AS | Added an elasticsearch health check conditio…
andy-symonds 3dd320a
[semantic-router] | AS | Updated make run command to include --wait a…
andy-symonds a1113df
now using huggingface encoder
2a396da
revert makefile changes
ea7a0c9
e2e test extended
5a9e2d8
[semantic-routing] | AS | Addedd code for non-streaming endpoint rout…
andy-symonds f547a5a
[semantic-routing] | AS | Updated tests to reflect vannila endpoint n…
andy-symonds 02675bf
[semantic-routing] | AS | Update test_chat.py to reflect vanilla chat…
andy-symonds fce683c
[semantic-routing] | AS | fixed formating
andy-symonds 7d4ae58
[semantic-routing] | AS | Refactored build_chain logic and added coac…
andy-symonds 6775819
[semantic-routing] | AS | Rename variables for route responses and re…
andy-symonds b6acc72
[semantic-routing] | AS | Fixed formating
andy-symonds 9ce2510
[semantic-routing] | AS | Refactor semantic routing setup into semant…
andy-symonds 017590a
[semantic-routing] | AS | Add test for non-streaming chat/rag endpoint
andy-symonds da4a406
[semantic-routing] | AS | Fixed formating
andy-symonds 30766ad
formatting changes
92a79a9
Merge branch 'main' into feature/semantic-routing
41110d2
tests passing again
1e51560
linting
1c3a805
Merge branch 'main' into feature/semantic-routing
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 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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from semantic_router import Route | ||
from semantic_router.encoders import HuggingFaceEncoder | ||
from semantic_router.layer import RouteLayer | ||
|
||
from redbox.model_db import MODEL_PATH | ||
|
||
# === Pre-canned responses for non-LLM routes === | ||
INFO_RESPONSE = """ | ||
I am RedBox, an AI focused on helping UK Civil Servants, Political Advisors and | ||
Ministers triage and summarise information from a wide variety of sources. | ||
""" | ||
|
||
ABILITY_RESPONSE = """ | ||
* I can help you search over selected documents and do Q&A on them. | ||
* I can help you summarise selected documents. | ||
* I can help you extract information from selected documents. | ||
* I can return information in a variety of formats, such as bullet points. | ||
""" | ||
|
||
COACH_RESPONSE = """ | ||
I am sorry that didn't work. | ||
You could try rephrasing your task, i.e if you want to summarise a document please use the term, | ||
"Summarise the selected document" or "extract all action items from the selected document." | ||
If you want the results to be returned in a specific format, please specify the format in as much detail as possible. | ||
""" | ||
|
||
# === Set up the semantic router === | ||
info = Route( | ||
name="info", | ||
utterances=[ | ||
"What is your name?", | ||
"Who are you?", | ||
"What is Redbox?", | ||
], | ||
) | ||
|
||
ability = Route( | ||
name="ability", | ||
utterances=[ | ||
"What can you do?", | ||
"What can you do?", | ||
"How can you help me?", | ||
"What does Redbox do?", | ||
"What can Redbox do", | ||
"What don't you do", | ||
"Please help me", | ||
"Please help", | ||
"Help me!", | ||
"help", | ||
], | ||
) | ||
|
||
coach = Route( | ||
name="coach", | ||
utterances=[ | ||
"That is not the answer I wanted", | ||
"Rubbish", | ||
"No good", | ||
"That's not what I wanted", | ||
"How can I improve the results?", | ||
], | ||
) | ||
|
||
gratitude = Route( | ||
name="gratitude", | ||
utterances=[ | ||
"Thank you ever so much for your help!", | ||
"I'm really grateful for your assistance.", | ||
"Cheers for the detailed response!", | ||
"Thanks a lot, that was very informative.", | ||
"Nice one", | ||
"Thanks!", | ||
], | ||
) | ||
|
||
summarisation = Route( | ||
name="summarisation", | ||
utterances=[ | ||
"I'd like to summarise the documents I've uploaded.", | ||
"Can you help me with summarising these documents?", | ||
"Please summarise the documents with a focus on the impact on northern England", | ||
"Please summarise the contents of the uploaded files.", | ||
"I'd appreciate a summary of the documents I've just uploaded.", | ||
"Could you provide a summary of these uploaded documents?", | ||
"Summarise the documents with a focus on macro economic trends.", | ||
], | ||
) | ||
|
||
extract = Route( | ||
name="extract", | ||
utterances=[ | ||
"I'd like to find some information in the documents I've uploaded", | ||
"Can you help me identify details from these documents?", | ||
"Please give me all action items from this document", | ||
"Give me all the action items from these meeting notes", | ||
"Could you locate some key information in these uploaded documents?", | ||
"I need to obtain certain details from the documents I have uploaded, please", | ||
"Please extract all action items from this document", | ||
"Extract all the sentences with the word 'shall'", | ||
], | ||
) | ||
|
||
|
||
routes = [info, ability, coach, gratitude, summarisation, extract] | ||
|
||
encoder = HuggingFaceEncoder(name="sentence-transformers/paraphrase-albert-small-v2", cache_dir=MODEL_PATH) | ||
route_layer = RouteLayer(encoder=encoder, routes=routes) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our markdown formatter in the front end is interpreting:
so i have stripped them out