You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can seamlessly incorporate several relevant images into the generated article by taking advantage of free services. I experimented with DuckDuckGo search—it’s free and unlimited, and I was impressed with the quality.
code might look like something like this :
class DDGS:
...
def images(self, keywords: str, max_results: int = config.DEFAULT_IMAGE_RESULTS):
vqd = self._get_vqd(keywords)
payload = {
"q": keywords,
"vqd": vqd,
"o": "json",
"f": ",,",
"p": "-2",
"ex": "-2"
}
results = []
try:
for page in range(3):
payload["p"] = str(page + 1)
resp_content = self._get_url("GET", "https://duckduckgo.com/i.js", params=payload)
data = json.loads(resp_content)
for item in data.get("results", []):
results.append({
"title": item.get("title", ""),
"image": item.get("image", ""),
"thumbnail": item.get("thumbnail", ""),
"source": item.get("source", ""),
"height": item.get("height", ""),
"width": item.get("width", "")
})
if len(results) >= max_results:
return results
if not data.get("results"):
break
return results
except Exception as e:
logger.warning(f"Error fetching image results: {str(e)}")
return []
with a prompt like :
"Please choose few images that best illustrate the content of the article. In your final article, insert the chosen images using the format ![caption] (URL) at appropriate locations where they enhance the narrative.\n"
The text was updated successfully, but these errors were encountered:
We can seamlessly incorporate several relevant images into the generated article by taking advantage of free services. I experimented with DuckDuckGo search—it’s free and unlimited, and I was impressed with the quality.
code might look like something like this :
with a prompt like :
The text was updated successfully, but these errors were encountered: