Skip to main content

Использование поиска

string (SearchModel)
Enum: "perplexity/llama-3-sonar-large-32k-online" "perplexity/llama-3.1-sonar-large-128k-online"

Список моделей с поддержкой поиска

"perplexity/llama-3-sonar-large-32k-online"

При использовании API Perplexity есть возможность поиска в интернете по введенному пользователем запросу и списку сайтов (опционально).

В ответе от нейросети Perplexity возвращается список использованных источников.

Справочная информация Perplexity

Как отправить запрос через API

  1. Сгенерировать API_TOKEN
  2. Отправить запрос на https://api.smartbuddy.ru/v1/chat/completions (см. примеры ниже)

Пример запроса на языке Python

  • search_domain_filter: список доменов (опционально). В настоящее время ограничено только 3 доменами для белого и черного списка. Для черного списка добавьте "-" в начало строки домена (в примере -habr.com).
import requests
import json

url = "https://api.smartbuddy.ru/v1/chat/completions"

payload = json.dumps({
"model": "perplexity/llama-3.1-sonar-large-128k-online",
"messages": [
{
"role": "user",
"content": "How many stars are there in our galaxy?"
}
],
"search_domain_filter": [
"perplexity.ai",
"-habr.com"
]
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer API_TOKEN'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Пример ответа

  • citations - ссылки на источники
{
"id": "gen-1735032650-llv396ZnihhwqoAk5aex",
"provider": "Perplexity",
"model": "perplexity/llama-3.1-sonar-large-128k-online",
"object": "chat.completion",
"created": 1735032650,
"choices": [
{
"logprobs": null,
"finish_reason": "stop",
"index": 0,
"message": {
"role": "assistant",
"content": "The estimated number of stars in our galaxy, the Milky Way, is a subject of ongoing research and some variation in estimates. Here are the main points from the sources:\n\n## Estimate Range\n- Astronomers estimate that the Milky Way contains between 100 and 400 billion stars. This range is supported by several sources, including estimates from the European Space Agency and other astronomical studies[3][4][5].\n\n## Specific Estimates\n- Some sources narrow this range to between 200 and 400 billion stars, highlighting the difficulty in achieving a precise count due to the vast number of faint and small stars that are hard to detect[4][5].\n\n## Methodology\n- The estimates are derived from methods such as analyzing the galaxy's mass, the rotation of the galaxy, and the spectrum of the light it emits. The Gaia mission, which has mapped the positions of billions of stars, also contributes to these estimates but still leaves some uncertainties[4].\n\nIn summary, the Milky Way is estimated to have between 100 and 400 billion stars, with some sources suggesting a more specific range of 200 to 400 billion.",
"refusal": ""
}
}
],
"citations": [
"https://www.astronomy.com/science/astro-for-kids-how-many-stars-are-there-in-space/",
"https://www.littlepassports.com/blog/space/how-many-stars-are-in-the-universe/",
"https://www.esa.int/Science_Exploration/Space_Science/Herschel/How_many_stars_are_there_in_the_Universe",
"https://www.space.com/25959-how-many-stars-are-in-the-milky-way.html",
"https://www.youtube.com/watch?v=Py2nZYmvTKg"
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 228,
"total_tokens": 237
}
}