From 6722da15b9d282ce0315ae7016e19d0ef3c4fa26 Mon Sep 17 00:00:00 2001 From: Nikita Ugnich Date: Fri, 24 May 2024 23:38:06 +0300 Subject: [PATCH] Added .gitignore, fixed dependencies installing, added get_models client method, version incremented to 0.3, added suppport for dict data in AIHordeClient._run --- .gitignore | 4 ++ README.md | 24 +++++++++- aihorde/__pycache__/__init__.cpython-311.pyc | Bin 239 -> 0 bytes aihorde/__pycache__/client.cpython-311.pyc | Bin 6100 -> 0 bytes aihorde/__pycache__/models.cpython-311.pyc | Bin 30908 -> 0 bytes aihorde/client.py | 45 ++++++++++++++----- pyproject.toml | 8 ++-- test.py | 7 ++- 8 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 .gitignore delete mode 100644 aihorde/__pycache__/__init__.cpython-311.pyc delete mode 100644 aihorde/__pycache__/client.cpython-311.pyc delete mode 100644 aihorde/__pycache__/models.cpython-311.pyc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..59aa8d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +__pycache__ +*/__pycache__ +build +*.egg_info \ No newline at end of file diff --git a/README.md b/README.md index 4d38108..4a97bbc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,12 @@ # Async Python client library for AI Horde -## Usage examples: -Here you can find some usage examples of library +## Installation: +Warning: supports only Python 3.11 or later +```bash +python3.11 -m pip install aihorde +``` + +## Usage examples ### Image generation ```python @@ -54,3 +59,18 @@ async def text(): asyncio.run(text()) ``` +### Get active models list +```python +import asyncio +from aihorde.client import AIHordeClient +from aihorde import models + +API_KEY = '0000000000' # Your API key from aihorde.net/register. You can also use 0000000000. + +async def models(): + client = AIHordeClient(API_KEY) + active_models: list[models.ActiveModel] = await client.get_models(type='image') # or 'text' + print(repr(active_models)) + +asyncio.run(models()) +``` \ No newline at end of file diff --git a/aihorde/__pycache__/__init__.cpython-311.pyc b/aihorde/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index ed460e5f755425e5d0b1b9b298fd32775e151bf5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 239 zcmZ3^%ge<81dr;h(jR9 z&&bbB)z3*R$SlsSEYUA3PR>tB)i02KczG$)vkyGXcQw57s~>P56p~=j5io0CYUyGcLZNxkN~2KU=qkEVgsrG0AQ^^ Ad;kCd diff --git a/aihorde/__pycache__/client.cpython-311.pyc b/aihorde/__pycache__/client.cpython-311.pyc deleted file mode 100644 index 60a75d535208fcc9e9eeb3d27eeba5e47793fb6c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6100 zcmeGgTWk~A^^WJ^cO0C=P6$b06Ce(041`@+U|~bTBMk&7lwI6PmdQ*K2fy~t1Qz2U zDo|xsQ5#iA(CxOHR$F!vKm0YHsQb}=+L0x!k&uw8O6{K!R6=}IJ!i&admMvM)vEi^ zJ9o~Ud+xdC-nr*>XTEm39R$kD#l6#$E<*l-4Wn>ns88Bx!d`Y5mG?@s8p=mprQUH&{0O!Z!kr`>KEJJ(P%Z=w3 z7+k+ZaLpl$$cPq^U1n=p4P4^x0q+C2^)k(hoWzSf+ydNI(Kc-p?Kk<5U?-wabO6l> zw@b20wmD-y(qRmTcat12!VM#wViWMd9_s~qY;$g-HO+~hn_Q?#Y{prj$5Yd@4tko` zj9v#^UW2PTBS`WBe~ZT7YV@y}tp#}6Dzo_vJ{a8!J^nSLakh4Y%QRaX@OOwd(3oF! zkBlEnQc)U>MWuwII<{9z+CQr(DS2-&7>Ujz%TPj6f{|1-J)F8y9<}%C_JzF$+e}oM zoxdSsGQ!!P=TIHOp%ybWk4=NqN&l`;l3oXHD zDNP1O2+%9CL;{;>nS8|r12&5832!4SG@7DLY*-`FB<_;x*0=eLB%?>DR#`_V+L&rB zJ4%34Ia!KLYl1WZTEC2|-3aB?p5SaUE>$=Ak~{_O279f{CKJ^yH}n?Nw|OW9dmj!* z6Hz4`PWw!HA2R5;5P1Z^by8|3?LAp;(N%2U_@(D_&o^woeX!6z2qgCte|Nz@nD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Ln6SYFCa`-w!6b$<1QcaRdC*!I*A?ou)&$=e41?t)diUtwi45*J!Sm zX%uC>Md1Bl8sGrMv2t;M2CX>X$~O zt;>InxxSCm-XhRWtfX_j6HxQs;|1^WoU6Y6KhV~uhBpUViopv4EcyW5gWw2)_Yv$x zun)n01Ro$cfZ!m2`k3i9`Cq#84SshThp&m3W2*yWk3Px|oG1*O$o19NM)C5!)z0@G zrt_VL3Y~{?ZT0oP5HADFWMDmhk|!c@DI8WE;V}F*n~x#x3Wq~^dy6_CzsN}Kl0>104T8x!xTx=b?vG_*5`<+ r7Rf-)T#LkcUAt;Vb>@hv7D-#qTuZ_!hC$uD{_#xjd+`Pq?Zy5DVY6u* diff --git a/aihorde/__pycache__/models.cpython-311.pyc b/aihorde/__pycache__/models.cpython-311.pyc deleted file mode 100644 index 87c47eba8bf010dde27364eeadf7739e7e84c9f4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 30908 zcmc(I3wRvYb>1#^7K``$4G;tYzCiIMl6sJ$Wl?-c6iG-CDcf4f+AOgHU`1dTnOR7r zO{I{l)=4lSq-oP;*V#7PX_L=wlJ;}I^ea`dU%$9* z+W$XyW@qO?Nb=`?1$Gba+;iv7z2}~L&bjBFJNQa_drJgA*FJk}ZvU}J zaVZr?sYX5eBI;B>zETM(l|ZScO-eOMsb-XF*`!pnlxjt(woOX4NU3&|>e!@ItCZ?Q zsjf{*wMnUNlYQ1Hc^&;Kl@ZFK~wfxGjP^4BU|bZd`Ep z0e61@w^eWt0QX=3HzByAz#R+Vwh8Vb;Eo4ylY;vYa1RG?Q-b?2aE}CV+XZ(5xJLuH z9fCUv+^GO=r{GQlcP4<_CAi0cdpv;KEx5D5JrTf73+^0n=L5Jsg1Z3ROaOO};GP8T zsQ_-T;C=+Srvtcsg1ZRZC4Ik-KMx4*8Q?w=z#SCaM}hlTpw4>*_bhP90Pc|Bo&)ar z0Pe8hJ`UUq0o)P6rGWd<0Pa4)rGdK~z}+vnS>Q4O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_xqn^vqS zHOXaqdZ+C7n~p;g<6YPf8$XL$@IgEb!k%x(qS0tI(y=PP)ky2A{8l5QCGY2U<4BbM z^CBD;AGrDOJA%7YU*cFtwCgs`W%7unGq-N!cg z!Fu0YV{F4dw!ucC4I^xWAFQ8x>pa^q!Zz5*mP8c)SS1KHw71*dVg4N#*%yuCfA$2y z#*w#=zr*}HF0v^a?O|Cz*f{kz+JJnPwUJGY(V^RsAW&tIf5%1k#G>18M}lBodkgJF z{v8+DR_mqPU#3Fo&`N#?f{nu47z^azagk#UY7wlFN%U-9VL-_ z$3=C;qPy8MKltii_G>r$Wuwq9q=KM`mLiu=xA84~(c#;XAlLxUAoq@o+TS0Yyd4RG z_4DsA_l}D?n22s6$M^xCj$HDKjp_?d1DP7d8hj*{|zu--<>kCO5>s!faT^o+34b|2h zeH0Qo9FnNSPzu#b4YiT`f?ypqK<*tEH9i`>_jV)*$fwA?Sd4opoqRBmnCgf%OoX25ERe9!`wR|DDl7iU-l08BLDyZ diff --git a/aihorde/client.py b/aihorde/client.py index 12acdef..1d34a11 100644 --- a/aihorde/client.py +++ b/aihorde/client.py @@ -4,8 +4,7 @@ from aihorde import __version__ as version import time import asyncio -from typing import Optional -from PIL import Image +from typing import Optional, Literal, Union class AIHordeClient: @@ -19,21 +18,22 @@ def __init__( ) -> None: self.api_key = api_key self.base_url = base_url.rstrip("/") - self.session = aiohttp.ClientSession() self.client_agent = client_agent self.version = version async def _run( - self, method: str, path: str, data: Optional[models.AIHordeModel] = None - ) -> dict: - json = data.to_dict() if data is not None else None + self, method: str, path: str, data: Optional[Union[dict, models.AIHordeModel]] = None # data is not AIHordeModel, but idk how i supposed to figure out 'subclass of AIHordeModel' + ) -> Union[list, dict]: + if not isinstance(data, dict): + data = data.to_dict() if data is not None else {} headers = {"apikey": self.api_key} - kwargs = {"json": json} if method.upper() == "POST" else {"params": data} - async with self.session.request( - method, self.base_url + path, headers=headers, **kwargs - ) as response: - resp = await response.json() - return resp + kwargs = {"json": data} if method.upper() == "POST" else {"params": data} + async with aiohttp.ClientSession() as session: + async with session.request( + method, self.base_url + path, headers=headers, **kwargs + ) as response: + resp = await response.json() + return resp async def generate_image_request( self, request: models.GenerationInputStable @@ -86,3 +86,24 @@ async def generate_text( return status.generations else: await asyncio.sleep(int(status.wait_time / 1.5)) + + async def get_models( + self, + type: Optional[Literal['text', 'image']] = 'image', + min_count: Optional[int] = None, + max_count: Optional[int] = None, + model_state: Optional[Literal['known', 'custom', 'all']] = 'all' + ) -> list[models.ActiveModel]: + data = {'type': type, + 'min_count': min_count, + 'max_count': max_count, + 'model_state': model_state} + cleaned = {} + for key, value in data.items(): + if not value is None: + cleaned[key] = value + active_models: list[dict] = await self._run('GET', '/v2/status/models', data=cleaned) + converted = [] + for active_model in active_models: + converted.append(models.ActiveModel.from_dict(active_model)) + return converted diff --git a/pyproject.toml b/pyproject.toml index 672ad20..82deebc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,19 +1,19 @@ [build-system] -requires = ["setuptools>=42", "wheel", "aiohttp", "msgspec"] +requires = ["setuptools>=62", "wheel"] build-backend = "setuptools.build_meta" [project] name = "aihorde" -version = "0.2" +version = "0.3" description = "Python client for AI Horde API" +dependencies = ["aiohttp", "msgspec"] authors = [ - {name = "LapisMYT (Nikita Gavrilin)", email = "nikitagavrilin005@gmail.com"} + {name = "LapisMYT (Nikita Ugnich)", email = "nikitagavrilin005@gmail.com"} ] readme = "README.md" classifiers = ["Development Status :: 4 - Beta", "Framework :: aiohttp", "Intended Audience :: Developers", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", diff --git a/test.py b/test.py index e0033b8..85bcf54 100644 --- a/test.py +++ b/test.py @@ -33,5 +33,10 @@ async def image(): for generation in generations: print(f'{generation.model}: {generation.img}') +async def models(): + client = AIHordeClient(API_KEY) + models = await client.get_models() + print(repr(models[0])) + if __name__ == '__main__': - asyncio.run(text()) \ No newline at end of file + asyncio.run(models()) \ No newline at end of file