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
e679623a
Commit
e679623a
authored
5 months ago
by
James Briggs
Browse files
Options
Downloads
Patches
Plain Diff
fix: test
parent
0e5aa5dc
Branches
Branches containing commit
Tags
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
+35
-22
35 additions, 22 deletions
tests/unit/test_layer.py
with
35 additions
and
22 deletions
tests/unit/test_layer.py
+
35
−
22
View file @
e679623a
...
...
@@ -186,13 +186,23 @@ def get_test_indexes():
return
indexes
def
get_test_encoders
():
encoders
=
[
OpenAIEncoder
]
if
importlib
.
util
.
find_spec
(
"
cohere
"
)
is
not
None
:
encoders
.
append
(
CohereEncoder
)
return
encoders
@pytest.mark.parametrize
(
"
index_cls
"
,
get_test_indexes
())
class
TestRouteLayer
:
def
test_initialization
(
self
,
openai_encoder
,
routes
,
index_cls
):
@pytest.mark.parametrize
(
"
index_cls,encoder_cls
"
,
[
(
index
,
encoder
)
for
index
in
get_test_indexes
()
for
encoder
in
get_test_encoders
()
])
class
TestIndexEncoders
:
def
test_initialization
(
self
,
routes
,
index_cls
,
encoder_cls
):
index
=
init_index
(
index_cls
)
route_layer
=
RouteLayer
(
encoder
=
openai_
encoder
,
routes
=
routes
,
index
=
index
,
encoder
=
encoder
_cls
()
,
routes
=
routes
,
index
=
index
,
auto_sync
=
"
local
"
if
index_cls
is
PineconeIndex
else
None
,
top_k
=
10
,
)
...
...
@@ -210,35 +220,32 @@ class TestRouteLayer:
)
def
test_initialization_different_encoders
(
self
,
cohere_encoder
,
openai_
encoder
,
index_cls
self
,
encoder
_cls
,
index_cls
):
index
=
init_index
(
index_cls
)
route_layer_cohere
=
RouteLayer
(
encoder
=
cohere_encoder
,
index
=
index
)
assert
cohere_encoder
.
score_threshold
==
0.3
assert
route_layer_cohere
.
score_threshold
==
0.3
route_layer_openai
=
RouteLayer
(
encoder
=
openai_encoder
,
index
=
index
)
assert
route_layer_openai
.
score_threshold
==
0.3
encoder
=
encoder_cls
()
route_layer
=
RouteLayer
(
encoder
=
encoder
,
index
=
index
)
assert
route_layer
.
score_threshold
==
encoder
.
score_threshold
def
test_initialization_no_encoder
(
self
,
openai_encoder
,
index_cls
):
def
test_initialization_no_encoder
(
self
,
openai_encoder
,
index_cls
,
encoder_cls
):
os
.
environ
[
"
OPENAI_API_KEY
"
]
=
"
test_api_key
"
route_layer_none
=
RouteLayer
(
encoder
=
None
)
assert
route_layer_none
.
score_threshold
==
openai_encoder
.
score_threshold
def
test_initialization_dynamic_route
(
self
,
cohere_encoder
,
openai_
encoder
,
dynamic_routes
,
index_cls
self
,
encoder
_cls
,
dynamic_routes
,
index_cls
):
index
=
init_index
(
index_cls
)
route_layer_cohere
=
RouteLayer
(
encoder
=
cohere_encoder
,
routes
=
dynamic_routes
,
index
=
index
,
encoder
=
encoder_cls
()
route_layer
=
RouteLayer
(
encoder
=
encoder
,
routes
=
dynamic_routes
,
index
=
index
,
auto_sync
=
"
local
"
if
index_cls
is
PineconeIndex
else
None
,
)
assert
route_layer_cohere
.
score_threshold
==
0.3
route_layer_openai
=
RouteLayer
(
encoder
=
openai_encoder
,
routes
=
dynamic_routes
,
index
=
index
)
assert
openai_encoder
.
score_threshold
==
0.3
assert
route_layer_openai
.
score_threshold
==
0.3
assert
route_layer
.
score_threshold
==
encoder
.
score_threshold
@pytest.mark.parametrize
(
"
index_cls
"
,
get_test_indexes
())
class
TestRouteLayer
:
def
test_delete_index
(
self
,
openai_encoder
,
routes
,
index_cls
):
# TODO merge .delete_index() and .delete_all() and get working
index
=
init_index
(
index_cls
)
...
...
@@ -759,7 +766,10 @@ class TestRouteLayer:
def
test_retrieve_one_match
(
self
,
openai_encoder
,
routes_3
,
index_cls
):
index
=
init_index
(
index_cls
)
route_layer
=
RouteLayer
(
encoder
=
openai_encoder
,
routes
=
routes_3
,
index
=
index
)
route_layer
=
RouteLayer
(
encoder
=
openai_encoder
,
routes
=
routes_3
,
index
=
index
,
auto_sync
=
"
local
"
,
)
text
=
"
Hello
"
if
index_cls
is
PineconeIndex
:
time
.
sleep
(
PINECONE_SLEEP
)
...
...
@@ -772,7 +782,10 @@ class TestRouteLayer:
self
,
openai_encoder
,
routes_2
,
index_cls
):
index
=
init_index
(
index_cls
)
route_layer
=
RouteLayer
(
encoder
=
openai_encoder
,
routes
=
routes_2
,
index
=
index
)
route_layer
=
RouteLayer
(
encoder
=
openai_encoder
,
routes
=
routes_2
,
index
=
index
,
auto_sync
=
"
local
"
,
)
text
=
"
Hello
"
if
index_cls
is
PineconeIndex
:
time
.
sleep
(
PINECONE_SLEEP
)
...
...
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