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
3b0de2d5
Commit
3b0de2d5
authored
1 year ago
by
zahid-syed
Browse files
Options
Downloads
Patches
Plain Diff
fixing pytest issues for optional dependency issues
parent
363ae337
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
semantic_router/encoders/mistral.py
+9
-9
9 additions, 9 deletions
semantic_router/encoders/mistral.py
semantic_router/llms/mistral.py
+4
-4
4 additions, 4 deletions
semantic_router/llms/mistral.py
with
13 additions
and
13 deletions
semantic_router/encoders/mistral.py
+
9
−
9
View file @
3b0de2d5
...
@@ -13,8 +13,8 @@ class MistralEncoder(BaseEncoder):
...
@@ -13,8 +13,8 @@ class MistralEncoder(BaseEncoder):
"""
Class to encode text using MistralAI
"""
"""
Class to encode text using MistralAI
"""
_client
:
Any
=
PrivateAttr
()
_client
:
Any
=
PrivateAttr
()
embedding_response
:
Any
=
PrivateAttr
()
_
embedding_response
:
Any
=
PrivateAttr
()
mistral_exception
:
Any
=
PrivateAttr
()
_
mistral_exception
:
Any
=
PrivateAttr
()
type
:
str
=
"
mistral
"
type
:
str
=
"
mistral
"
def
__init__
(
def
__init__
(
...
@@ -51,14 +51,14 @@ class MistralEncoder(BaseEncoder):
...
@@ -51,14 +51,14 @@ class MistralEncoder(BaseEncoder):
)
)
try
:
try
:
self
.
client
=
MistralClient
(
api_key
=
api_key
)
self
.
_
client
=
MistralClient
(
api_key
=
api_key
)
self
.
embedding_response
=
EmbeddingResponse
self
.
_
embedding_response
=
EmbeddingResponse
self
.
mistral_exception
=
MistralException
self
.
_
mistral_exception
=
MistralException
except
Exception
as
e
:
except
Exception
as
e
:
raise
ValueError
(
f
"
Unable to connect to MistralAI
{
e
.
args
}
:
{
e
}
"
)
from
e
raise
ValueError
(
f
"
Unable to connect to MistralAI
{
e
.
args
}
:
{
e
}
"
)
from
e
def
__call__
(
self
,
docs
:
List
[
str
])
->
List
[
List
[
float
]]:
def
__call__
(
self
,
docs
:
List
[
str
])
->
List
[
List
[
float
]]:
if
self
.
client
is
None
:
if
self
.
_
client
is
None
:
raise
ValueError
(
"
Mistral client not initialized
"
)
raise
ValueError
(
"
Mistral client not initialized
"
)
embeds
=
None
embeds
=
None
error_message
=
""
error_message
=
""
...
@@ -66,10 +66,10 @@ class MistralEncoder(BaseEncoder):
...
@@ -66,10 +66,10 @@ class MistralEncoder(BaseEncoder):
# Exponential backoff
# Exponential backoff
for
_
in
range
(
3
):
for
_
in
range
(
3
):
try
:
try
:
embeds
=
self
.
client
.
embeddings
(
model
=
self
.
name
,
input
=
docs
)
embeds
=
self
.
_
client
.
embeddings
(
model
=
self
.
name
,
input
=
docs
)
if
embeds
.
data
:
if
embeds
.
data
:
break
break
except
self
.
mistral_exception
as
e
:
except
self
.
_
mistral_exception
as
e
:
sleep
(
2
**
_
)
sleep
(
2
**
_
)
error_message
=
str
(
e
)
error_message
=
str
(
e
)
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -77,7 +77,7 @@ class MistralEncoder(BaseEncoder):
...
@@ -77,7 +77,7 @@ class MistralEncoder(BaseEncoder):
if
(
if
(
not
embeds
not
embeds
or
not
isinstance
(
embeds
,
self
.
embedding_response
)
or
not
isinstance
(
embeds
,
self
.
_
embedding_response
)
or
not
embeds
.
data
or
not
embeds
.
data
):
):
raise
ValueError
(
f
"
No embeddings returned from MistralAI:
{
error_message
}
"
)
raise
ValueError
(
f
"
No embeddings returned from MistralAI:
{
error_message
}
"
)
...
...
This diff is collapsed.
Click to expand it.
semantic_router/llms/mistral.py
+
4
−
4
View file @
3b0de2d5
...
@@ -11,7 +11,7 @@ from pydantic.v1 import PrivateAttr
...
@@ -11,7 +11,7 @@ from pydantic.v1 import PrivateAttr
class
MistralAILLM
(
BaseLLM
):
class
MistralAILLM
(
BaseLLM
):
client
:
Any
=
PrivateAttr
()
_
client
:
Any
=
PrivateAttr
()
temperature
:
Optional
[
float
]
temperature
:
Optional
[
float
]
max_tokens
:
Optional
[
int
]
max_tokens
:
Optional
[
int
]
...
@@ -42,17 +42,17 @@ class MistralAILLM(BaseLLM):
...
@@ -42,17 +42,17 @@ class MistralAILLM(BaseLLM):
"
`pip install
'
semantic-router[mistralai]
'
`
"
"
`pip install
'
semantic-router[mistralai]
'
`
"
)
)
try
:
try
:
self
.
client
=
MistralClient
(
api_key
=
api_key
)
self
.
_
client
=
MistralClient
(
api_key
=
api_key
)
except
Exception
as
e
:
except
Exception
as
e
:
raise
ValueError
(
raise
ValueError
(
f
"
MistralAI API client failed to initialize. Error:
{
e
}
"
f
"
MistralAI API client failed to initialize. Error:
{
e
}
"
)
from
e
)
from
e
def
__call__
(
self
,
messages
:
List
[
Message
])
->
str
:
def
__call__
(
self
,
messages
:
List
[
Message
])
->
str
:
if
self
.
client
is
None
:
if
self
.
_
client
is
None
:
raise
ValueError
(
"
MistralAI client is not initialized.
"
)
raise
ValueError
(
"
MistralAI client is not initialized.
"
)
try
:
try
:
completion
=
self
.
client
.
chat
(
completion
=
self
.
_
client
.
chat
(
model
=
self
.
name
,
model
=
self
.
name
,
messages
=
[
m
.
to_mistral
()
for
m
in
messages
],
messages
=
[
m
.
to_mistral
()
for
m
in
messages
],
temperature
=
self
.
temperature
,
temperature
=
self
.
temperature
,
...
...
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