Chat(Perplexity搜索)
POST
/chat/completions支持模型:
sonar-pro(每次调用最多会搜索3次,最大输出8000)
sonar(每次调用只会搜索1次,最大输出4000)
sonar-reasoning-pro(每次调用最多会搜索3次,最大输出8000)
sonar-reasoning(每次调用只会搜索1次,最大输出4000)
sonar-deep-research(每次调用会搜索很多次,由模型自己决定,最终生成详细的深度调研报告)
r1-1776(不会调用搜索)
官方文档:https://docs.perplexity.ai/api-reference/chat-completions
请求参数
以聊天格式生成聊天完成的消息。
-2.0 和 2.0 之间的数字。正值会根据新标记在文本中的现有频率对其进行惩罚,从而降低模型逐字重复同一行的可能性。 查看有关频率和存在惩罚的更多信息。
聊天完成时生成的最大令牌数。 输入标记和生成标记的总长度受模型上下文长度的限制。
-2.0 和 2.0 之间的数字。正值会根据到目前为止是否出现在文本中来惩罚新标记,从而增加模型谈论新主题的可能性。 查看有关频率和存在惩罚的更多信息。
使用什么采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使输出更加集中和确定。 我们通常建议改变这个或top_p
但不是两者。
一种替代温度采样的方法,称为核采样,其中模型考虑具有 top_p 概率质量的标记的结果。所以 0.1 意味着只考虑构成前 10% 概率质量的标记。 我们通常建议改变这个或temperature
但不是两者。
default:false
default:false
Given a list of domains, limit the citations used by the online model to URLs from the specified domains. Currently limited to only 3 domains for whitelisting and blacklisting. For blacklisting add a - to the beginning of the domain string.
Returns search results within the specified time interval - does not apply to images. Values include month, week, day, hour
{
"model": "sonar",
"messages": [
{
"role": "user",
"content": "明天纽约天气怎么样"
}
]
}
示例代码
返回响应
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}