Using Perplexity.ai not possible

I was trying to integrate Perplexity.ai in Leo AI. I successfully integrated OpenAI and it worked, but I wanted to move to Perplexity and for now I have no luck:

My configuration:

The error is in Polish and can be translated as: “There was a network issue connecting to Leo; check your connection and try again.​”

Unfortunately it returns an error while trying to use it:

However, I noticed that when I open Leo AI and use it on Settings page of Brave, it works:

I tried using different sites for summarization (Polish and English ones). Zero issues when I use OpenAI API directly.

[edit]

I was thinking about that error and I have a concern why it even says “There was a network issue connecting TO Leo”? Does it mean that Leo sidebar component does not connect directly to the API URL using OpenAI library, but proxies the data with my private API key to some server?

1 Like

I have the same problem :(.

Pretty sure it does NOT proxy anything when you add external services. The connection goes directly to the URL you provided from your browser.

There is a way to debug these things, but it’s quite involved. First close all tabs to stop as much background communication as you can. Then go to brave://net-export/ and chose to include raw bytes. Start recording. Then go do what you need to do to cause the network error. Then stop recording. Then you can use a tool like https://netlog-viewer.appspot.com/#import to view the recorded data and try to figure out what actually goes wrong. Figuring that out took me quite a while because I was going in blind, and honestly I don’t remember by heart how to help you with that last step. Just a few warnings: I do not know the people who maintain that netlog-viewer tool, they are three people from the Chromium project. In theory their tool processes data locally, but who knows, maybe they are lying and it uploads it to some server too. If you use their tool you are choosing to trust them. Do not share the recorded data with anyone else as you have no idea what other personal data may be in there. Only analyze them yourself or get someone you trust 100% will not steal your identity to analyze them for you.

Thank you for your answer, you are a GOAT! I tried all the steps you described and finally figured it out after a while…

So the problem is when you want to summarize the website content, then Brave sends it like this:

{
    "model": "sonar",
    "messages": [
        {"role": "user", "content": "Here is the website's content"},
        {"role": "user", "content": "Summarize this site"}
    ]
}

This is basically correct when you consider OpenAI’s standard. However Perplexity requires roles to be defined alternately (user > assistant > user > assistant).

And that’s why Perplexity is working when I use Leo AI when Settings page is open (no page content is sent, just the prompt I write).

Here’s the error found using Netlog Viewer:

Error JSON:

{
  "error":{
    "message":"After the (optional) system message(s), user and assistant roles should be alternating.",
    "type":"invalid_message",
    "code":400
  }
}

So to make it work Brave would have to send it concatenated like:

{
    "model": "sonar",
    "messages": [{"role": "user", "content": "Here is the website's content \n\n Summarize this site"}}]
}

I tried to reproduce that to double confirm using Postman:

I’m not sure where to post that bug. In fact Open AI standard lets you send as many user role messages in a row as you want, but there are many APIs (I asked Chat GPT) that use this more restricted rules. That’s why I think despite it is not a bug, it should be possible to check an option like “Concatenate as one message” per custom model to make Leo AI more flexible to use. I don’t think that Perplexity changes anything in their API, but I will also try to reach them.

1 Like