Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on run {input, parameters}
- set originalText to input as string
- set apiKey to “YOURAPIKEYHERE” -- Replace with your GPT-3.5 Turbo API key
- set promptTemplate to "Please rewrite the following text using proper English: "
- set promptText to promptTemplate & originalText
- set apiEndpoint to "https://api.openai.com/v1/chat/completions"
- set requestBody to "{ \"model\": \"gpt-3.5-turbo\", \"messages\": [{\"role\": \"user\", \"content\": \"" & promptText & "\"}], \"temperature\": 0.7 }"
- set curlCommand to "curl -s -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer " & apiKey & "\" --data " & (quoted form of requestBody) & " " & apiEndpoint
- set jsonResponse to ""
- try
- set jsonResponse to do shell script curlCommand
- on error errMsg
- display dialog "Error executing curl command: " & errMsg buttons {"OK"} default button 1
- return
- end try
- set theResponse to ""
- try
- set theResponse to (do shell script "/usr/bin/python3 -c \"import json, sys; jsonData = json.loads(sys.argv[1]); content = jsonData['choices'][0]['message']['content'].strip(); print(content.encode('unicode_escape').decode('unicode_escape'))\" " & (quoted form of jsonResponse))
- on error errMsg
- display dialog "Error processing JSON response: " & errMsg & " | JSON: " & jsonResponse buttons {"OK"} default button 1
- return
- end try
- return theResponse
- end run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement