Action

Ask Claude

Posted by agiletortoise, Last update about 1 month ago

Ask for a prompt to send to Anthropic’s Claude AI, inserting the result text in the editor. The prompt will default to the current text selection in the editor.

For more information and examples incorporating Antropic Claude, visit the integration guide

Steps

  • script

    const models = AnthropicAI.knownModels()
    
    const initialText = editor.getSelectedText()
    
    let f = () => {
    	let p = new Prompt()
    	p.title = "Ask Claude"
    	p.message = "Type your prompt for Claude, 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 = new AnthropicAI()
    	const model = p.fieldValues["model"][0]
    	let answer = ai.quickPrompt(chatPrompt, {"model": model})
    
    	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.