Skip to content

Commit

Permalink
Update test_llm_unify.py
Browse files Browse the repository at this point in the history
delete some unnecessary parts of the code.
  • Loading branch information
Yara97Mansour authored Aug 28, 2024
1 parent bb8f7d3 commit c53db87
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions tests/unit/llms/test_llm_unify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

from semantic_router.llms.unify import UnifyLLM
from semantic_router.schema import Message
from unify.clients import Unify, AsyncUnify
from unittest.mock import patch

from unify.clients import Unify, AsyncUnify
from unify.exceptions import UnifyError
# from dotenv import load_dotenv

# load_dotenv()

@pytest.fixture
def unify_llm(mocker):
mocker.patch("unify.clients.Unify")
mocker.patch("json.loads", return_value=["llama-3-8b-chat@together-ai"])
# mocker.patch("json.loads", return_value=["llama-3-8b-chat@together-ai"])
mocker.patch.object(Unify, "set_endpoint", return_value=None)
mocker.patch.object(AsyncUnify, "set_endpoint", return_value=None)

Expand All @@ -22,15 +18,14 @@ def unify_llm(mocker):

class TestUnifyLLM:

def test_unify_llm_init_success_1(self, unify_llm, mocker):
mocker.patch("os.getenv", return_value="fake-api-key")
mocker.patch.object(unify_llm.client, "set_endpoint", return_value=None)
# def test_unify_llm_init_success_1(self, unify_llm, mocker):
# mocker.patch("os.getenv", return_value="fake-api-key")
# mocker.patch.object(unify_llm.client, "set_endpoint", return_value=None)

assert unify_llm.client is not None
# assert unify_llm.client is not None

def test_unify_llm_init_success_2(self, unify_llm, mocker):
mocker.patch("os.getenv", return_value="fake-api-key")

# mocker.patch("os.getenv", return_value="fake-api-key")
assert unify_llm.name == "llama-3-8b-chat@together-ai"
assert unify_llm.temperature == 0.01
assert unify_llm.max_tokens == 200
Expand Down Expand Up @@ -61,10 +56,8 @@ def test_unify_llm_error_handling(self, unify_llm, mocker):


def test_unify_llm_call_success(self, unify_llm, mocker):

# mock_response = mocker.MagicMock()
# mock_response.choices[0].message.content = {"message": {"content": "test response"}}
mock_response = "test response" # unify currently outputs strings in generate, not completions

mock_response = "test response"
mocker.patch.object(unify_llm.client, "generate", return_value=mock_response)

output = unify_llm([Message(role="user", content="test")])
Expand Down

0 comments on commit c53db87

Please sign in to comment.