url_artifact#
Bases: BaseArtifact “)
Attributes#
Name |
Type |
Description |
|---|---|---|
<a href="url_artifact.mdx#griptape.artifacts.url_artifact.UrlArtifact.value" title="value = field(metadata={'serializable': True}) class-attribute instance-attribute (griptape.artifacts.url_artifact.UrlArtifact.value)"><code class="language-python">value</code></a> |
str |
The url.<br/> |
Source Code in griptape/artifacts/url_artifact.py
@define
class UrlArtifact(BaseArtifact):
"""Stores a url.
Attributes:
value: The url.
"""
value: str = field(metadata={"serializable": True})
def to_bytes(self, *, headers: dict | None = None, **kwargs: dict) -> bytes:
"""Fetches the content of the URL and returns it as bytes.
Args:
headers: Optional headers to include in the request.
**kwargs: Additional keyword arguments, not used.
Returns:
bytes: The content of the URL as bytes.
"""
response = requests.get(self.value, headers=headers)
response.raise_for_status()
return response.content
def to_text(self) -> str:
"""Returns the URL as is."""
return self.value
value = field(metadata={'serializable': True})class-attribute instance-attribute
to_bytes(*, headers=None, **kwargs)#
Fetches the content of the URL and returns it as bytes.
Parameters#
Name |
Type |
Description |
Default |
|---|---|---|---|
headers |
dict I None |
Optional headers to include in the request.<br/> |
None |
**kwargs |
dict |
Additional keyword arguments, not used.<br/> |
{} |
Returns#
Name |
Type |
Description |
|---|---|---|
bytes |
bytes |
The content of the URL as bytes.<br/> |
Source Code in griptape/artifacts/url_artifact.py
def to_bytes(self, *, headers: dict | None = None, **kwargs: dict) -> bytes:
"""Fetches the content of the URL and returns it as bytes.
Args:
headers: Optional headers to include in the request.
**kwargs: Additional keyword arguments, not used.
Returns:
bytes: The content of the URL as bytes.
"""
response = requests.get(self.value, headers=headers)
response.raise_for_status()
return response.content
to_text()#
Source Code in griptape/artifacts/url_artifact.py
def to_text(self) -> str:
"""Returns the URL as is."""
return self.value