Using OpenAI-ChatGPT with Drafts

I’m getting No reply received for anything I query. What am I missing on the ChatGPT side? I have added the credentials and all.

Have you checked the action log for details on what went wrong?

Where do I see that? The action seems to run just fine but the result is the same for everything.

Sorry, it was linked above in the “Troubleshooting” section: Action Log | Drafts User Guide

Ah! I think it’s rate limits which is strange since I got this error on the first action I tried.

OpenAI: 429, Your request to the OpenAI API has been refused due to rate limits. Either you have made too many requests in a short period of time, or the API Key you are using has reached usage limits. Check your usage and billing configuration at platform.openai.com for details.

Update: Added a payment method and now it works. Thanks!

Sounds like a use case for PopClip, which has its own ChatGPT extension.

2 Likes

I am trying to combine the two scripts together: Prompt to ask what to do with the selection.

Keep getting an error

Script Error: SyntaxError: Unexpected EOF
Line number: 46, Column undefined

Script:

let f = () => {
	let p = new Prompt()
	p.title = "Ask ChatGPT"
	p.message = "Type your prompt for ChatGPT, and continue. The response will be inserted in the current draft."
	p.addTextView("prompt", "ChatGPT Prompt", "")
	p.addButton("Ask")
	
	if (!p.show()) {
		return false
	}
	const chatPrompt = p.fieldValues["prompt"]
	if (chatPrompt.length == 0) { return false }

	let ai = new OpenAI()
	let answer = ai.quickChatResponse(chatPrompt)

	if (!answer || answer.length == 0) {
		answer = "No reply received"
	}
	let instruction = `${chatPrompt}


// get editor values
const [st, len] = editor.getSelectedRange()
const selection = editor.getSelectedText()

// build prompt
var instruction = content

// create OpenAI API object and use single response
// convenience function to send prompt
let ai = new OpenAI()
let answer = ai.quickTextEdit(selection, instruction)

// if we got a reply, add it to the draft
if (answer) {
	answer = answer.replace(/^"+|"+$/g, '')
	editor.setSelectedText(answer)
	editor.setSelectedRange(st, answer.length)
}

	}

if (!f()) {
	context.cancel()
}
1 Like

This script isn’t valid to compile. I think you’ve at least got some mismatched backticks, and it does not seem like you are on the right track to be asking about what to do with the results. This might be best asked in a new thread, and just state in detail what you are trying to accomplish, and we should be able to guide you in the right direction.

Posted: Combine Prompt with Selection and ChatGPT

1 Like

Just installed PopClip with the ChatGPT extension, and that was the exact functionality I was looking for. Thank you!

The MAS hides updates in the update view sometimes (rather, it’s slow to show them) but going directly to the app’s page in the App Store will give the truth about its update status.

I can’t wait to see what the big brains in this community build with this functionally. Very exciting!

I have a paid subscription to OpenAI.

I’ve created a brand new API key to use with Drafts on my iPhone. When I use the ask, chat, GPT action, and enter the prompt, I get the enter credential dialog box. I Paste in the new API key that I generated, and I am getting the no reply received response.

Here is the text from the action log:

OpenAI: 401, Unauthorized. You may need to forget OpenAI credentials in Drafts Settings and enter a new API key next time the action is run.
Script step completed.

The set up process seems pretty straightforward, I’m not sure why this isn’t working. Does anyone have any other suggestions?

The response from the API seems pretty definitive. Have you tried…

  • Forgetting and reentering the API key.
  • Entering a different API key.
  • Testing the existing API key in another app, or using an API client such as Postman.

I assume you copied and pasted the key, but is there any chance it may have included an extra space at the end or similar?

1 Like

I’m created a API key but I get always “No reply received”. Any tips how to check where the problem is? Thanks.

See the “troubleshooting” section in the very first post on this thread.

Hey there! Fairly new to Drafts and OpenAI. I feel live I have everything set up correctly, but I’m not getting replies.

I have a paid account on OpenAI, a fresh key, and Drafts updated. Any thoughts?

Try forgetting and reentering your key.

Failing that, try generating a new key and using that.

I tried both, but still no replies. @agiletortoise any ideas?

Hey there! Fairly new to Drafts and OpenAI. I feel live I have everything set up correctly, but I’m not getting replies. I have a paid account on OpenAI, a fresh key, and Drafts updated. Any thoughts?

Are the example actions working? It seems you are working with a custom one.