[mod] tavily engine: revert double punctuation & remove f-stringed gettexts

This commit is contained in:
GenericMale 2025-01-23 11:02:44 +01:00
parent 1a3ffdb4ea
commit e4e6f21494

View File

@ -6,7 +6,7 @@
Before reporting an issue with this engine, Before reporting an issue with this engine,
please consult `API error codes`_. please consult `API error codes`_.
Tavily_ search API (AI engine). This engine implements the REST API Tavily_ search API (AI engine). This engine implements the REST API
(`POST /search`_) and does not make use of the `Tavily Python Wrapper`_. (`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
@ -17,7 +17,7 @@ into an *infobox result*.
.. attention:: .. attention::
AI queries take considerably longer to process than queries to conventional AI queries take considerably longer to process than queries to conventional
search engines. The ``timeout`` should therefore also be set considerably search engines. The ``timeout`` should therefore also be set considerably
higher, but it is not recommended to activate AI queries by default higher, but it is not recommended to activate AI queries by default
(set ``disabled: true``), as otherwise all user searches will have to wait (set ``disabled: true``), as otherwise all user searches will have to wait
for the AI. for the AI.
@ -93,7 +93,7 @@ about = {
"official_api_documentation": "https://docs.tavily.com/docs/rest-api/api-reference", "official_api_documentation": "https://docs.tavily.com/docs/rest-api/api-reference",
"use_official_api": True, "use_official_api": True,
"require_api_key": True, "require_api_key": True,
"results": 'JSON', "results": "JSON",
} }
search_url = "https://api.tavily.com/search" search_url = "https://api.tavily.com/search"
@ -104,31 +104,31 @@ api_key: str = "unset"
"""Tavily API Key (`Getting started`_).""" """Tavily API Key (`Getting started`_)."""
search_depth: str = "basic" search_depth: str = "basic"
"""The depth of the search. It can be ``basic`` or ``advanced``. Default is """The depth of the search. It can be ``basic`` or ``advanced``. Default is
``basic`` unless specified otherwise in a given method. ``basic`` unless specified otherwise in a given method.
- have an eye on your `Tavily API Credit Deduction`_! - have an eye on your `Tavily API Credit Deduction`_!
""" """
topic: str = "" topic: str = ""
"""The category of the search. This will determine which of Tavily's agents """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 will be used for the search. Currently, only ``general`` and ``news`` are
supported.""" supported."""
days: int = 3 days: int = 3
"""The number of days back from the current date to include in the search results. """The number of days back from the current date to include in the search results.
This specifies the time frame of data to be retrieved. Please note that this This specifies the time frame of data to be retrieved. Please note that this
feature is only available when using the ``news`` search topic. Default is 3.""" feature is only available when using the ``news`` search topic. Default is 3."""
max_results: int = 5 max_results: int = 5
"""The maximum number of search results to return. Default is 5.""" """The maximum number of search results to return. Default is 5."""
include_answer: bool = True include_answer: bool = True
"""Include a short answer to the original query, generated by an LLM based on Tavily's """Include a short answer to the original query, generated by an LLM based on Tavily's
search results.""" search results."""
include_images: bool = False include_images: bool = False
"""Include a list of query-related images in the response. Creates an infobox """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, with the first image (as far as there are any images in the response) and the answer,
if ``include_answer`` is also enabled. if ``include_answer`` is also enabled.
""" """
@ -185,9 +185,9 @@ def response(resp):
for result in data.get("results", []): for result in data.get("results", []):
results.append( results.append(
{ {
"title": result['title'], "title": result["title"],
"url": result["url"], "url": result["url"],
"content": f"[{gettext('ai')}] {result['content']}", "content": "[" + gettext("ai") + "] " + result["content"],
"publishedDate": _parse_date(result.get("published_date")), "publishedDate": _parse_date(result.get("published_date")),
} }
) )
@ -195,18 +195,18 @@ def response(resp):
img_list = data.get("images") img_list = data.get("images")
if img_list: if img_list:
result = { result = {
"infobox": f"Tavily [{gettext('ai')}]", "infobox": "Tavily [" + gettext("ai") + "]",
"img_src": img_list[0], "img_src": img_list[0],
} }
content = data.get("answer") content = data.get("answer")
if isinstance(img_list[0], dict): if isinstance(img_list[0], dict):
result["img_src"] = img_list[0]["url"] result["img_src"] = img_list[0]["url"]
img_caption = f"<i>{gettext('Image caption')}</i>: {img_list[0]['description']}" img_caption = gettext("Image caption") + ": " + img_list[0]["description"]
if not content: if not content:
result["content"] = img_caption result["content"] = img_caption
else: else:
result["content"] = f"{content}<br/>{img_caption}" result["content"] = content + "//" + img_caption
elif content: elif content:
result["content"] = content result["content"] = content