Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Semantic Router
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
aurelio-labs
Semantic Router
Commits
5eca3c02
Unverified
Commit
5eca3c02
authored
1 year ago
by
Siraj R Aizlewood
Browse files
Options
Downloads
Patches
Plain Diff
New PyTests.
parent
0262f97b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/unit/test_layer.py
+36
-0
36 additions, 0 deletions
tests/unit/test_layer.py
with
36 additions
and
0 deletions
tests/unit/test_layer.py
+
36
−
0
View file @
5eca3c02
...
...
@@ -8,6 +8,7 @@ from semantic_router.encoders import BaseEncoder, CohereEncoder, OpenAIEncoder
from
semantic_router.layer
import
LayerConfig
,
RouteLayer
from
semantic_router.llms.base
import
BaseLLM
from
semantic_router.route
import
Route
from
semantic_router.index.local
import
LocalIndex
def
mock_encoder_call
(
utterances
):
...
...
@@ -522,3 +523,38 @@ class TestLayerConfig:
layer_config
=
LayerConfig
(
routes
=
[
route
])
layer_config
.
remove
(
"
test
"
)
assert
layer_config
.
routes
==
[]
def
test_check_threshold_with_none_route
(
self
,
openai_encoder
):
route_layer
=
RouteLayer
(
encoder
=
openai_encoder
)
result
=
route_layer
.
_check_threshold
(
scores
=
[
0.5
,
0.6
],
route
=
None
)
assert
(
not
result
),
"
Expected _check_threshold to return False when route is None.
"
def
test_simulate_static_route_selection_returns_route_choice
(
self
,
openai_encoder
,
routes
):
route_layer
=
RouteLayer
(
encoder
=
openai_encoder
,
routes
=
routes
)
# Manually set the index to simulate a scenario where a route passes the threshold
route_layer
.
index
=
LocalIndex
()
# Assuming routes[0] is the route we want to simulate as the top route
route_layer
.
index
.
add
(
embeddings
=
[[
0.1
,
0.2
,
0.3
]],
routes
=
[
routes
[
0
].
name
],
utterances
=
[
routes
[
0
].
utterances
[
0
]],
)
# Adjust the score_threshold to ensure the route passes the threshold
route_layer
.
score_threshold
=
0
# Simulate a vector that would match the route we added to the index
vector
=
[
0.1
,
0.2
,
0.3
]
route_choice
=
route_layer
.
_simulate_static_route_selection
(
vector
=
vector
)
assert
(
route_choice
.
name
==
routes
[
0
].
name
),
"
Expected the RouteChoice name to match the simulated top route name.
"
assert
route_choice
.
function_call
is
None
,
"
Expected function_call to be None.
"
assert
(
route_choice
.
similarity_score
is
None
),
"
Expected similarity_score to be None.
"
assert
route_choice
.
trigger
is
None
,
"
Expected trigger to be None.
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment