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
1eb511c0
Unverified
Commit
1eb511c0
authored
1 year ago
by
James Briggs
Browse files
Options
Downloads
Patches
Plain Diff
lint
parent
839c259a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/unit/test_layer.py
+18
-5
18 additions, 5 deletions
tests/unit/test_layer.py
with
18 additions
and
5 deletions
tests/unit/test_layer.py
+
18
−
5
View file @
1eb511c0
import
pytest
import
pytest
from
semantic_router.encoders
import
BaseEncoder
,
CohereEncoder
,
OpenAIEncoder
from
semantic_router.encoders
import
BaseEncoder
,
CohereEncoder
,
OpenAIEncoder
from
semantic_router.layer
import
DecisionLayer
,
HybridDecisionLayer
# Replace with the actual module name
from
semantic_router.layer
import
(
DecisionLayer
,
HybridDecisionLayer
,
)
# Replace with the actual module name
from
semantic_router.schema
import
Decision
from
semantic_router.schema
import
Decision
...
@@ -111,9 +114,12 @@ class TestDecisionLayer:
...
@@ -111,9 +114,12 @@ class TestDecisionLayer:
decision_layer
=
DecisionLayer
(
encoder
=
base_encoder
)
decision_layer
=
DecisionLayer
(
encoder
=
base_encoder
)
assert
decision_layer
.
score_threshold
==
0.82
assert
decision_layer
.
score_threshold
==
0.82
class
TestHybridDecisionLayer
:
class
TestHybridDecisionLayer
:
def
test_initialization
(
self
,
openai_encoder
,
decisions
):
def
test_initialization
(
self
,
openai_encoder
,
decisions
):
decision_layer
=
HybridDecisionLayer
(
encoder
=
openai_encoder
,
decisions
=
decisions
)
decision_layer
=
HybridDecisionLayer
(
encoder
=
openai_encoder
,
decisions
=
decisions
)
assert
decision_layer
.
score_threshold
==
0.82
assert
decision_layer
.
score_threshold
==
0.82
assert
len
(
decision_layer
.
index
)
==
5
assert
len
(
decision_layer
.
index
)
==
5
assert
len
(
set
(
decision_layer
.
categories
))
==
2
assert
len
(
set
(
decision_layer
.
categories
))
==
2
...
@@ -140,7 +146,9 @@ class TestHybridDecisionLayer:
...
@@ -140,7 +146,9 @@ class TestHybridDecisionLayer:
assert
len
(
set
(
decision_layer
.
categories
))
==
2
assert
len
(
set
(
decision_layer
.
categories
))
==
2
def
test_query_and_classification
(
self
,
openai_encoder
,
decisions
):
def
test_query_and_classification
(
self
,
openai_encoder
,
decisions
):
decision_layer
=
HybridDecisionLayer
(
encoder
=
openai_encoder
,
decisions
=
decisions
)
decision_layer
=
HybridDecisionLayer
(
encoder
=
openai_encoder
,
decisions
=
decisions
)
query_result
=
decision_layer
(
"
Hello
"
)
query_result
=
decision_layer
(
"
Hello
"
)
assert
query_result
in
[
"
Decision 1
"
,
"
Decision 2
"
]
assert
query_result
in
[
"
Decision 1
"
,
"
Decision 2
"
]
...
@@ -149,7 +157,9 @@ class TestHybridDecisionLayer:
...
@@ -149,7 +157,9 @@ class TestHybridDecisionLayer:
assert
decision_layer
(
"
Anything
"
)
is
None
assert
decision_layer
(
"
Anything
"
)
is
None
def
test_semantic_classify
(
self
,
openai_encoder
,
decisions
):
def
test_semantic_classify
(
self
,
openai_encoder
,
decisions
):
decision_layer
=
HybridDecisionLayer
(
encoder
=
openai_encoder
,
decisions
=
decisions
)
decision_layer
=
HybridDecisionLayer
(
encoder
=
openai_encoder
,
decisions
=
decisions
)
classification
,
score
=
decision_layer
.
_semantic_classify
(
classification
,
score
=
decision_layer
.
_semantic_classify
(
[
[
{
"
decision
"
:
"
Decision 1
"
,
"
score
"
:
0.9
},
{
"
decision
"
:
"
Decision 1
"
,
"
score
"
:
0.9
},
...
@@ -160,7 +170,9 @@ class TestHybridDecisionLayer:
...
@@ -160,7 +170,9 @@ class TestHybridDecisionLayer:
assert
score
==
[
0.9
]
assert
score
==
[
0.9
]
def
test_semantic_classify_multiple_decisions
(
self
,
openai_encoder
,
decisions
):
def
test_semantic_classify_multiple_decisions
(
self
,
openai_encoder
,
decisions
):
decision_layer
=
HybridDecisionLayer
(
encoder
=
openai_encoder
,
decisions
=
decisions
)
decision_layer
=
HybridDecisionLayer
(
encoder
=
openai_encoder
,
decisions
=
decisions
)
classification
,
score
=
decision_layer
.
_semantic_classify
(
classification
,
score
=
decision_layer
.
_semantic_classify
(
[
[
{
"
decision
"
:
"
Decision 1
"
,
"
score
"
:
0.9
},
{
"
decision
"
:
"
Decision 1
"
,
"
score
"
:
0.9
},
...
@@ -180,4 +192,5 @@ class TestHybridDecisionLayer:
...
@@ -180,4 +192,5 @@ class TestHybridDecisionLayer:
decision_layer
=
HybridDecisionLayer
(
encoder
=
base_encoder
)
decision_layer
=
HybridDecisionLayer
(
encoder
=
base_encoder
)
assert
decision_layer
.
score_threshold
==
0.82
assert
decision_layer
.
score_threshold
==
0.82
# Add more tests for edge cases and error handling as needed.
# Add more tests for edge cases and error handling as needed.
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