mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-23 08:54:24 +01:00
Pass Configs to Commands and remove CFG = Config() in the commands/ folder (#4328)
* feat: pass config to call_ai_functions in coimmands * feat: config for read_audio_from_file * feat: file operations cfg NOTE: we replaced the CFG in the command enable with TRUE b/c not sure how to handle this yet * feat: git command conversion * feat: google search * feat: image generation * feat: extract cfg from browser commands * feat: remove cfg from execute code commands * fix: file operation related tests * fix: linting * fix: tests for read_audio * fix: test error * feat: update cassettes * fix: linting * fix: test typechecking * fix: google_search errors if unexpected kw arg is passed * fix: pass config param to google search test * fix: agent commands were broken + cassettes * fix: agent test * feat: cassettes * feat: enable/disable logic for commands * fix: some commands threw errors * feat: fix tests * Add new cassettes * Add new cassettes * ci: trigger ci * Update autogpt/commands/execute_code.py Co-authored-by: Reinier van der Leer <github@pwuts.nl> * fix prompt * fix prompt + rebase * add config remove useless imports * put back CFG just for download file * lint * The signature should be mandatory in the decorator * black isort * fix: remove the CFG * fix: non typed arg * lint: type some args * lint: add types for libraries * Add new cassettes * fix: windows compatibility * fix: add config access to decorator * fix: remove twitter mention * DDGS search works at 3.0.2 version * ci: linting --------- Co-authored-by: Auto-GPT-Bot <github-bot@agpt.co> Co-authored-by: merwanehamadi <merwanehamadi@gmail.com> Co-authored-by: Reinier van der Leer <github@pwuts.nl> Co-authored-by: kinance <kinance@gmail.com>
This commit is contained in:
@@ -66,6 +66,7 @@ def test_sd_webui_negative_prompt(config, workspace, image_size):
|
||||
gen_image = functools.partial(
|
||||
generate_image_with_sd_webui,
|
||||
prompt="astronaut riding a horse",
|
||||
config=config,
|
||||
size=image_size,
|
||||
extra={"seed": 123},
|
||||
)
|
||||
@@ -101,7 +102,7 @@ def generate_and_validate(
|
||||
config.huggingface_image_model = hugging_face_image_model
|
||||
prompt = "astronaut riding a horse"
|
||||
|
||||
image_path = lst(generate_image(prompt, image_size, **kwargs))
|
||||
image_path = lst(generate_image(prompt, config, image_size, **kwargs))
|
||||
assert image_path.exists()
|
||||
with Image.open(image_path) as img:
|
||||
assert img.size == (image_size, image_size)
|
||||
@@ -146,7 +147,7 @@ def test_huggingface_fail_request_with_delay(
|
||||
|
||||
with patch("time.sleep") as mock_sleep:
|
||||
# Verify request fails.
|
||||
result = generate_image(prompt, image_size)
|
||||
result = generate_image(prompt, config, image_size)
|
||||
assert result == "Error creating image."
|
||||
|
||||
# Verify retry was called with delay if delay is in return_text
|
||||
@@ -156,8 +157,7 @@ def test_huggingface_fail_request_with_delay(
|
||||
mock_sleep.assert_not_called()
|
||||
|
||||
|
||||
def test_huggingface_fail_request_with_delay(mocker):
|
||||
config = Config()
|
||||
def test_huggingface_fail_request_with_delay(mocker, config):
|
||||
config.huggingface_api_token = "1"
|
||||
|
||||
# Mock requests.post
|
||||
@@ -172,7 +172,7 @@ def test_huggingface_fail_request_with_delay(mocker):
|
||||
config.image_provider = "huggingface"
|
||||
config.huggingface_image_model = "CompVis/stable-diffusion-v1-4"
|
||||
|
||||
result = generate_image("astronaut riding a horse", 512)
|
||||
result = generate_image("astronaut riding a horse", config, 512)
|
||||
|
||||
assert result == "Error creating image."
|
||||
|
||||
@@ -180,8 +180,7 @@ def test_huggingface_fail_request_with_delay(mocker):
|
||||
mock_sleep.assert_called_with(0)
|
||||
|
||||
|
||||
def test_huggingface_fail_request_no_delay(mocker):
|
||||
config = Config()
|
||||
def test_huggingface_fail_request_no_delay(mocker, config):
|
||||
config.huggingface_api_token = "1"
|
||||
|
||||
# Mock requests.post
|
||||
@@ -198,7 +197,7 @@ def test_huggingface_fail_request_no_delay(mocker):
|
||||
config.image_provider = "huggingface"
|
||||
config.huggingface_image_model = "CompVis/stable-diffusion-v1-4"
|
||||
|
||||
result = generate_image("astronaut riding a horse", 512)
|
||||
result = generate_image("astronaut riding a horse", config, 512)
|
||||
|
||||
assert result == "Error creating image."
|
||||
|
||||
@@ -206,8 +205,7 @@ def test_huggingface_fail_request_no_delay(mocker):
|
||||
mock_sleep.assert_not_called()
|
||||
|
||||
|
||||
def test_huggingface_fail_request_bad_json(mocker):
|
||||
config = Config()
|
||||
def test_huggingface_fail_request_bad_json(mocker, config):
|
||||
config.huggingface_api_token = "1"
|
||||
|
||||
# Mock requests.post
|
||||
@@ -222,7 +220,7 @@ def test_huggingface_fail_request_bad_json(mocker):
|
||||
config.image_provider = "huggingface"
|
||||
config.huggingface_image_model = "CompVis/stable-diffusion-v1-4"
|
||||
|
||||
result = generate_image("astronaut riding a horse", 512)
|
||||
result = generate_image("astronaut riding a horse", config, 512)
|
||||
|
||||
assert result == "Error creating image."
|
||||
|
||||
@@ -230,8 +228,7 @@ def test_huggingface_fail_request_bad_json(mocker):
|
||||
mock_sleep.assert_not_called()
|
||||
|
||||
|
||||
def test_huggingface_fail_request_bad_image(mocker):
|
||||
config = Config()
|
||||
def test_huggingface_fail_request_bad_image(mocker, config):
|
||||
config.huggingface_api_token = "1"
|
||||
|
||||
# Mock requests.post
|
||||
@@ -241,13 +238,12 @@ def test_huggingface_fail_request_bad_image(mocker):
|
||||
config.image_provider = "huggingface"
|
||||
config.huggingface_image_model = "CompVis/stable-diffusion-v1-4"
|
||||
|
||||
result = generate_image("astronaut riding a horse", 512)
|
||||
result = generate_image("astronaut riding a horse", config, 512)
|
||||
|
||||
assert result == "Error creating image."
|
||||
|
||||
|
||||
def test_huggingface_fail_missing_api_token(mocker):
|
||||
config = Config()
|
||||
def test_huggingface_fail_missing_api_token(mocker, config):
|
||||
config.image_provider = "huggingface"
|
||||
config.huggingface_image_model = "CompVis/stable-diffusion-v1-4"
|
||||
|
||||
@@ -256,4 +252,4 @@ def test_huggingface_fail_missing_api_token(mocker):
|
||||
|
||||
# Verify request raises an error.
|
||||
with pytest.raises(ValueError):
|
||||
generate_image("astronaut riding a horse", 512)
|
||||
generate_image("astronaut riding a horse", config, 512)
|
||||
|
||||
Reference in New Issue
Block a user