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

Answer makes no sense #35

Open
George3d6 opened this issue Nov 11, 2023 · 1 comment
Open

Answer makes no sense #35

George3d6 opened this issue Nov 11, 2023 · 1 comment

Comments

@George3d6
Copy link

I execute the following code:

    perplexity = Perplexity("[email protected]")
    answer = perplexity.search(q)
    for a in answer:
        wr = a["web_results"]
        print(wr[0]["snippet"])

The answer seems to have 75 yields but they are all the exact same sentence (as far of the snippet for the web result) -- it never gets completed.

Same happens without login

@suckerfish
Copy link

suckerfish commented Jan 14, 2024

seems the responses can be chunked. I had chatgpt help me with code to deal with chunked responses. Not sure if that is exactly what's happening with you but it helped me with incomplete or duplicate looking results. Note that I'm using 'answer' and not 'snippet' though:

`answer = perplexity.search(text)

full_answer = ""
last_chunk = ""
for item in answer:
    if 'answer' in item and item['answer']:
        current_chunk = item['answer']
        if current_chunk.startswith(last_chunk):
            new_content = current_chunk[len(last_chunk):]
            full_answer += new_content
        else:
            full_answer += current_chunk
        last_chunk = current_chunk

        if 'final' in item and item['final']:
            break

if full_answer:
    print(textwrap.fill(full_answer, width=90))
else:
    logging.error("No valid results found")`

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

No branches or pull requests

2 participants