Skip to content

Commit

Permalink
test: reset default model in openai tests to fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Dec 21, 2024
1 parent 5076376 commit 7ff8492
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions gptme/llm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def get_default_model() -> ModelMeta | None:
return DEFAULT_MODEL


def set_default_model(model: str) -> None:
modelmeta = get_model(model)
def set_default_model(model: str | ModelMeta) -> None:
modelmeta = model if isinstance(model, ModelMeta) else get_model(model)
assert modelmeta
global DEFAULT_MODEL
DEFAULT_MODEL = modelmeta
Expand Down
11 changes: 10 additions & 1 deletion tests/test_llm_openai.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import pytest
from gptme.llm.llm_openai import _prepare_messages_for_api
from gptme.llm.models import set_default_model
from gptme.llm.models import get_default_model, set_default_model
from gptme.message import Message
from gptme.tools import get_tool, init_tools


@pytest.fixture(autouse=True)
def reset_default_model():
default_model = get_default_model()
assert default_model
yield
set_default_model(default_model)


def test_message_conversion():
messages = [
Message(role="system", content="Initial Message", pinned=True, hide=True),
Expand Down

0 comments on commit 7ff8492

Please sign in to comment.