Skip to content

LittleLicy/Langbot-perplexity-ai-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

使用前注意

Bug?:该插件可能需要打开代理才能使用,不然可能会出现无法访问pplx的问题!

Perplexity现在可以通过One-hub以Openai的方式接入到Langbot,具体可以查看这里

Perplexity-ai-API 这是什么?

一个在互联网进行搜索的插件,Perplexity(以下简称pplx),使用Python API调用,具体方法查看perplexity ai文档

安装方法

对机器人输入指令!plugin get https://github.com/LittleLicy/QchatGPT-perplexity-ai-api.git安装

使用

  • 你需要在config/config.py中填入你的pplx API Key,点击此处注册pplx账号并在这里查看你的API,需要账户里有余额才能获取pplx apikey

  • 默认的模型llama-3.1-sonar-small-128k-online价格为百万token/0.2刀

  • 计费详细请看文档

# config.py
# API_KEY获取:https://www.perplexity.ai/hub/blog/introducing-pplx-api

API_KEY = "<your_pplx_api>"  # 替换为你的实际API密钥
API_URL = "https://api.perplexity.ai/chat/completions"
  • 模型切换:支持多个llama模型,具体查看这里

  • 新增:支持sonar-reasoning等思考模型。

  • 修正:近期的更新,API可以返回搜索来源,具体请看这里,去掉了"return_citations"的参数,现在搜索默认返回引用url。

展示

默认llama-3.1-sonar-small-128k-online模型调用pplx api进行搜索并总结你提问的内容

群聊@机器人#<你要搜索的内容>,或者私聊发送机器人#<你要搜索的内容>,可以在不使用自己的模型下进行pplx搜索。

image image image

PPLX AI网页版效果

https://www.perplexity.ai/

image

API回答参数修改

你可以在main.py修改API回答的参数

#参数参考:https://docs.perplexity.ai/api-reference/chat-completions

async def call_pplx_api(query: str) -> str:
    url = config.API_URL
    payload = {
        "model": "llama-3.1-sonar-small-128k-online",
        "messages": [
            {
                "role": "system",
                "content": "你的回答简洁而精确。"
            },
            {
                "role": "user",
                "content": query
            }
        ],
        "max_tokens": 4000,  # 默认4000
        "temperature": 0.2,
        "top_p": 0.9,
        "search_domain_filter": ["perplexity.ai"],
        "return_images": False, #确定对在线模型的请求是否应返回图像,需要你的API有pplx的测试资格
        "return_related_questions": False, #同上
        "search_recency_filter": "month", #值包括 month、week、day、hour
        "top_k": 0,
        "stream": False, #API文档的流式输出,不推荐使用,除非你的机器人是官方QQ私聊机器人
        "presence_penalty": 0,
        "frequency_penalty": 1
    }

其他

  • 待复现:可能需要开代理才能使用,否则返回500错误

  • API仪表盘

About

Perplexity(简称pplx)互联网搜索功能插件,基于PerplexityAI API调用

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

No releases published

Contributors

Languages