well that was fucking retarded
This commit is contained in:
parent
9b78aa2ce5
commit
65fbb69733
2 changed files with 22 additions and 20 deletions
17
tools.py
17
tools.py
|
|
@ -33,13 +33,6 @@ SUPPORTED_TEXT_MIMETYPES = [
|
|||
"application/x-yaml",
|
||||
]
|
||||
|
||||
SUPPORTED_IMAGE_DOCUMENT_MIMETYPES = [
|
||||
"application/pdf",
|
||||
"image/png",
|
||||
"image/apng",
|
||||
"image/jpeg"
|
||||
]
|
||||
|
||||
|
||||
async def searxng(query: str) -> list:
|
||||
"""
|
||||
|
|
@ -89,7 +82,7 @@ async def searxng(query: str) -> list:
|
|||
return results
|
||||
|
||||
|
||||
async def open_url(url: str) -> dict | types.Part:
|
||||
async def open_url(url: str) -> dict:
|
||||
"""
|
||||
Opens a URL and returns its full content (if it's HTML, it will be converted to clean Markdown).
|
||||
Use this when a `search` result's content is insufficient or when a user provides a direct URL to analyze.
|
||||
|
|
@ -116,19 +109,13 @@ async def open_url(url: str) -> dict | types.Part:
|
|||
content_type = response.content_type.split(";")[0].strip()
|
||||
content_length = response.content_length or 0
|
||||
|
||||
if content_type not in SUPPORTED_TEXT_MIMETYPES + SUPPORTED_IMAGE_DOCUMENT_MIMETYPES:
|
||||
if content_type not in SUPPORTED_TEXT_MIMETYPES:
|
||||
return {
|
||||
"content_type": content_type,
|
||||
"content_length": content_length,
|
||||
"content": None,
|
||||
}
|
||||
|
||||
if content_type in SUPPORTED_IMAGE_DOCUMENT_MIMETYPES:
|
||||
return types.Part.from_bytes(
|
||||
data=await response.read(),
|
||||
mime_type=content_type
|
||||
)
|
||||
|
||||
if "text/html" in content_type:
|
||||
content = markdownify(await response.text())
|
||||
if len(content) > 262144:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue