Created
December 25, 2024 03:57
Revisions
-
hitamu created this gist
Dec 25, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ function run(input) { const key = 'your-key-here'; return summarizeText(input[0], key) } function summarizeText(text, apiKey) { const app = Application.currentApplication(); app.includeStandardAdditions = true; const endpoint = 'https://api.openai.com/v1/chat/completions'; const requestData = { model: 'gpt-4o-mini', messages: [ { role: 'system', content: 'You are a helpful assistant that provides concise summaries.' }, { role: 'user', content: `Please summarize the following text: ${text}` } ], temperature: 0.7, max_tokens: 500 }; try { // Properly escape the JSON data for shell command const escapedData = JSON.stringify(requestData).replace(/'/g, "'\\''"); const curlCommand = `curl -s "${endpoint}" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${apiKey}" \ -d '${escapedData}'`; const response = app.doShellScript(curlCommand); const jsonResponse = JSON.parse(response); return jsonResponse.choices[0].message.content; } catch (error) { return `Error: ${error}`; } }