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
7d0aaae2
Commit
7d0aaae2
authored
1 year ago
by
Arash Mosharraf
Browse files
Options
Downloads
Patches
Plain Diff
fixed the test not getting 87% coverage
parent
287126d5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
semantic_router/llms/zure.py
+4
-4
4 additions, 4 deletions
semantic_router/llms/zure.py
tests/unit/llms/test_llm_azure_openai.py
+11
-4
11 additions, 4 deletions
tests/unit/llms/test_llm_azure_openai.py
with
15 additions
and
8 deletions
semantic_router/llms/zure.py
+
4
−
4
View file @
7d0aaae2
...
...
@@ -23,11 +23,11 @@ class AzureOpenAILLM(BaseLLM):
api_version
=
"
2023-07-01-preview
"
,
):
if
name
is
None
:
name
=
os
.
getenv
(
"
OPENAI_CHAT_MODEL_NAME
"
,
"
gpt-35-turbo
"
)
name
=
os
.
getenv
(
"
OPENAI_CHAT_MODEL_NAME
"
,
"
gpt-3
.
5-turbo
"
)
super
().
__init__
(
name
=
name
)
api_key
=
openai_api_key
or
os
.
getenv
(
"
AZURE_OPENAI_API_KEY
"
)
if
api_key
is
None
:
raise
ValueError
(
"
OpenAI API key cannot be
'
None
'
.
"
)
raise
ValueError
(
"
Azure
OpenAI API key cannot be
'
None
'
.
"
)
azure_endpoint
=
azure_endpoint
or
os
.
getenv
(
"
AZURE_OPENAI_ENDPOINT
"
)
if
azure_endpoint
is
None
:
raise
ValueError
(
"
Azure endpoint API key cannot be
'
None
'
.
"
)
...
...
@@ -36,13 +36,13 @@ class AzureOpenAILLM(BaseLLM):
api_key
=
api_key
,
azure_endpoint
=
azure_endpoint
,
api_version
=
api_version
)
except
Exception
as
e
:
raise
ValueError
(
f
"
OpenAI API client failed to initialize. Error:
{
e
}
"
)
raise
ValueError
(
f
"
Azure
OpenAI API client failed to initialize. Error:
{
e
}
"
)
self
.
temperature
=
temperature
self
.
max_tokens
=
max_tokens
def
__call__
(
self
,
messages
:
List
[
Message
])
->
str
:
if
self
.
client
is
None
:
raise
ValueError
(
"
OpenAI client is not initialized.
"
)
raise
ValueError
(
"
Azure
OpenAI client is not initialized.
"
)
try
:
completion
=
self
.
client
.
chat
.
completions
.
create
(
model
=
self
.
name
,
...
...
This diff is collapsed.
Click to expand it.
tests/unit/llms/test_llm_azure_openai.py
+
11
−
4
View file @
7d0aaae2
...
...
@@ -6,8 +6,8 @@ from semantic_router.schema import Message
@pytest.fixture
def
azure_openai_llm
(
mocker
):
mocker
.
patch
(
"
azure
openai.Client
"
)
return
AzureOpenAILLM
(
openai_api_key
=
"
test_api_key
"
)
mocker
.
patch
(
"
openai.Client
"
)
return
AzureOpenAILLM
(
openai_api_key
=
"
test_api_key
"
,
azure_endpoint
=
"
test_endpoint
"
)
class
TestOpenAILLM
:
...
...
@@ -25,12 +25,19 @@ class TestOpenAILLM:
with
pytest
.
raises
(
ValueError
)
as
_
:
AzureOpenAILLM
()
# def test_azure_openai_llm_init_without_azure_endpoint(self, mocker):
# mocker.patch("os.getenv", side_effect=[None, "fake-api-key"])
# with pytest.raises(ValueError) as e:
# AzureOpenAILLM(openai_api_key="test_api_key")
# assert "Azure endpoint API key cannot be 'None'." in str(e.value)
def
test_azure_openai_llm_init_without_azure_endpoint
(
self
,
mocker
):
mocker
.
patch
(
"
os.getenv
"
,
side_effect
=
[
None
,
"
fake-api-key
"
])
# Simulate missing Azure endpoint
mocker
.
patch
(
"
os.getenv
"
,
side_effect
=
lambda
key
,
default
=
None
:
{
"
OPENAI_CHAT_MODEL_NAME
"
:
"
test-model-name
"
}.
get
(
key
,
default
))
with
pytest
.
raises
(
ValueError
)
as
e
:
AzureOpenAILLM
(
openai_api_key
=
"
test_api_key
"
)
assert
"
Azure endpoint API key cannot be
'
None
'"
in
str
(
e
.
value
)
def
test_azure_openai_llm_call_uninitialized_client
(
self
,
azure_openai_llm
):
# Set the client to None to simulate an uninitialized client
azure_openai_llm
.
client
=
None
...
...
@@ -52,7 +59,7 @@ class TestOpenAILLM:
def
test_azure_openai_llm_temperature_max_tokens_initialization
(
self
):
test_temperature
=
0.5
test_max_tokens
=
100
azure_llm
=
AzureOpenAILLM
(
openai_api_key
=
"
test_api_key
"
,
temperature
=
test_temperature
,
max_tokens
=
test_max_tokens
)
azure_llm
=
AzureOpenAILLM
(
openai_api_key
=
"
test_api_key
"
,
azure_endpoint
=
"
test_endpoint
"
,
temperature
=
test_temperature
,
max_tokens
=
test_max_tokens
)
assert
azure_llm
.
temperature
==
test_temperature
,
"
Temperature not set correctly
"
assert
azure_llm
.
max_tokens
==
test_max_tokens
,
"
Max tokens not set correctly
"
...
...
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