Skip to content

Commit

Permalink
Merge pull request #529 from 3rd-Son/testrefactor
Browse files Browse the repository at this point in the history
added skipifs and fixture for all tests requiring env
  • Loading branch information
cobycloud authored Sep 25, 2024
2 parents 26993e9 + 8708245 commit 470e962
Show file tree
Hide file tree
Showing 32 changed files with 586 additions and 919 deletions.
17 changes: 12 additions & 5 deletions pkgs/swarmauri/tests/integration/agents/RagAgent_i9n_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import pytest

from swarmauri.llms.concrete.GroqModel import GroqModel
from swarmauri.llms.concrete.GroqModel import GroqModel as LLM
from swarmauri.conversations.concrete.MaxSystemContextConversation import (
MaxSystemContextConversation,
)
Expand All @@ -11,10 +11,17 @@
from swarmauri.agents.concrete.RagAgent import RagAgent


@pytest.mark.integration
def test_agent_exec():
@pytest.fixture(scope="module")
def groq_model():
API_KEY = os.getenv("GROQ_API_KEY")
llm = GroqModel(api_key=API_KEY)
if not API_KEY:
pytest.skip("Skipping due to environment variable not set")
llm = LLM(api_key=API_KEY)
return llm


@pytest.mark.integration
def test_agent_exec(groq_model):
system_context = SystemMessage(content="Your name is Jeff.")
conversation = MaxSystemContextConversation(
system_context=system_context, max_size=4
Expand All @@ -29,7 +36,7 @@ def test_agent_exec():
vector_store.add_documents(documents)

agent = RagAgent(
llm=llm,
llm=groq_model,
conversation=conversation,
system_context=system_context,
vector_store=vector_store,
Expand Down
27 changes: 13 additions & 14 deletions pkgs/swarmauri/tests/integration/llms/AI21StudioModel_i9n_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
from swarmauri.messages.concrete.SystemMessage import SystemMessage


@pytest.mark.skipif(
not os.getenv("AI21STUDIO_API_KEY"),
reason="Skipping due to environment variable not set",
)
@pytest.mark.acceptance
def test_nonpreamble_system_context():
@pytest.fixture(scope="module")
def ai21studio_model():
API_KEY = os.getenv("AI21STUDIO_API_KEY")
model = LLM(api_key=API_KEY)
if not API_KEY:
pytest.skip("Skipping due to environment variable not set")
llm = LLM(api_key=API_KEY)
return llm


@pytest.mark.acceptance
def test_nonpreamble_system_context(ai21studio_model):
model = ai21studio_model
conversation = Conversation()

# Say hi
Expand All @@ -41,14 +45,9 @@ def test_nonpreamble_system_context():
assert "Jeff" in prediction


@pytest.mark.skipif(
not os.getenv("AI21STUDIO_API_KEY"),
reason="Skipping due to environment variable not set",
)
@pytest.mark.acceptance
def test_multiple_system_contexts():
API_KEY = os.getenv("AI21STUDIO_API_KEY")
model = LLM(api_key=API_KEY)
def test_multiple_system_contexts(ai21studio_model):
model = ai21studio_model
conversation = Conversation()

system_context = 'You only respond with the following phrase, "Jeff"'
Expand Down
27 changes: 13 additions & 14 deletions pkgs/swarmauri/tests/integration/llms/AnthropicModel_i9n_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
from swarmauri.messages.concrete.SystemMessage import SystemMessage


@pytest.mark.skipif(
not os.getenv("ANTHROPIC_API_KEY"),
reason="Skipping due to environment variable not set",
)
@pytest.mark.acceptance
def test_nonpreamble_system_context():
@pytest.fixture(scope="module")
def anthropic_model():
API_KEY = os.getenv("ANTHROPIC_API_KEY")
model = LLM(api_key=API_KEY)
if not API_KEY:
pytest.skip("Skipping due to environment variable not set")
llm = LLM(api_key=API_KEY)
return llm


@pytest.mark.acceptance
def test_nonpreamble_system_context(anthropic_model):
model = anthropic_model
conversation = Conversation()

# Say hi
Expand All @@ -41,14 +45,9 @@ def test_nonpreamble_system_context():
assert "Jeff" in prediction


@pytest.mark.skipif(
not os.getenv("ANTHROPIC_API_KEY"),
reason="Skipping due to environment variable not set",
)
@pytest.mark.acceptance
def test_multiple_system_contexts():
API_KEY = os.getenv("ANTHROPIC_API_KEY")
model = LLM(api_key=API_KEY)
def test_multiple_system_contexts(anthropic_model):
model = anthropic_model
conversation = Conversation()

system_context = 'You only respond with the following phrase, "Jeff"'
Expand Down
27 changes: 13 additions & 14 deletions pkgs/swarmauri/tests/integration/llms/CohereModel_i9n_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
from swarmauri.messages.concrete.SystemMessage import SystemMessage


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("COHERE_API_KEY"),
reason="Skipping due to environment variable not set",
)
def test_nonpreamble_system_context():
@pytest.fixture(scope="module")
def cohere_model():
API_KEY = os.getenv("COHERE_API_KEY")
model = LLM(api_key=API_KEY)
if not API_KEY:
pytest.skip("Skipping due to environment variable not set")
llm = LLM(api_key=API_KEY)
return llm


@pytest.mark.acceptance
def test_nonpreamble_system_context(cohere_model):
model = cohere_model
conversation = Conversation()

# Say hi
Expand All @@ -42,13 +46,8 @@ def test_nonpreamble_system_context():


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("COHERE_API_KEY"),
reason="Skipping due to environment variable not set",
)
def test_multiple_system_contexts():
API_KEY = os.getenv("COHERE_API_KEY")
model = LLM(api_key=API_KEY)
def test_multiple_system_contexts(cohere_model):
model = cohere_model
conversation = Conversation()

system_context = 'You only respond with the following phrase, "Jeff"'
Expand Down
27 changes: 13 additions & 14 deletions pkgs/swarmauri/tests/integration/llms/DeepInfraModel_i9n_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
from swarmauri.messages.concrete.SystemMessage import SystemMessage


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("DEEPINFRA_API_KEY"),
reason="Skipping due to environment variable not set",
)
def test_nonpreamble_system_context():
@pytest.fixture(scope="module")
def deepinfra_model():
API_KEY = os.getenv("DEEPINFRA_API_KEY")
model = LLM(api_key=API_KEY)
if not API_KEY:
pytest.skip("Skipping due to environment variable not set")
llm = LLM(api_key=API_KEY)
return llm


@pytest.mark.acceptance
def test_nonpreamble_system_context(deepinfra_model):
model = deepinfra_model
conversation = Conversation()

# Say hi
Expand All @@ -42,13 +46,8 @@ def test_nonpreamble_system_context():


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("DEEPINFRA_API_KEY"),
reason="Skipping due to environment variable not set",
)
def test_multiple_system_contexts():
API_KEY = os.getenv("DEEPINFRA_API_KEY")
model = LLM(api_key=API_KEY)
def test_multiple_system_contexts(deepinfra_model):
model = deepinfra_model
conversation = Conversation()

system_context = 'You only respond with the following phrase, "Jeff"'
Expand Down
27 changes: 13 additions & 14 deletions pkgs/swarmauri/tests/integration/llms/DeepSeekModel_i9n_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
from swarmauri.messages.concrete.SystemMessage import SystemMessage


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("DEEPSEEK_API_KEY"),
reason="Skipping due to environment variable not set",
)
def test_nonpreamble_system_context():
@pytest.fixture(scope="module")
def deepseek_model():
API_KEY = os.getenv("DEEPSEEK_API_KEY")
model = LLM(api_key=API_KEY)
if not API_KEY:
pytest.skip("Skipping due to environment variable not set")
llm = LLM(api_key=API_KEY)
return llm


@pytest.mark.acceptance
def test_nonpreamble_system_context(deepseek_model):
model = deepseek_model
conversation = Conversation()

# Say hi
Expand All @@ -42,13 +46,8 @@ def test_nonpreamble_system_context():


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("DEEPSEEK_API_KEY"),
reason="Skipping due to environment variable not set",
)
def test_multiple_system_contexts():
API_KEY = os.getenv("DEEPSEEK_API_KEY")
model = LLM(api_key=API_KEY)
def test_multiple_system_contexts(deepseek_model):
model = deepseek_model
conversation = Conversation()

system_context = 'You only respond with the following phrase, "Jeff"'
Expand Down
27 changes: 13 additions & 14 deletions pkgs/swarmauri/tests/integration/llms/GeminiProModel_i9n_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
from swarmauri.messages.concrete.SystemMessage import SystemMessage


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("GEMINI_API_KEY"),
reason="Skipping due to environment variable not set",
)
def test_nonpreamble_system_context():
@pytest.fixture(scope="module")
def gemini_pro_model():
API_KEY = os.getenv("GEMINI_API_KEY")
model = LLM(api_key=API_KEY)
if not API_KEY:
pytest.skip("Skipping due to environment variable not set")
llm = LLM(api_key=API_KEY)
return llm


@pytest.mark.acceptance
def test_nonpreamble_system_context(gemini_pro_model):
model = gemini_pro_model
conversation = Conversation()

# Say hi
Expand All @@ -42,13 +46,8 @@ def test_nonpreamble_system_context():


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("GEMINI_API_KEY"),
reason="Skipping due to environment variable not set",
)
def test_multiple_system_contexts():
API_KEY = os.getenv("GEMINI_API_KEY")
model = LLM(api_key=API_KEY)
def test_multiple_system_contexts(gemini_pro_model):
model = gemini_pro_model
conversation = Conversation()

system_context = 'You only respond with the following phrase, "Jeff"'
Expand Down
25 changes: 13 additions & 12 deletions pkgs/swarmauri/tests/integration/llms/GroqModel_i9n_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
from swarmauri.messages.concrete.SystemMessage import SystemMessage


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("GROQ_API_KEY"), reason="Skipping due to environment variable not set"
)
def test_nonpreamble_system_context():
@pytest.fixture(scope="module")
def groq_model():
API_KEY = os.getenv("GROQ_API_KEY")
model = LLM(api_key=API_KEY)
if not API_KEY:
pytest.skip("Skipping due to environment variable not set")
llm = LLM(api_key=API_KEY)
return llm


@pytest.mark.acceptance
def test_nonpreamble_system_context(groq_model):
model = groq_model
conversation = Conversation()

# Say hi
Expand All @@ -41,12 +46,8 @@ def test_nonpreamble_system_context():


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("GROQ_API_KEY"), reason="Skipping due to environment variable not set"
)
def test_multiple_system_contexts():
API_KEY = os.getenv("GROQ_API_KEY")
model = LLM(api_key=API_KEY)
def test_multiple_system_contexts(groq_model):
model = groq_model
conversation = Conversation()

system_context = 'You only respond with the following phrase, "Jeff"'
Expand Down
27 changes: 13 additions & 14 deletions pkgs/swarmauri/tests/integration/llms/MistralModel_i9n_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
from swarmauri.messages.concrete.SystemMessage import SystemMessage


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("MISTRAL_API_KEY"),
reason="Skipping due to environment variable not set",
)
def test_nonpreamble_system_context():
@pytest.fixture(scope="module")
def mistral_model():
API_KEY = os.getenv("MISTRAL_API_KEY")
model = LLM(api_key=API_KEY)
if not API_KEY:
pytest.skip("Skipping due to environment variable not set")
llm = LLM(api_key=API_KEY)
return llm


@pytest.mark.acceptance
def test_nonpreamble_system_context(mistral_model):
model = mistral_model
conversation = Conversation()

# Say hi
Expand All @@ -42,13 +46,8 @@ def test_nonpreamble_system_context():


@pytest.mark.acceptance
@pytest.mark.skipif(
not os.getenv("MISTRAL_API_KEY"),
reason="Skipping due to environment variable not set",
)
def test_multiple_system_contexts():
API_KEY = os.getenv("MISTRAL_API_KEY")
model = LLM(api_key=API_KEY)
def test_multiple_system_contexts(mistral_model):
model = mistral_model
conversation = Conversation()

system_context = 'You only respond with the following phrase, "Jeff"'
Expand Down
Loading

0 comments on commit 470e962

Please sign in to comment.