Skip to content

Commit

Permalink
feat: support news title and more_info_urls fields (#414)
Browse files Browse the repository at this point in the history
* feat: support news `title` and `more_info_urls` fields

- Incidentally moves the news pieces to a json file
- Also exposes the existing "tags" field via api endpoint
* chore: bump formatter versions
* fix: correct typo in `black` version
* tests: update dummy bridge agent major version
   This was causing the CI to fail as extra images are associated with a bridge agent version greater than 5 (which was the value before).
* tests: other test bridge agent causing fail
* tests: debug the image gen tests
* tests: more image gen debug
* test: tweaks for consistency
* tests: set all fixtures to session scoped
* fix: try/except news.json load

This would be in the off chance the json is malformed.
  • Loading branch information
tazlin authored Jun 5, 2024
1 parent 49b8ff6 commit 89903c2
Show file tree
Hide file tree
Showing 7 changed files with 870 additions and 664 deletions.
7 changes: 7 additions & 0 deletions horde/apis/models/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,13 @@ def __init__(self, api):
example="Information",
description="How critical this piece of news is.",
),
"tags": fields.List(
fields.String(description="Tags for this newspiece."),
),
"title": fields.String(description="The title of this newspiece."),
"more_info_urls": fields.List(
fields.String(description="URLs for more information about this newspiece."),
),
},
)

Expand Down
676 changes: 22 additions & 654 deletions horde/classes/base/news.py

Large diffs are not rendered by default.

825 changes: 825 additions & 0 deletions horde/data/news.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pytest==8.0.2
black==24.2.0
ruff==0.3.1
black==24.4.2
ruff==0.4.2
tox~=4.14.1
horde_sdk>=0.7.29

Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import requests


@pytest.fixture
@pytest.fixture(scope="session")
def CIVERSION() -> str:
return "0.1.1"


@pytest.fixture
@pytest.fixture(scope="session")
def HORDE_URL() -> str:
return "localhost:7001"


@pytest.fixture
@pytest.fixture(scope="session")
def api_key() -> str:
key_file = pathlib.Path(__file__).parent / "apikey.txt"
if key_file.exists():
Expand All @@ -23,7 +23,7 @@ def api_key() -> str:
raise ValueError("No api key file found")


@pytest.fixture(autouse=True)
@pytest.fixture(autouse=True, scope="session")
def increase_kudos(api_key: str, HORDE_URL: str, CIVERSION: str) -> None:
headers = {"apikey": api_key, "Client-Agent": f"aihorde_ci_client:{CIVERSION}:(discord)db0#1625", "user_id": "1"}

Expand Down
11 changes: 8 additions & 3 deletions tests/test_image.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import requests

TEST_MODELS = ["Fustercluck", "AlbedoBase XL (SDXL)"]
Expand Down Expand Up @@ -31,10 +33,12 @@ def test_simple_image_gen(api_key: str, HORDE_URL: str, CIVERSION: str) -> None:
async_results = async_req.json()
req_id = async_results["id"]
# print(async_results)
print(async_results)
pop_dict = {
"name": "CICD Fake Dreamer",
"models": TEST_MODELS,
"bridge_agent": "AI Horde Worker reGen:4.1.0-citests:https://github.com/Haidra-Org/horde-worker-reGen",
"bridge_agent": "AI Horde Worker reGen:8.0.1-citests:https://github.com/Haidra-Org/horde-worker-reGen",
"nsfw": True,
"amount": 10,
"max_pixels": 4194304,
"allow_img2img": True,
Expand All @@ -47,13 +51,14 @@ def test_simple_image_gen(api_key: str, HORDE_URL: str, CIVERSION: str) -> None:
}
pop_req = requests.post(f"{protocol}://{HORDE_URL}/api/v2/generate/pop", json=pop_dict, headers=headers)
try:
print(pop_req.text)
assert pop_req.ok, pop_req.text
except AssertionError as err:
requests.delete(f"{protocol}://{HORDE_URL}/api/v2/generate/status/{req_id}", headers=headers)
print("Request cancelled")
raise err
pop_results = pop_req.json()
# print(json.dumps(pop_results, indent=4))
print(json.dumps(pop_results, indent=4))

job_id = pop_results["id"]
try:
Expand All @@ -75,7 +80,7 @@ def test_simple_image_gen(api_key: str, HORDE_URL: str, CIVERSION: str) -> None:
retrieve_req = requests.get(f"{protocol}://{HORDE_URL}/api/v2/generate/status/{req_id}", headers=headers)
assert retrieve_req.ok, retrieve_req.text
retrieve_results = retrieve_req.json()
# print(json.dumps(retrieve_results,indent=4))
print(json.dumps(retrieve_results, indent=4))
assert len(retrieve_results["generations"]) == 1
gen = retrieve_results["generations"][0]
assert len(gen["gen_metadata"]) == 0
Expand Down
3 changes: 2 additions & 1 deletion tests/test_image_extra_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def test_simple_image_gen(api_key: str, HORDE_URL: str, CIVERSION: str) -> None:
pop_dict = {
"name": "CICD Fake Dreamer",
"models": TEST_MODELS,
"bridge_agent": "AI Horde Worker reGen:5.3.0-citests:https://github.com/Haidra-Org/horde-worker-reGen",
"bridge_agent": "AI Horde Worker reGen:8.0.1-citests:https://github.com/Haidra-Org/horde-worker-reGen",
"nsfw": True,
"amount": 10,
"max_pixels": 4194304,
"allow_img2img": True,
Expand Down

0 comments on commit 89903c2

Please sign in to comment.