Action

Ask Gemini

Posted by agiletortoise, Last update 7 months ago

Ask for a prompt to send to Google Gemini, inserting the result text in the editor.

For more information and examples incorporating Google Gemini, visit the integration guide

Steps

  • script

    // change variable to alter model used
    const models = [
    	"models/gemini-pro"
    ]
    
    const initialText = editor.getSelectedText()
    
    let f = () => {
    	let p = new Prompt()
    	p.title = "Ask Google Gemini"
    	p.message = "Type your prompt for Gemini, 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 GoogleAI()
    	const model = p.fieldValues["model"][0]
    	let answer = ai.quickPrompt(chatPrompt, 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.