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
4a12b4a8
Commit
4a12b4a8
authored
1 year ago
by
zahid-syed
Browse files
Options
Downloads
Patches
Plain Diff
fix mistral ai llm issue
parent
09f0335b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
semantic_router/encoders/mistral.py
+4
-2
4 additions, 2 deletions
semantic_router/encoders/mistral.py
semantic_router/llms/mistral.py
+12
-3
12 additions, 3 deletions
semantic_router/llms/mistral.py
with
16 additions
and
5 deletions
semantic_router/encoders/mistral.py
+
4
−
2
View file @
4a12b4a8
...
...
@@ -25,7 +25,7 @@ class MistralEncoder(BaseEncoder):
if
name
is
None
:
name
=
EncoderDefault
.
MISTRAL
.
value
[
"
embedding_model
"
]
super
().
__init__
(
name
=
name
,
score_threshold
=
score_threshold
)
self
.
_client
,
self
.
_mistralai
=
self
.
_initialize_client
(
mistralai_api_key
)
self
.
_client
,
self
.
_mistralai
=
self
.
_initialize_client
(
mistralai_api_key
)
def
_initialize_client
(
self
,
api_key
):
try
:
...
...
@@ -67,7 +67,9 @@ class MistralEncoder(BaseEncoder):
if
(
not
embeds
or
not
isinstance
(
embeds
,
self
.
_mistralai
.
models
.
embeddings
.
EmbeddingResponse
)
or
not
isinstance
(
embeds
,
self
.
_mistralai
.
models
.
embeddings
.
EmbeddingResponse
)
or
not
embeds
.
data
):
raise
ValueError
(
f
"
No embeddings returned from MistralAI:
{
error_message
}
"
)
...
...
This diff is collapsed.
Click to expand it.
semantic_router/llms/mistral.py
+
12
−
3
View file @
4a12b4a8
...
...
@@ -14,6 +14,7 @@ class MistralAILLM(BaseLLM):
_client
:
Any
=
PrivateAttr
()
temperature
:
Optional
[
float
]
max_tokens
:
Optional
[
int
]
_mistralai
:
Any
=
PrivateAttr
()
def
__init__
(
self
,
...
...
@@ -25,12 +26,13 @@ class MistralAILLM(BaseLLM):
if
name
is
None
:
name
=
EncoderDefault
.
MISTRAL
.
value
[
"
language_model
"
]
super
().
__init__
(
name
=
name
)
self
.
_client
=
self
.
_initialize_client
(
mistralai_api_key
)
self
.
_client
,
self
.
_mistralai
=
self
.
_initialize_client
(
mistralai_api_key
)
self
.
temperature
=
temperature
self
.
max_tokens
=
max_tokens
def
_initialize_client
(
self
,
api_key
):
try
:
import
mistralai
from
mistralai.client
import
MistralClient
except
ImportError
:
raise
ImportError
(
...
...
@@ -47,15 +49,22 @@ class MistralAILLM(BaseLLM):
raise
ValueError
(
f
"
MistralAI API client failed to initialize. Error:
{
e
}
"
)
from
e
return
client
return
client
,
mistralai
def
__call__
(
self
,
messages
:
List
[
Message
])
->
str
:
if
self
.
_client
is
None
:
raise
ValueError
(
"
MistralAI client is not initialized.
"
)
chat_messages
=
[
self
.
_mistralai
.
models
.
chat_completion
.
ChatMessage
(
role
=
m
.
role
,
content
=
m
.
content
)
for
m
in
messages
]
try
:
completion
=
self
.
_client
.
chat
(
model
=
self
.
name
,
messages
=
[
m
.
to_mistral
()
for
m
in
messages
]
,
messages
=
chat_
messages
,
temperature
=
self
.
temperature
,
max_tokens
=
self
.
max_tokens
,
)
...
...
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