Perplexity Chatbot Project

This project is a chatbot that uses one of the best open-source online LLMs developed by Perplexity AI, Inc. (perplexity.ai) called 'mistral-7b-instruct'

The app uses the HTTP POST restful method of sending and receiving data to and from the API (https://api.perplexity.ai/chat/completions). How that works can be seen in the 'Chatbot' procedure in this app. Header information is sent to the API URL in the 'RequestHeaders' block followed by a messages section in the 'PostText' block that sends a prompt to the API on the web.

The 'ChatbotAPI.GotText' event block receives the reply embedded in a Jason string which is then extracted and displayed on the device screen and optionally spoken using the text-to-speech component.

For fun I added speech input as well, so the app user and chatbot can have a voice conversation (the user must press the record button each time they speak, however, sort of like a walkie-talkie.)

I have included two other LLMs to try, but I find that they are less capable. There are others available for study via the Chat Completions page at: docs.perplexity.ai/reference/post_chat_completions and you can try their online chatbot with Copilot here: perplexity.ai

labs.perplexity.ai provides a chatbot playground to test their LLM models: pplx-7b-online, pplx-70b-online, pplx-7b-chat, pplx-70b-chat, mistral-7b-instruct, codellama-34b-instruct, llama-2-70b-chat, llava-7b-chat, mistral-8x7b-instruct

mistral-7b-instruct used in this app costs $5 per 1000 requests. The web page says the API key for the open-source language models is free with a preplexity PRO account. I have not had to pay anything yet and have a PRO account.

Not displayed in the Designer above is the 'Record Voice' button which swaps positions with the textbox input section when the Speech Input switch is on.

As stated above this app simply sends a text string via an API call to an online server which uses AI to generate an 'intelligent' response. This is not to be confused with a web 'search' as an AI can create original content as demonstrated in this session I had with the mistral-7b-instruct which was designed to be proficient at chat:

Of course, it does information retrieval as well...

Here's the project file. You would need an API key for the app to work:
PerplexityAPI.aia (6.4 KB)

Happy Inventing!

4 Likes

The link to the api doens't work. I think you have to be logged in to the site. Now you get an 401 error.

Hi, Peter. Have you entered the API key into the variable in the Blocks Editor? That is required to access the API. I will look into what happens when I don't have a valid API key to see if that is what is happening with you and then I will get back to you.

Without entering a valid API Key which you get at the perplexity.ai site after setting up an account (https://www.perplexity.ai/settings/account) the app will throw an error. I got a 'select list item' error without the API Key entered in the variable block in the app. I hope this helps.

Version 2 of this project displays a helpful message if you don't have a valid API Key entered.
PerplexityAPI (1).aia (6.8 KB)

Hi,

I tried this link https://api.perplexity.ai/chat/completions from your post. Then I get the 401. That's why I thought that is only accessible when you have an account which I don't have.

That is correct.

Thank you very much for your contribution, I find it very useful.

I put my perplexity api but it returns a 400 error. I haven't modified anything in your version 2 blocks.

Thanks, miguel_cano. Here is what that error 400 is described as: 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing).

I am sorry that you are getting this error. You did not change any of the blocks, so I am wondering if it is your location that may be affecting the result if you are out of the U.S. and Perplexity does not support certain countries with their API? I hope this is not the case. Dreamhost.com has these suggestions to clear a HTTP 400 Bad Request error:

How to Fix the 400 Bad Request Error (6 Methods)

  1. Check for Errors in the Address. First, you'll want to check your URL for any errors. ...
  2. Clear Your Browser's Cache and Cookies. ...
  3. Disable Browser Extensions. ...
  4. Flush the DNS Cache. ...
  5. Check the Uploaded File Size. ...
  6. Troubleshoot Your Device and Internet Connection.

I am a novice at working with APIs so much of what I do is trial-and-error. I did see that two parameters in my original api header were not not needed for it to work. The content-length parameter is supposed to be returned by the server, I believe. You may want to try removing them and retesting without them as shown below: