Skip to content
Snippets Groups Projects
Commit b5fa9ede authored by André Pedersen's avatar André Pedersen
Browse files

Linted code

parent 15151696
No related branches found
No related tags found
No related merge requests found
"""This file contains the MistralEncoder class which is used to encode text using MistralAI""" """This file contains the MistralEncoder class which is used to encode text using MistralAI"""
import os import os
from time import sleep from time import sleep
from typing import List, Optional from typing import List, Optional
......
...@@ -66,9 +66,9 @@ class AzureOpenAIEncoder(BaseEncoder): ...@@ -66,9 +66,9 @@ class AzureOpenAIEncoder(BaseEncoder):
try: try:
self.client = openai.AzureOpenAI( self.client = openai.AzureOpenAI(
azure_deployment=str(self.deployment_name) azure_deployment=(
if self.deployment_name str(self.deployment_name) if self.deployment_name else None
else None, ),
api_key=str(self.api_key), api_key=str(self.api_key),
azure_endpoint=str(self.azure_endpoint), azure_endpoint=str(self.azure_endpoint),
api_version=str(self.api_version), api_version=str(self.api_version),
......
...@@ -111,9 +111,9 @@ class LayerConfig: ...@@ -111,9 +111,9 @@ class LayerConfig:
llm_class = getattr(llm_module, llm_data["class"]) llm_class = getattr(llm_module, llm_data["class"])
# Instantiate the LLM class with the provided model name # Instantiate the LLM class with the provided model name
llm = llm_class(name=llm_data["model"]) llm = llm_class(name=llm_data["model"])
route_data[ route_data["llm"] = (
"llm" llm # Reassign the instantiated llm object back to route_data
] = llm # Reassign the instantiated llm object back to route_data )
# Dynamically create the Route object using the remaining route_data # Dynamically create the Route object using the remaining route_data
route = Route(**route_data) route = Route(**route_data)
......
...@@ -8,7 +8,6 @@ from semantic_router.splitters.base import BaseSplitter ...@@ -8,7 +8,6 @@ from semantic_router.splitters.base import BaseSplitter
class ConsecutiveSimSplitter(BaseSplitter): class ConsecutiveSimSplitter(BaseSplitter):
""" """
Called "consecutive sim splitter" because we check the similarities of consecutive document embeddings (compare ith to i+1th document embedding). Called "consecutive sim splitter" because we check the similarities of consecutive document embeddings (compare ith to i+1th document embedding).
""" """
......
...@@ -81,7 +81,11 @@ sparse_encoder.fit(["The quick brown fox", "jumps over the lazy dog", "Hello, wo ...@@ -81,7 +81,11 @@ sparse_encoder.fit(["The quick brown fox", "jumps over the lazy dog", "Hello, wo
class TestHybridRouteLayer: class TestHybridRouteLayer:
def test_initialization(self, openai_encoder, routes): def test_initialization(self, openai_encoder, routes):
route_layer = HybridRouteLayer( route_layer = HybridRouteLayer(
encoder=openai_encoder, sparse_encoder=sparse_encoder, routes=routes, top_k=10, alpha=0.8, encoder=openai_encoder,
sparse_encoder=sparse_encoder,
routes=routes,
top_k=10,
alpha=0.8,
) )
assert route_layer.index is not None and route_layer.categories is not None assert route_layer.index is not None and route_layer.categories is not None
assert openai_encoder.score_threshold == 0.82 assert openai_encoder.score_threshold == 0.82
......
...@@ -47,10 +47,8 @@ def test_cumulative_sim_splitter(): ...@@ -47,10 +47,8 @@ def test_cumulative_sim_splitter():
# Adjust the side_effect to simulate the encoder's behavior for cumulative document comparisons # Adjust the side_effect to simulate the encoder's behavior for cumulative document comparisons
# This simplistic simulation assumes binary embeddings for demonstration purposes # This simplistic simulation assumes binary embeddings for demonstration purposes
# Define a side_effect function for the mock encoder # Define a side_effect function for the mock encoder
mock_encoder.side_effect = ( mock_encoder.side_effect = lambda x: (
lambda x: [[0.5, 0]] [[0.5, 0]] if "doc1" in x or "doc1\ndoc2" in x or "doc2" in x else [[0, 0.5]]
if "doc1" in x or "doc1\ndoc2" in x or "doc2" in x
else [[0, 0.5]]
) )
# Instantiate the CumulativeSimSplitter with the mock encoder # Instantiate the CumulativeSimSplitter with the mock encoder
...@@ -112,8 +110,8 @@ def test_split_by_topic_consecutive_similarity(): ...@@ -112,8 +110,8 @@ def test_split_by_topic_consecutive_similarity():
def test_split_by_topic_cumulative_similarity(): def test_split_by_topic_cumulative_similarity():
mock_encoder = Mock() mock_encoder = Mock()
mock_encoder.side_effect = ( mock_encoder.side_effect = lambda x: (
lambda x: [[0.5, 0]] if "User: What is the latest news?" in x else [[0, 0.5]] [[0.5, 0]] if "User: What is the latest news?" in x else [[0, 0.5]]
) )
messages = [ messages = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment