Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create information retrieval challenge a #3770

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/integration/agent_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,37 @@ def memory_management_agent(
)

return agent


@pytest.fixture
def get_company_revenue_agent(
agent_test_config, memory_local_cache, workspace: Workspace
):
command_registry = CommandRegistry()
command_registry.import_commands("autogpt.commands.file_operations")
command_registry.import_commands("autogpt.app")

ai_config = AIConfig(
ai_name="Get-CompanyRevenue",
ai_role="an autonomous agent that specializes in finding the reported revenue of a company.",
ai_goals=[
"Write the revenue of Tesla in 2022 to a file. You should write the number without commas and you should not use signs like B for billion and M for million.",
],
)
ai_config.command_registry = command_registry

system_prompt = ai_config.construct_full_prompt()
Config().set_continuous_mode(False)
agent = Agent(
ai_name="Get-CompanyRevenue",
memory=memory_local_cache,
full_message_history=[],
command_registry=command_registry,
config=ai_config,
next_action_count=0,
system_prompt=system_prompt,
triggering_prompt=DEFAULT_TRIGGERING_PROMPT,
workspace_directory=workspace.root,
)

return agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import contextlib
from functools import wraps
from typing import Generator

import pytest

from autogpt.commands.file_operations import read_file, write_to_file
from tests.integration.agent_utils import run_interaction_loop
from tests.integration.challenges.utils import run_multiple_times
from tests.utils import requires_api_key


def input_generator(input_sequence: list) -> Generator[str, None, None]:
"""
Creates a generator that yields input strings from the given sequence.

:param input_sequence: A list of input strings.
:return: A generator that yields input strings.
"""
yield from input_sequence


# @pytest.skip("Nobody beat this challenge yet")
@pytest.mark.skip("This challenge hasn't been beaten yet.")
@pytest.mark.vcr
@requires_api_key("OPENAI_API_KEY")
@run_multiple_times(3)
def test_information_retrieval_challenge_a(
get_company_revenue_agent, monkeypatch
) -> None:
"""
Test the challenge_a function in a given agent by mocking user inputs and checking the output file content.

:param get_company_revenue_agent: The agent to test.
:param monkeypatch: pytest's monkeypatch utility for modifying builtins.
"""
input_sequence = ["s", "s", "s", "s", "s", "EXIT"]
gen = input_generator(input_sequence)
monkeypatch.setattr("builtins.input", lambda _: next(gen))

with contextlib.suppress(SystemExit):
run_interaction_loop(get_company_revenue_agent, None)

file_path = str(get_company_revenue_agent.workspace.get_path("output.txt"))
content = read_file(file_path)
assert "81" in content, "Expected the file to contain 81"
Loading