From 000b2d928c89910337a6c4e0df5289212a472ebc Mon Sep 17 00:00:00 2001 From: michaeldecent2 <111002205+MichaelDecent@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:10:48 +0100 Subject: [PATCH 1/3] fixed an error with OpenRouterModel_unit_test.py --- pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py b/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py index 159b79302..ad77182a0 100644 --- a/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py +++ b/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py @@ -20,6 +20,8 @@ def openrouter_model(): def get_allowed_models(): + if not API_KEY: + return [] llm = LLM(api_key=API_KEY) return llm.allowed_models From a4b3d6045ec9f28aa71d7a2a696a03c31671e190 Mon Sep 17 00:00:00 2001 From: michaeldecent2 <111002205+MichaelDecent@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:25:14 +0100 Subject: [PATCH 2/3] fixed an error with OpenRouterModel_unit_test.py --- .../llms/concrete/OpenRouterModel.py | 2 ++ .../unit/llms/OpenRouterModel_unit_test.py | 26 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pkgs/swarmauri/swarmauri/llms/concrete/OpenRouterModel.py b/pkgs/swarmauri/swarmauri/llms/concrete/OpenRouterModel.py index eb3840d76..64064e538 100644 --- a/pkgs/swarmauri/swarmauri/llms/concrete/OpenRouterModel.py +++ b/pkgs/swarmauri/swarmauri/llms/concrete/OpenRouterModel.py @@ -357,6 +357,8 @@ def predict( else: response = requests.post(url, json=payload, headers=headers) response_json = json.loads(response.text) + if "error" in response_json: + raise ValueError(response_json["error"]) print(response_json) message_content = response_json["choices"][0]["message"]["content"] conversation.add_message(AgentMessage(content=message_content)) diff --git a/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py b/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py index ad77182a0..388eb958e 100644 --- a/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py +++ b/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py @@ -46,7 +46,7 @@ def test_serialization(openrouter_model): @pytest.mark.unit def test_default_name(openrouter_model): - assert openrouter_model.name == "mistralai/pixtral-12b:free" + assert openrouter_model.name == "01-ai/yi-34b" @pytest.mark.parametrize("model_name", get_allowed_models()) @@ -84,3 +84,27 @@ def test_preamble_system_context(openrouter_model, model_name): prediction = conversation.get_last().content assert type(prediction) == str assert "Jeff" in prediction + + +@pytest.mark.unit +def test_preamble_system_context_default_model(openrouter_model): + model = openrouter_model + model.name = "01-ai/yi-34b" + conversation = Conversation() + + system_context = 'You only respond with the following phrase, "Jeff"' + human_message = SystemMessage(content=system_context) + conversation.add_message(human_message) + + input_data = "Hi" + human_message = HumanMessage(content=input_data) + conversation.add_message(human_message) + try: + model.predict(conversation=conversation) + prediction = conversation.get_last().content + assert isinstance(prediction, str) + assert "Jeff" in prediction + assert model.name == "01-ai/yi-34b" + except Exception as e: + pytest.fail(f"Error: {e}") + # pytest.skip(f"Error: {e}") From 75c2d4d0615ab0fac1896ce24733b9a8aa1371a0 Mon Sep 17 00:00:00 2001 From: michaeldecent2 <111002205+MichaelDecent@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:28:41 +0100 Subject: [PATCH 3/3] fixed an error with OpenRouterModel_unit_test.py final --- .../unit/llms/OpenRouterModel_unit_test.py | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py b/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py index 388eb958e..b3b1c51bf 100644 --- a/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py +++ b/pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py @@ -80,31 +80,11 @@ def test_preamble_system_context(openrouter_model, model_name): human_message = HumanMessage(content=input_data) conversation.add_message(human_message) - model.predict(conversation=conversation) - prediction = conversation.get_last().content - assert type(prediction) == str - assert "Jeff" in prediction - - -@pytest.mark.unit -def test_preamble_system_context_default_model(openrouter_model): - model = openrouter_model - model.name = "01-ai/yi-34b" - conversation = Conversation() - - system_context = 'You only respond with the following phrase, "Jeff"' - human_message = SystemMessage(content=system_context) - conversation.add_message(human_message) - - input_data = "Hi" - human_message = HumanMessage(content=input_data) - conversation.add_message(human_message) try: model.predict(conversation=conversation) prediction = conversation.get_last().content assert isinstance(prediction, str) assert "Jeff" in prediction - assert model.name == "01-ai/yi-34b" except Exception as e: pytest.fail(f"Error: {e}") # pytest.skip(f"Error: {e}")