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
5141474a
Commit
5141474a
authored
1 year ago
by
Ismail Ashraq
Browse files
Options
Downloads
Patches
Plain Diff
fix test issues
parent
adc8e853
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_route.py
+18
-23
18 additions, 23 deletions
tests/unit/test_route.py
with
18 additions
and
23 deletions
tests/unit/test_route.py
+
18
−
23
View file @
5141474a
from
unittest.mock
import
Mock
,
patch
# , AsyncMock
from
unittest.mock
import
patch
# , AsyncMock
# import pytest
from
semantic_router.llms
import
BaseLLM
from
semantic_router.route
import
Route
,
is_valid
...
...
@@ -41,11 +42,9 @@ def test_is_valid_with_invalid_json():
mock_logger
.
error
.
assert_called_once
()
class
TestRoute
:
@patch
(
"
semantic_router.route.llm
"
,
new_callable
=
Mock
)
def
test_generate_dynamic_route
(
self
,
mock_llm
):
print
(
f
"
mock_llm:
{
mock_llm
}
"
)
mock_llm
.
return_value
=
"""
class
MockLLM
(
BaseLLM
):
def
__call__
(
self
,
prompt
):
llm_output
=
"""
<config>
{
"
name
"
:
"
test_function
"
,
...
...
@@ -58,8 +57,16 @@ class TestRoute:
}
</config>
"""
return
llm_output
class
TestRoute
:
def
test_generate_dynamic_route
(
self
):
mock_llm
=
MockLLM
(
name
=
"
test
"
)
function_schema
=
{
"
name
"
:
"
test_function
"
,
"
type
"
:
"
function
"
}
route
=
Route
.
_generate_dynamic_route
(
function_schema
)
route
=
Route
.
_generate_dynamic_route
(
llm
=
mock_llm
,
function_schema
=
function_schema
)
assert
route
.
name
==
"
test_function
"
assert
route
.
utterances
==
[
"
example_utterance_1
"
,
...
...
@@ -105,6 +112,7 @@ class TestRoute:
"
utterances
"
:
[
"
utterance
"
],
"
description
"
:
None
,
"
function_schema
"
:
None
,
"
llm
"
:
None
,
}
assert
route
.
to_dict
()
==
expected_dict
...
...
@@ -114,28 +122,15 @@ class TestRoute:
assert
route
.
name
==
"
test
"
assert
route
.
utterances
==
[
"
utterance
"
]
@patch
(
"
semantic_router.route.llm
"
,
new_callable
=
Mock
)
def
test_from_dynamic_route
(
self
,
mock_llm
):
def
test_from_dynamic_route
(
self
):
# Mock the llm function
mock_llm
.
return_value
=
"""
<config>
{
"
name
"
:
"
test_function
"
,
"
utterances
"
: [
"
example_utterance_1
"
,
"
example_utterance_2
"
,
"
example_utterance_3
"
,
"
example_utterance_4
"
,
"
example_utterance_5
"
]
}
</config>
"""
mock_llm
=
MockLLM
(
name
=
"
test
"
)
def
test_function
(
input
:
str
):
"""
Test function docstring
"""
pass
dynamic_route
=
Route
.
from_dynamic_route
(
test_function
)
dynamic_route
=
Route
.
from_dynamic_route
(
llm
=
mock_llm
,
entity
=
test_function
)
assert
dynamic_route
.
name
==
"
test_function
"
assert
dynamic_route
.
utterances
==
[
...
...
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