Skip to content

Commit

Permalink
Merge pull request #535 from MichaelDecent/0.4.5.dev1
Browse files Browse the repository at this point in the history
fixed an error with OpenRouterModel_unit_test.py
  • Loading branch information
cobycloud authored Sep 25, 2024
2 parents f197401 + 75c2d4d commit 817983b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pkgs/swarmauri/swarmauri/llms/concrete/OpenRouterModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
16 changes: 11 additions & 5 deletions pkgs/swarmauri/tests/unit/llms/OpenRouterModel_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -44,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())
Expand Down Expand Up @@ -78,7 +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
try:
model.predict(conversation=conversation)
prediction = conversation.get_last().content
assert isinstance(prediction, str)
assert "Jeff" in prediction
except Exception as e:
pytest.fail(f"Error: {e}")
# pytest.skip(f"Error: {e}")

0 comments on commit 817983b

Please sign in to comment.