[mod] small tavily engine changes
- add include_image_descriptions & include_answer to engine settings - move [ai] prefix in results from title to content content - minor doc fixes
This commit is contained in:
parent
8ab16bb419
commit
1a3ffdb4ea
@ -9,10 +9,10 @@
|
||||
Tavily_ search API (AI engine). This engine implements the REST API
|
||||
(`POST /search`_) and does not make use of the `Tavily Python Wrapper`_.
|
||||
|
||||
From the API response this engine generates *result items* (shown in the main
|
||||
From the API response, this engine generates *result items* (shown in the main
|
||||
result list) and an *answer result* (shown on top of the main result list).
|
||||
If the *answer* from Tavily contains an image, the *answer result* is turned
|
||||
into a *infobox result*.
|
||||
into an *infobox result*.
|
||||
|
||||
.. attention::
|
||||
|
||||
@ -43,7 +43,9 @@ Optional settings are:
|
||||
- :py:obj:`days`
|
||||
- :py:obj:`search_depth`
|
||||
- :py:obj:`max_results`
|
||||
- :py:obj:`include_answer`
|
||||
- :py:obj:`include_images`
|
||||
- :py:obj:`include_image_descriptions`
|
||||
- :py:obj:`include_domains`
|
||||
- :py:obj:`exclude_domains`
|
||||
|
||||
@ -109,10 +111,9 @@ search_depth: str = "basic"
|
||||
"""
|
||||
|
||||
topic: str = ""
|
||||
"""The category of the search. This will determine which of tavily's agents
|
||||
will be used for the search. Currently: only ``general`` and ``news`` are
|
||||
supported and ``general`` will implicitly activate ``include_answer`` in the
|
||||
`POST /search`_ API."""
|
||||
"""The category of the search. This will determine which of Tavily's agents
|
||||
will be used for the search. Currently, only ``general`` and ``news`` are
|
||||
supported."""
|
||||
|
||||
days: int = 3
|
||||
"""The number of days back from the current date to include in the search results.
|
||||
@ -122,16 +123,23 @@ feature is only available when using the ``news`` search topic. Default is 3."""
|
||||
max_results: int = 5
|
||||
"""The maximum number of search results to return. Default is 5."""
|
||||
|
||||
include_answer: bool = True
|
||||
"""Include a short answer to the original query, generated by an LLM based on Tavily's
|
||||
search results."""
|
||||
|
||||
include_images: bool = False
|
||||
"""Include a list of query-related images in the response. Turns answer into
|
||||
infobox with first image (as far there are any images in the response). Will
|
||||
implicitly activate ``include_image_descriptions`` in the `POST /search`_ API
|
||||
(adds descriptive text for each image).
|
||||
"""Include a list of query-related images in the response. Creates an infobox
|
||||
with the first image (as far as there are any images in the response) and the answer,
|
||||
if ``include_answer`` is also enabled.
|
||||
"""
|
||||
|
||||
include_image_descriptions: bool = False
|
||||
"""When ``include_images`` is set to True, this option adds descriptive text for
|
||||
each image."""
|
||||
|
||||
include_domains: list[str] = []
|
||||
"""A list of domains to specifically include in the search results. Default
|
||||
is ``[]```, which includes all domains."""
|
||||
is ``[]``, which includes all domains."""
|
||||
|
||||
exclude_domains: list[str] = []
|
||||
"""A list of domains to specifically exclude from the search results. Default
|
||||
@ -154,13 +162,12 @@ def request(query, params):
|
||||
}
|
||||
|
||||
if include_images:
|
||||
data["include_image_descriptions"] = True
|
||||
data["include_image_descriptions"] = include_image_descriptions
|
||||
|
||||
if topic == "general":
|
||||
data["include_answer"] = True
|
||||
data["include_answer"] = include_answer
|
||||
|
||||
elif topic == "news":
|
||||
data["topic"] = "news"
|
||||
data["days"] = days
|
||||
|
||||
params["url"] = search_url
|
||||
@ -178,33 +185,32 @@ def response(resp):
|
||||
for result in data.get("results", []):
|
||||
results.append(
|
||||
{
|
||||
"title": f"[{gettext('ai')}] {result['title']}",
|
||||
"title": result['title'],
|
||||
"url": result["url"],
|
||||
"content": result["content"],
|
||||
"content": f"[{gettext('ai')}] {result['content']}",
|
||||
"publishedDate": _parse_date(result.get("published_date")),
|
||||
}
|
||||
)
|
||||
|
||||
img_list = data.get("images")
|
||||
if img_list:
|
||||
content = data.get("answer")
|
||||
img_src = img_list[0]
|
||||
if isinstance(img_list[0], dict):
|
||||
img_src = img_list[0]["url"]
|
||||
img_caption = gettext("Image caption") + ": " + img_list[0]["description"]
|
||||
if not content:
|
||||
gettext("Image caption")
|
||||
content = img_caption
|
||||
else:
|
||||
content += "//" + img_caption
|
||||
|
||||
results.append(
|
||||
{
|
||||
result = {
|
||||
"infobox": f"Tavily [{gettext('ai')}]",
|
||||
"img_src": img_src,
|
||||
"content": content,
|
||||
"img_src": img_list[0],
|
||||
}
|
||||
)
|
||||
|
||||
content = data.get("answer")
|
||||
if isinstance(img_list[0], dict):
|
||||
result["img_src"] = img_list[0]["url"]
|
||||
img_caption = f"<i>{gettext('Image caption')}</i>: {img_list[0]['description']}"
|
||||
if not content:
|
||||
result["content"] = img_caption
|
||||
else:
|
||||
result["content"] = f"{content}<br/>{img_caption}"
|
||||
elif content:
|
||||
result["content"] = content
|
||||
|
||||
results.append(result)
|
||||
|
||||
elif data["answer"]:
|
||||
results.append({"answer": data["answer"]})
|
||||
|
Loading…
x
Reference in New Issue
Block a user