nathanrchn / perplexityai

A python api to use perplexity.ai
233 stars 60 forks source link

Empty result #33

Open ArtDoctor opened 1 year ago

ArtDoctor commented 1 year ago

Recently perplexity API started returning empty results. The strangest part is that it doesn't always do it, but it just randomly sometimes returns nothing. Here is my code:

from perplexity import Perplexity
def send_query_perp(query: str) -> Tuple[str, List[str]]:
    perplexity = Perplexity()
    perp_answer = perplexity.search(query)
    perp_answer_dicts = []
    sources = []
    for i in perp_answer:
        perp_answer_dicts.append(i)
    perplexity.close()
    try:
        print("web results: ", perp_answer_dicts[-1])
    except Exception as e:
        print("exc: ", e)
        print("web results: ", perp_answer_dicts)
    for source in perp_answer_dicts[-1]["web_results"]:
        sources.append(source['url'])
    return perp_answer_dicts[-1]["answer"], sources

Result (sometimes): exc: list index out of range web results: []

Could anyone please point out if I did something wrong, or it's an actual issue?

gmkung commented 1 year ago

Oh I just realised you have similar issues too. Since 2-3 weeks I have unreadable responses when I deploy on Heroku and I raised this in issue #34 . @nathanrchn is this something you know about?

ArtDoctor commented 1 year ago

Yes, it's pretty sad that it doesn't work. You could post this issue here too, maybe that author will be more approachable.

LexiestLeszek commented 11 months ago

any ideas on how to fix? I have exactly this error with Vercel/Render

ArtDoctor commented 11 months ago

You don't need to use this library any more - perplexity officially released their API with mistral and llama endpoint, so you can use it instead. They are much more stable than this library.

LexiestLeszek commented 11 months ago

You don't need to use this library any more - perplexity officially released their API with mistral and llama endpoint, so you can use it instead. They are much more stable than this library.

But their models don't search in web

ArtDoctor commented 11 months ago

You can see here https://docs.perplexity.ai/docs/model-cards they have pplx-7b-online and pplx-70b-online, they are online meaning they do search in web.

LexiestLeszek commented 11 months ago

You can see here https://docs.perplexity.ai/docs/model-cards they have pplx-7b-online and pplx-70b-online, they are online meaning they do search in web.

They don't work in web, there are even reddit threads about it.

ArtDoctor commented 11 months ago

I am sorry then, I didn't know about it. So far I've been using it and it always gave up-to-date information. I just ran a query with its API and asked about Mixtral (was released a few days ago), it gave fully correct answer. Could you please share the threads where this topic is discussed?

LexiestLeszek commented 11 months ago

I am sorry then, I didn't know about it. So far I've been using it and it always gave up-to-date information. I just ran a query with its API and asked about Mixtral (was released a few days ago), it gave fully correct answer. Could you please share the threads where this topic is discussed?

Oh, really? I didn't know that, I only read threads, sorry. Can you please share a python code for API calling?

ArtDoctor commented 11 months ago

Sure, here you go:

import requests

pplx_key = "pplx-your-key"

url = "https://api.perplexity.ai/chat/completions"

payload = {
    "model": "pplx-7b-online",
    "messages": [
        {
            "role": "system",
            "content": "Be precise and concise."
        },
        {
            "role": "user",
            "content": "What is Mixtral model?"
        }
    ]
}
headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "Authorization": "Bearer " + pplx_key
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)

You also have to follow their guide to get your API key if you didn't already: https://docs.perplexity.ai/docs

LexiestLeszek commented 11 months ago

@ArtDoctor thanks! paid one works just fine.

But I still don't understand why the one from here doesn't work only when its deployed and works perfectly when I run it from my macbook.

ArtDoctor commented 11 months ago

Glad to help!

I'm wondering about that as well. It looks like the owner of this library isn't working on it anymore, because there are lots of open problems and no recent updates. That's sad. Maybe perplexity made some changes that broke the library, which is causing all these problems.

nathanrchn commented 11 months ago

I think it's because when you test it on your mac locally, cloudfare doesn't block the request, but on a server, they block it.

LexiestLeszek commented 11 months ago

I think it's because when you test it on your mac locally, cloudfare doesn't block the request, but on a server, they block it.

But I use ngrok and it works, shouldn't cloudfare block it in that case?