Action

Ask Perplexity.ai

Posted by agiletortoise, Last update 8 months ago

UPDATES

8 months ago

Update model options for Perplexity changes.

Prompt for input to send to Perplexity.ai, and insert the response to the prompt in the current draft.

This version includes options to select preferred model from a list of some of the available models. See docs for other supported models.

For more information on using this action, visit our OpenAI integration guide

Steps

  • script

    // setup Perplexity options
    const models = [
    	"llama-3-sonar-small-32k-chat",
    	"llama-3-sonar-large-32k-chat",
    	"llama-3-8b-instruct"
    ]
    const host = "https://api.perplexity.ai"
    const initialText = editor.getSelectedText()
    
    let f = () => {
    	let p = new Prompt()
    	p.title = "Ask Perplexity.ai"
    	p.message = "Type your prompt for Perplexity, and continue. The response will be inserted in the current draft."
    	p.addTextView("prompt", "Prompt", initialText)
    
    	p.addSelect("model", "Model", models, [models[0]], false)
    	p.addButton("Ask")
    	
    	if (!p.show()) {
    		return false
    	}
    	const chatPrompt = p.fieldValues["prompt"]
    	if (chatPrompt.length == 0) { return false }
    
    	let ai = OpenAI.create(null, host)
    	ai.model = p.fieldValues["model"][0]
    	ai.credentialIdentifier = "Perplexity.ai"
    
    	let answer = ai.quickChatResponse(chatPrompt)
    
    	if (!answer || answer.length == 0) {
    		answer = "No reply received"
    	}
    	let content = `${chatPrompt}
    
    ===
    
    ${answer}
    
    ===
    `
    	editor.setSelectedText(content)
    	return true
    }
    
    if (!f()) {
    	context.cancel()
    }
    
    

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.