The of value of the key response_content from the return dict value of RequestToolresponse.content was returning a byte. decoding it to a str solves the problem
Steps to Reproduce
CreateGradio app using the ResquestTool as Tool
ToolAgent as the Agent
GroqModel as the LLM
Toolkit as the Kit
Use the Jupyter notebook, installing the following:
swarmauri: swamauri.0.4.dev1
python: python==10.14
gradio: gradio==4.44.0
Software Version
Latest (Nightly Build)
Python Version
Python 3.10
Environment Details
Output of pip freeze
absl-py==2.1.0
ai21==2.14.1
ai21-tokenizer==0.12.0
aiofiles==23.2.1
aiohappyeyeballs==2.4.0
aiohttp==3.10.5
aiosignal==1.3.1
altair==5.4.1
annotated-types==0.7.0
annoy==1.17.3
anthropic==0.34.2
anyio==4.4.0
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asgiref==3.7.2
asttokens==2.4.1
astunparse==1.6.3
async-lru==2.0.4
async-timeout==4.0.3
attrs==24.2.0
babel==2.16.0
backoff==2.2.1
bcrypt==4.2.0
beautifulsoup4==4.12.3
bleach==6.1.0
blis==0.7.11
boto3==1.35.17
botocore==1.35.17
branca==0.7.2
bs4==0.0.2
build==1.2.2
CacheControl==0.14.0
cachetools==5.5.0
captcha==0.6.0
catalogue==2.0.10
certifi==2023.7.22
cffi==1.17.1
charset-normalizer==3.3.2
chroma-hnswlib==0.7.6
chromadb==0.5.5
cleo==2.1.0
click==8.1.7
cloudpathlib==0.16.0
cohere==5.9.1
colorama==0.4.6
coloredlogs==15.0.1
comm==0.2.2
confection==0.1.5
contourpy==1.3.0
copier==8.1.0
crashtest==0.4.1
cryptography==43.0.1
cycler==0.12.1
cymem==2.0.8
debugpy==1.8.5
decorator==5.1.1
defusedxml==0.7.1
Deprecated==1.2.14
distlib==0.3.7
distro==1.9.0
Django==3.2.21
dulwich==0.21.7
dunamai==1.18.0
exceptiongroup==1.1.2
executing==2.1.0
fastapi==0.114.1
fastavro==1.9.7
fastjsonschema==2.20.0
ffmpy==0.4.0
filelock==3.12.3
flatbuffers==24.3.25
flet==0.9.0
flet-core==0.9.0
flet-runtime==0.9.0
folium==0.17.0
fonttools==4.53.1
fqdn==1.5.1
frozenlist==1.4.1
fsspec==2024.9.0
funcy==2.0
gast==0.6.0
gensim==4.3.3
google-ai-generativelanguage==0.6.9
google-api-core==2.19.2
google-api-python-client==2.145.0
google-auth==2.34.0
google-auth-httplib2==0.2.0
google-auth-oauthlib==1.2.1
google-generativeai==0.8.0
google-pasta==0.2.0
googleapis-common-protos==1.65.0
gradio==4.44.0
gradio_client==1.3.0
groq==0.11.0
grpcio==1.66.1
grpcio-status==1.62.3
grpcio-tools==1.62.3
h11==0.14.0
h2==4.1.0
h5py==3.11.0
hpack==4.0.0
httpcore==1.0.5
httplib2==0.22.0
httptools==0.6.1
httpx==0.27.2
httpx-sse==0.4.0
huggingface-hub==0.24.7
humanfriendly==10.0
hyperframe==6.0.1
idna==3.4
importlib_metadata==8.4.0
importlib_resources==6.4.5
installer==0.7.0
ipykernel==6.29.5
ipython==8.27.0
ipywidgets==8.1.5
isoduration==20.11.0
jaraco.classes==3.4.0
jedi==0.19.1
jeepney==0.8.0
jellyfish==1.1.0
Jinja2==3.1.2
jinja2-ansible-filters==1.3.2
jiter==0.5.0
jmespath==1.0.1
joblib==1.4.2
json5==0.9.25
jsonpath-python==1.0.6
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
jupyter==1.1.1
jupyter-console==6.6.3
jupyter-events==0.10.0
jupyter-lsp==2.2.5
jupyter_client==8.6.2
jupyter_core==5.7.2
jupyter_server==2.14.2
jupyter_server_terminals==0.5.3
jupyterlab==4.2.5
jupyterlab_pygments==0.3.0
jupyterlab_server==2.27.3
jupyterlab_widgets==3.0.13
keras==3.5.0
keyring==24.3.1
kiwisolver==1.4.7
kubernetes==30.1.0
langcodes==3.4.0
language_data==1.2.0
libclang==18.1.1
llvmlite==0.43.0
marisa-trie==1.2.0
Markdown==3.7
markdown-it-py==3.0.0
MarkupSafe==2.1.3
matplotlib==3.9.2
matplotlib-inline==0.1.7
mdurl==0.1.2
mistralai==1.0.3
mistune==3.0.2
ml-dtypes==0.4.0
mmh3==4.1.0
monotonic==1.6
more-itertools==10.5.0
mpmath==1.3.0
msgpack==1.1.0
multidict==6.1.0
murmurhash==1.0.10
mypy-extensions==1.0.0
namex==0.0.8
narwhals==1.7.0
nbclient==0.10.0
nbconvert==7.16.4
nbformat==5.10.4
nest-asyncio==1.6.0
networkx==3.3
nltk==3.9.1
notebook==7.2.2
notebook_shim==0.2.4
numba==0.60.0
numpy==1.26.4
nvidia-cublas-cu12==12.1.3.1
nvidia-cuda-cupti-cu12==12.1.105
nvidia-cuda-nvrtc-cu12==12.1.105
nvidia-cuda-runtime-cu12==12.1.105
nvidia-cudnn-cu12==9.1.0.70
nvidia-cufft-cu12==11.0.2.54
nvidia-curand-cu12==10.3.2.106
nvidia-cusolver-cu12==11.4.5.107
nvidia-cusparse-cu12==12.1.0.106
nvidia-nccl-cu12==2.20.5
nvidia-nvjitlink-cu12==12.6.68
nvidia-nvtx-cu12==12.1.105
oauthlib==3.2.2
onnxruntime==1.19.2
openai==1.44.1
opentelemetry-api==1.27.0
opentelemetry-exporter-otlp-proto-common==1.27.0
opentelemetry-exporter-otlp-proto-grpc==1.27.0
opentelemetry-instrumentation==0.48b0
opentelemetry-instrumentation-asgi==0.48b0
opentelemetry-instrumentation-fastapi==0.48b0
opentelemetry-proto==1.27.0
opentelemetry-sdk==1.27.0
opentelemetry-semantic-conventions==0.48b0
opentelemetry-util-http==0.48b0
opt-einsum==3.3.0
optree==0.12.1
orjson==3.10.7
overrides==7.7.0
packaging==23.1
pacmap==0.7.3
pandas==2.2.2
pandocfilters==1.5.1
parameterized==0.9.0
parso==0.8.4
pathspec==0.11.2
pbr==5.11.1
pexpect==4.9.0
pillow==10.4.0
pkginfo==1.11.1
platformdirs==3.10.0
plumbum==1.8.2
poetry==1.8.3
poetry-core==1.9.0
poetry-plugin-export==1.8.0
poetry-version-plugin==0.2.1
portalocker==2.10.1
posthog==3.6.5
preshed==3.0.9
prometheus_client==0.20.0
prompt_toolkit==3.0.47
proto-plus==1.24.0
protobuf==4.25.4
psutil==6.0.0
ptyprocess==0.7.0
pure_eval==0.2.3
pyasn1==0.6.1
pyasn1_modules==0.4.1
pycparser==2.22
pydantic==2.8.2
pydantic_core==2.20.1
pydub==0.25.1
PyGithub==2.4.0
Pygments==2.15.1
PyJWT==2.9.0
PyNaCl==1.5.0
pyparsing==3.1.4
pyphen==0.16.0
PyPika==0.48.9
pypng==0.20220715.0
pyproject_hooks==1.1.0
pyreadline3==3.4.3
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-json-logger==2.0.7
python-multipart==0.0.9
pytz==2023.3.post1
PyYAML==6.0.2
pyyaml-include==1.3.1
pyzmq==26.2.0
qdrant-client==1.11.1
qrcode==7.4.2
questionary==1.10.0
rapidfuzz==3.9.7
referencing==0.35.1
regex==2024.9.11
repath==0.9.0
requests==2.31.0
requests-oauthlib==2.0.0
requests-toolbelt==1.0.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rich==13.8.1
rpds-py==0.20.0
rsa==4.9
ruff==0.6.4
s3transfer==0.10.2
safetensors==0.4.5
scikit-learn==1.5.2
scipy==1.10.0
SecretStorage==3.3.3
segtok==1.5.11
semantic-version==2.10.0
Send2Trash==1.8.3
sentencepiece==0.2.0
shellingham==1.5.4
shuttleai==4.7.1
six==1.16.0
smart-open==6.4.0
sniffio==1.3.0
soupsieve==2.6
spacy==3.7.4
spacy-legacy==3.0.12
spacy-loggers==1.0.5
sqlparse==0.4.4
srsly==2.4.8
stack-data==0.6.3
starlette==0.38.5
stevedore==5.1.0
swarmauri==0.4.2.dev1
sympy==1.13.2
tabulate==0.9.0
tenacity==8.5.0
tensorboard==2.17.1
tensorboard-data-server==0.7.2
tensorflow==2.17.0
tensorflow-io-gcs-filesystem==0.37.1
termcolor==2.4.0
terminado==0.18.1
textblob==0.18.0.post0
textstat==0.7.4
tf_keras==2.17.0
thinc==8.2.5
threadpoolctl==3.5.0
tinycss2==1.3.0
tokenizers==0.19.1
tomli==2.0.1
tomlkit==0.12.0
torch==2.4.1
tornado==6.4.1
tqdm==4.66.5
traitlets==5.14.3
transformers==4.44.2
triton==3.0.0
trove-classifiers==2024.7.2
typer==0.12.5
types-aiofiles==23.2.0.20240623
types-python-dateutil==2.9.0.20240906
types-requests==2.32.0.20240907
typing-inspect==0.9.0
typing_extensions==4.12.2
tzdata==2024.1
uri-template==1.3.0
uritemplate==4.1.1
urllib3==2.2.2
uvicorn==0.30.6
uvloop==0.20.0
virtualenv==20.24.5
virtualenv-clone==0.5.7
virtualenvwrapper==4.8.4
wasabi==1.1.3
watchdog==3.0.0
watchfiles==0.24.0
wcwidth==0.2.6
weasel==0.3.4
webcolors==24.8.0
webencodings==0.5.1
websocket-client==1.8.0
websockets==11.0.3
Werkzeug==3.0.4
widgetsnbextension==4.0.13
wrapt==1.16.0
xyzservices==2024.9.0
yake==0.4.8
yarl==1.11.1
zipp==3.20.1
Relevant Logs or Error Output
File "/home/michaeldecent/miniconda3/envs/swarmauri-0.4.dev1/lib/python3.10/site-packages/swarmauri/standard/agents/concrete/ToolAgent.py", line 40, in exec
self.conversation = self.llm.predict(
File "/tmp/ipykernel_529524/3642738221.py", line 72, in predict
content=json.dumps(func_result),
File "/home/michaeldecent/miniconda3/envs/swarmauri-0.4.dev1/lib/python3.10/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/home/michaeldecent/miniconda3/envs/swarmauri-0.4.dev1/lib/python3.10/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/home/michaeldecent/miniconda3/envs/swarmauri-0.4.dev1/lib/python3.10/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/home/michaeldecent/miniconda3/envs/swarmauri-0.4.dev1/lib/python3.10/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable
Additional Context (Optional)
Potential solution for the RequestTool
# Import necessary modules
import requests
from typing import Optional, Dict, Any, Literal, List
from pydantic import BaseModel, Field, Extra
from swarmauri.standard.tools.base.ToolBase import (
ToolBase,
) # Assuming the location of ToolBase import
from swarmauri.standard.tools.concrete.Parameter import Parameter
class RequestsTool(ToolBase):
"""
A tool that leverages the `requests` library to perform HTTP operations.
Attributes:
name (str): The name of the tool.
description (str): A brief description of what the tool does.
"""
name: str = "RequestsTool"
type: Literal["RequestsTool"] = "RequestsTool"
description: Optional[str] = (
"A tool for making HTTP requests using the `requests` library."
)
parameters: List[Parameter] = Field(
default_factory=lambda: [
Parameter(
name="method",
type="string",
description="The HTTP method to use ('get', 'post', 'put', 'delete').",
required=True,
enum=["get", "post", "put", "delete"],
),
Parameter(
name="url",
type="string",
description="The URL for the request.",
required=True,
),
Parameter(
name="params",
type="object",
description="The query parameters to include in the request.",
required=False,
),
Parameter(
name="data",
type="object",
description="The form data to include in the request (used in POST and PUT).",
required=False,
),
Parameter(
name="json",
type="object",
description="The JSON data to include in the request (used in POST and PUT).",
required=False,
),
Parameter(
name="headers",
type="object",
description="Additional headers to include in the request.",
required=False,
),
]
)
def get(
self,
url: str,
params: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, str]] = None,
) -> requests.Response:
"""
Perform an HTTP GET request.
Args:
url (str): The URL to send the GET request to.
params (Optional[Dict[str, Any]]): The query parameters to include in the request.
headers (Optional[Dict[str, str]]): Additional headers to include in the request.
Returns:
requests.Response: The response object from the GET request.
"""
response = requests.get(url, params=params, headers=headers)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
return response
def post(
self,
url: str,
data: Optional[Dict[str, Any]] = None,
json: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, str]] = None,
) -> requests.Response:
"""
Perform an HTTP POST request.
Args:
url (str): The URL to send the POST request to.
data (Optional[Dict[str, Any]]): The form data to include in the request.
json (Optional[Dict[str, Any]]): The JSON data to include in the request.
headers (Optional[Dict[str, str]]): Additional headers to include in the request.
Returns:
requests.Response: The response object from the POST request.
"""
response = requests.post(url, data=data, json=json, headers=headers)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
return response
def put(
self,
url: str,
data: Optional[Dict[str, Any]] = None,
json: Optional[Dict[str, Any]] = None,
headers: Optional[Dict[str, str]] = None,
) -> requests.Response:
"""
Perform an HTTP PUT request.
Args:
url (str): The URL to send the PUT request to.
data (Optional[Dict[str, Any]]): The form data to include in the request.
json (Optional[Dict[str, Any]]): The JSON data to include in the request.
headers (Optional[Dict[str, str]]): Additional headers to include in the request.
Returns:
requests.Response: The response object from the PUT request.
"""
response = requests.put(url, data=data, json=json, headers=headers)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
return response
def delete(
self, url: str, headers: Optional[Dict[str, str]] = None
) -> requests.Response:
"""
Perform an HTTP DELETE request.
Args:
url (str): The URL to send the DELETE request to.
headers (Optional[Dict[str, str]]): Additional headers to include in the request.
Returns:
requests.Response: The response object from the DELETE request.
"""
response = requests.delete(url, headers=headers)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx and 5xx)
return response
def __call__(self, method: str, url: str, **kwargs) -> Dict[str, Any]:
"""
Calls the appropriate HTTP method (GET, POST, PUT, DELETE) based on the method argument.
Args:
method (str): The HTTP method to use ('get', 'post', 'put', 'delete').
url (str): The URL for the request.
**kwargs: Additional keyword arguments passed to the respective method.
Returns:
requests.Response: The response object from the HTTP request.
"""
method = method.lower()
if method == "get":
response = self.get(url, **kwargs)
elif method == "post":
response = self.post(url, **kwargs)
elif method == "put":
response = self.put(url, **kwargs)
elif method == "delete":
response = self.delete(url, **kwargs)
else:
raise ValueError(f"Unsupported HTTP method: {method}")
return {
"response_content": (response.content).decode('utf-8'),
"response_status": response.status_code,
}
Confirmation
[X] I have searched the existing issues for this bug.
[X] I have provided all necessary information to reproduce the bug.
Describe the Bug
The of value of the key
response_content
from the returndict
value ofRequestTool
response.content
was returning a byte. decoding it to astr
solves the problemSteps to Reproduce
Gradio
app using theResquestTool
asTool
ToolAgent
as theAgent
GroqModel
as theLLM
Toolkit
as theKit
Use the Jupyter notebook, installing the following:
swamauri.0.4.dev1
python==10.14
gradio==4.44.0
Software Version
Latest (Nightly Build)
Python Version
Python 3.10
Environment Details
Output of pip freeze
Relevant Logs or Error Output
Additional Context (Optional)
Potential solution for the RequestTool
Confirmation