mech-client 0.1.5__tar.gz → 0.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mech_client-0.1.5 → mech_client-0.1.7}/PKG-INFO +3 -1
- mech_client-0.1.7/mech_client/__init__.py +1 -0
- {mech_client-0.1.5 → mech_client-0.1.7}/mech_client/cli.py +11 -0
- {mech_client-0.1.5 → mech_client-0.1.7}/mech_client/interact.py +4 -0
- mech_client-0.1.7/mech_client/to_png.py +61 -0
- {mech_client-0.1.5 → mech_client-0.1.7}/pyproject.toml +2 -1
- {mech_client-0.1.5 → mech_client-0.1.7}/setup.py +1 -1
- mech_client-0.1.5/mech_client/__init__.py +0 -1
- {mech_client-0.1.5 → mech_client-0.1.7}/LICENSE +0 -0
- {mech_client-0.1.5 → mech_client-0.1.7}/README.md +0 -0
- {mech_client-0.1.5 → mech_client-0.1.7}/mech_client/prompt_to_ipfs.py +0 -0
- {mech_client-0.1.5 → mech_client-0.1.7}/mech_client/push_to_ipfs.py +0 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mech-client
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
4
4
|
Summary: Basic client to interact with a mech
|
|
5
|
+
License: Apache-2.0
|
|
5
6
|
Author: David Minarsch
|
|
6
7
|
Author-email: david.minarsch@googlemail.com
|
|
7
8
|
Requires-Python: >=3.10,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
8
10
|
Classifier: Programming Language :: Python :: 3
|
|
9
11
|
Classifier: Programming Language :: Python :: 3.10
|
|
10
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.7"
|
|
@@ -4,6 +4,7 @@ from mech_client import __version__
|
|
|
4
4
|
from mech_client.interact import interact as interact_
|
|
5
5
|
from mech_client.prompt_to_ipfs import main as prompt_to_ipfs_main
|
|
6
6
|
from mech_client.push_to_ipfs import main as push_to_ipfs_main
|
|
7
|
+
from mech_client.to_png import main as to_png_main
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
@click.group(name="mechx") # type: ignore
|
|
@@ -35,9 +36,19 @@ def push_to_ipfs(file_path: str) -> None:
|
|
|
35
36
|
push_to_ipfs_main(file_path=file_path)
|
|
36
37
|
|
|
37
38
|
|
|
39
|
+
@click.command()
|
|
40
|
+
@click.argument("ipfs_hash")
|
|
41
|
+
@click.argument("path")
|
|
42
|
+
@click.argument("request_id")
|
|
43
|
+
def to_png(ipfs_hash: str, path: str, request_id: str) -> None:
|
|
44
|
+
"""Convert a stability AI API's diffusion model output into a PNG format."""
|
|
45
|
+
to_png_main(ipfs_hash, path, request_id)
|
|
46
|
+
|
|
47
|
+
|
|
38
48
|
cli.add_command(interact)
|
|
39
49
|
cli.add_command(prompt_to_ipfs)
|
|
40
50
|
cli.add_command(push_to_ipfs)
|
|
51
|
+
cli.add_command(to_png)
|
|
41
52
|
|
|
42
53
|
|
|
43
54
|
if __name__ == "__main__":
|
|
@@ -72,6 +72,10 @@ def check_for_tools(tool: str) -> Optional[int]:
|
|
|
72
72
|
"openai-text-davinci-003",
|
|
73
73
|
"openai-gpt-3.5-turbo",
|
|
74
74
|
"openai-gpt-4",
|
|
75
|
+
"stabilityai-stable-diffusion-v1-5",
|
|
76
|
+
"stabilityai-stable-diffusion-xl-beta-v2-2-2",
|
|
77
|
+
"stabilityai-stable-diffusion-512-v2-1",
|
|
78
|
+
"stabilityai-stable-diffusion-768-v2-1",
|
|
75
79
|
]
|
|
76
80
|
else None
|
|
77
81
|
)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# ------------------------------------------------------------------------------
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2023 Valory AG
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
# ------------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
"""
|
|
21
|
+
This script facilitates the conversion of a stability AI API's diffusion model output into a PNG format.
|
|
22
|
+
|
|
23
|
+
Usage:
|
|
24
|
+
|
|
25
|
+
python push_to_ipfs.py <ipfs_hash> <path>
|
|
26
|
+
"""
|
|
27
|
+
import json
|
|
28
|
+
import os.path
|
|
29
|
+
from base64 import b64decode
|
|
30
|
+
from tempfile import gettempdir
|
|
31
|
+
|
|
32
|
+
from aea_cli_ipfs.ipfs_utils import IPFSTool
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def to_png(data: dict, path: str) -> None:
|
|
36
|
+
"""Stores a stability AI API's diffusion model output into a PNG formatted file."""
|
|
37
|
+
for i, image in enumerate(data["artifacts"]):
|
|
38
|
+
with open(path, "wb") as f:
|
|
39
|
+
f.write(b64decode(image["base64"]))
|
|
40
|
+
|
|
41
|
+
print(f"Successfully created {path}.")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_from_ipfs(ipfs_hash: str, request_id: str) -> dict:
|
|
45
|
+
"""Get data from IPFS."""
|
|
46
|
+
temp_dir = gettempdir()
|
|
47
|
+
IPFSTool().client.get(cid=ipfs_hash, target=temp_dir)
|
|
48
|
+
stored_data = os.path.join(temp_dir, ipfs_hash)
|
|
49
|
+
|
|
50
|
+
with open(os.path.join(stored_data, request_id)) as f:
|
|
51
|
+
data = json.loads(f.read()).get("result", {})
|
|
52
|
+
|
|
53
|
+
if not isinstance(data, dict):
|
|
54
|
+
raise ValueError("Data do not have the expected format!")
|
|
55
|
+
|
|
56
|
+
return data
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def main(ipfs_hash: str, path: str, request_id: str) -> None:
|
|
60
|
+
data_ = get_from_ipfs(ipfs_hash, request_id)
|
|
61
|
+
to_png(data_, path)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "mech-client"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.7"
|
|
4
4
|
description = "Basic client to interact with a mech"
|
|
5
5
|
authors = ["David Minarsch <david.minarsch@googlemail.com>"]
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
packages = [{include = "mech_client"}]
|
|
8
|
+
license = "Apache-2.0"
|
|
8
9
|
|
|
9
10
|
[tool.poetry.dependencies]
|
|
10
11
|
python = "^3.10"
|
|
@@ -18,7 +18,7 @@ entry_points = \
|
|
|
18
18
|
|
|
19
19
|
setup_kwargs = {
|
|
20
20
|
'name': 'mech-client',
|
|
21
|
-
'version': '0.1.
|
|
21
|
+
'version': '0.1.7',
|
|
22
22
|
'description': 'Basic client to interact with a mech',
|
|
23
23
|
'long_description': '# mech-client\nBasic client to interact with a mech\n\n> **Warning**<br />\n> **This is a hacky alpha version of the client - don\'t rely on it as production software.**\n\n## Installation\n\n```bash\npip install mech-client\n```\n\nThen, set a websocket endpoint for Gnosis RPC like so:\n\n```bash\nexport WEBSOCKET_ENDPOINT=<YOUR ENDPOINT>\n```\n\n## CLI:\n\n```bash\nUsage: mechx [OPTIONS] COMMAND [ARGS]...\n\n Command-line tool for interacting with mechs.\n\nOptions:\n --version Show the version and exit.\n --help Show this message and exit.\n\nCommands:\n interact Interact with a mech specifying a prompt and tool.\n prompt-to-ipfs Upload a prompt and tool to IPFS as metadata.\n push-to-ipfs Upload a file to IPFS.\n ```\n\n## Usage:\n\nFirst, create a private key in file `ethereum_private_key.txt` with this command:\n\n```bash\naea generate-key ethereum\n```\n\nEnsure the private key carries funds on Gnosis Chain.\n\nSecond, run the following command to instruct the mech with `<prompt>` and `<tool>`:\n\n```bash\nmechx interact <prompt> <tool>\n```\n\nExample output:\n```bash\nmechx interact "write a short poem" "openai-text-davinci-003"\nPrompt uploaded: https://gateway.autonolas.tech/ipfs/f01701220ad9e2d5698fbd6c3a4ce61f329590e68a23181772669e543e69decdae316423b\nTransaction sent: https://gnosisscan.io/tx/0xb3a17ef90da6cc7a86e008a3a91bd367d573b406eae53405a4aa981001a5eaf3\nRequest on-chain with id: 15263135923206312300456917202469137903009897852865973093832667165921851537677\nData arrived: https://gateway.autonolas.tech/ipfs/f017012205053a4ae3ef0cf4ed7eff0c2d74dbaf3479fbdeb292472560e7bfaa4cfecfcdc\nData: {\'requestId\': 15263135923206312300456917202469137903009897852865973093832667165921851537677, \'result\': "\\n\\nA sun-filled sky,\\nA soft breeze blowing by,\\nWhere the trees sway in the wind,\\nA peaceful moment I can\'t rewind."}\n```\n\n## Release guide:\n\nFinish edits, bump versions in `pyproject.toml` and `mech_client/__init__.py`, then `poetry lock`, then `rm -rf dist`, then `poetry publish --build --username=<username> --password=<password>`.',
|
|
24
24
|
'author': 'David Minarsch',
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.1.5"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|