Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请求perplexity api 支持 #743

Open
5 tasks
ixxmu opened this issue Nov 24, 2023 · 15 comments
Open
5 tasks

请求perplexity api 支持 #743

ixxmu opened this issue Nov 24, 2023 · 15 comments
Labels
enhancement New feature or request

Comments

@ixxmu
Copy link

ixxmu commented Nov 24, 2023

例行检查

  • 我已确认目前没有类似 issue
  • 我已确认我已升级到最新版本
  • 我已完整查看过项目 README,已确定现有版本无法满足需求
  • 我理解并愿意跟进此 issue,协助测试和提供反馈
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

功能描述
perplexity 也是有api的,在自定义模型中没有添加成功

应用场景
模型列表如下
codellama-34b-instruct | 16384 | Chat Completion
llama-2-70b-chat | 4096 | Chat Completion
mistral-7b-instruct | 4096 [1] | Chat Completion
openhermes-2-mistral-7b | 4096 [1] | Chat Completion
openhermes-2.5-mistral-7b | 4096 [1] | Chat Completion
pplx-7b-chat-alpha | 4096 | Chat Completion
pplx-70b-chat-alpha | 4096 | Chat Completion

@ixxmu ixxmu added the enhancement New feature or request label Nov 24, 2023
@lijie97
Copy link

lijie97 commented Jan 9, 2024

+1

@Fried-dumplings
Copy link

球球牛逼的大佬支持一下,很需要这个功能

@codeenxi
Copy link

codeenxi commented Feb 6, 2024

the same issue, need help~

@LiaoSW
Copy link

LiaoSW commented Mar 18, 2024

确实很有需求,希望增加支持~

@Riofd
Copy link

Riofd commented Mar 27, 2024

+1

@songquanpeng
Copy link
Owner

这个格式看上去就是 OpenAI 的格式哦,使用自定义渠道功能不可以么?

@Riofd
Copy link

Riofd commented Apr 7, 2024

这个格式看上去就是 OpenAI 的格式哦,使用自定义渠道功能不可以么?

实测了一下使用自定义渠道确实不可以,但是官方的调用规则跟openai是一致的,添加自定义渠道后进行渠道测试,报错代码404

@lijie97
Copy link

lijie97 commented Apr 7, 2024

image
body 实测起来应该是没有问题的, 但是url上比起 openai 少了一个v1

@voctot
Copy link

voctot commented Apr 20, 2024

+1

@songquanpeng
Copy link
Owner

songquanpeng commented Apr 21, 2024

本周末忘记这回事情了,如果只是path不一致请求体和响应体格式兼容的话,那会比较好处理,得等到下次有空了或者pr

@orienthong0304
Copy link

什么时候支持呀大佬

@ShaySheng
Copy link

+1,希望能支持。这个太需要了。

@hostage007
Copy link

image body 实测起来应该是没有问题的, 但是url上比起 openai 少了一个v1

确实,就差这一个v1,没法用自定义endpoint

@haso2007
Copy link

佬,到现在还有没有适配吗。最新版本还是没找到对应的方法

@BaksiLi
Copy link
Contributor

BaksiLi commented Dec 29, 2024

Temporary Workaround

一个临时的解决方案,供后来者参考。

Cloudflare AI Gateway 同样 支持 Perplexity,渠道选择 OpenAI,然后填入代理地址就可以规避 URL 里没有 /v1/ 的问题。换句话说,由第三方 Gateway 解决了 OpenAI API Compatible 转换的问题。

API Implementation

至于实现 Perplexity API,有以下需要考虑的问题:

  • URL 格式不同(/v1/
  • Perplexity 的计费模型不单纯是基于 token,也考虑了 request 次数。具体参见 Price based on requests times #2007
  • 返回的 JSON 里有一个 citations 列表,这个渲染需要聊天前端的支持,如下(官方例):
{
  "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "model": "llama-3.1-sonar-small-128k-online",
  "object": "chat.completion",
  "created": 1724369245,
  "citations": [
    "https://www.astronomy.com/science/astro-for-kids-how-many-stars-are-there-in-space/",
    "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.space.com/26078-how-many-stars-are-there.html",
    "https://en.wikipedia.org/wiki/Milky_Way",
    "https://www.littlepassports.com/blog/space/how-many-stars-are-in-the-universe/?srsltid=AfmBOoqWVymRloolU4KZBI9-LotDIoTnzhKYKCw7vVkaIifhjrEU66_5"
  ],
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {
        "role": "assistant",
        "content": "The number of stars in the Milky Way galaxy is estimated to be between 100 billion and 400 billion stars. The most recent estimates from the Gaia mission suggest that there are approximately 100 to 400 billion stars in the Milky Way, with significant uncertainties remaining due to the difficulty in detecting faint red dwarfs and brown dwarfs."
      },
      "delta": {
        "role": "assistant",
        "content": ""
      }
    }
  ],
  "usage": {
    "prompt_tokens": 14,
    "completion_tokens": 70,
    "total_tokens": 84
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests