ShareShortcuts

ShortGPT

Access the power of OpenAI GPT-4o using your own API key

cyb3rfr3ak
Fazer fork de “ShortGPT”

Criou algo novo a partir deste atalho? Compartilhe como uma derivação: ela se torna um atalho seu, que você gerencia, e as duas páginas têm links entre si para que cyb3rfr3ak receba o crédito.

  1. 1Obtenha o atalho e altere-o no app Atalhos. Dê a ele um nome próprio.
  2. 2Compartilhe pelo app Atalhos e copie o link do iCloud.
  3. 3Volte aqui, cole o link e descreva o que mudou, por exemplo: “Adicionei uma etapa que usa a Apple Intelligence para personalizar o texto.”
Downloads
20K
Salvo
0
Ações
125
Categoria
Utilities
Versão
1.0
Idioma
EN

Access the power of OpenAI GPT-4o using your own API key.

Features:

  • Currently only English is supported - other languages have to be adjusted in the Shortcut itself (text-to-speech at the bottom)
  • Stores up to 4 message pairs for context
  • Customize parameters like model, max tokens, system message, and temperature

Novidades

Versão 1.0

First release

Histórico de versões
1.0 25 de set de 2024

First release

O que ele faz

125 ações
  1. Comment
    Version History ————————— 2024-09-25 - v0.3.0: Adjusted default storage file 2024-09-25 - v0.2.0: Added simple localization 2024-09-25 - v0.1.6: Initial version
  2. Text
  3. Set Variable
    Language
  4. Text
  5. Set Variable
    ApiKey
  6. Text
  7. Set Variable
    Model
  8. Number
  9. Set Variable
    MaxTokens
  10. Text
  11. Text
  12. Number
  13. Set Variable
    Temperature
  14. Text
  15. Comment
    Initialize localization data
  16. Set Variable
    LocalizedTextsArray
  17. Dictionary
  18. Get Dictionary Value
  19. If
  20. Repeat with Each
  21. Add to Variable
  22. If
  23. Get Dictionary Value
  24. Repeat with Each
  25. Add to Variable
  26. Comment
    Set all texts
  27. Get Dictionary from Input
  28. Get Dictionary Value
  29. Set Variable
    msgInitializedStorage
  30. Get Dictionary Value
  31. Set Variable
    msgDuplicatePrompt
  32. Get Dictionary Value
  33. Set Variable
    msgEmptyPrompt
  34. Comment
    Initialize storage file
  35. Get File
  36. If
  37. Text
  38. Get Dictionary from Input
  39. Save File
  40. Show Notification
    …
  41. If
  42. Set Variable
    previousPrompt
  43. Repeat
  44. Comment
    Only allow eight most recent entries from history. To achieve this, the history array is iterated reversed.
  45. Set Variable
    reverseHistory
  46. Get File
  47. Get Dictionary from Input
  48. Get Dictionary Value
  49. Count
  50. Repeat
  51. If
  52. Get Variable
  53. Calculate
  54. Calculate
  55. Get Item from List
  56. Add to Variable
  57. If
  58. Comment
    Now, revert the reverseHistory again, to get the correct order
  59. Set Variable
    history
  60. Count
  61. Repeat
  62. Get Variable
  63. Calculate
  64. Calculate
  65. Get Item from List
  66. Add to Variable
  67. Comment
    Prepare messages array (which will be sent to OpenAI) with system message and content of history
  68. Set Variable
    messages
  69. Add to Variable
  70. Add to Variable
  71. Comment
    User speech input
  72. Dictate Text
  73. If
  74. If
  75. Show Notification
    …
  76. Stop This Shortcut
  77. If
  78. Set Variable
    previousPrompt
  79. If
  80. Show Notification
    …
  81. Stop This Shortcut
  82. Comment
    Add user prompt to history and messages array
  83. Text
  84. Add to Variable
  85. Add to Variable
  86. Comment
    Create initial dictionary to build an OpenAI request payload
  87. Dictionary
  88. Comment
    Concat messages array by comma
  89. Combine Text
  90. Comment
    Create a JSON object
  91. Text
  92. Get Dictionary from Input
  93. Get Dictionary Value
  94. Comment
    Set messages JSON object to request payload dictionary
  95. Set Dictionary Value
  96. Comment
    Send request to OpenAI. Request body payload must be the last modified dictionary (not the initial PayloadDictInit).
  97. Get Contents of URL
    https://api.openai.com/v1/chat/completions
  98. Get Dictionary from Input
  99. Comment
    Store full response as lastResponse in storage file. The save command must use the last modified dictionary (not the initial StorageFileDict).
  100. Set Dictionary Value
  101. Save File
  102. Comment
    Extract single answer from OpenAI response
  103. Get Dictionary Value
  104. Get Dictionary Value
  105. Comment
    Store plain answer to lastAnswer in storage file. The save command must use the last modified dictionary (not the initial StorageFileDict).
  106. Set Dictionary Value
  107. Save File
  108. Comment
    Sanitize answer and add it to the history array
  109. Replace Text
  110. Text
  111. Add to Variable
  112. Comment
    Create a JSON object of the history array
  113. Combine Text
  114. Text
  115. Get Dictionary from Input
  116. Get Dictionary Value
  117. Comment
    Store history to storage file. The save command must use the last modified dictionary (not the initial StorageFileDict).
  118. Set Dictionary Value
  119. Save File
  120. Comment
    Respond to user
  121. Set Volume
  122. Speak Text
  123. Text
  124. Show Alert
  125. Speak Text

Ver como código
Beta

Todas as ações deste atalho escritas em Cherri, uma linguagem de programação para o app Atalhos. Ótimo para aprender como ele funciona.

#include 'actions/web'
#include 'actions/text'
#include 'actions/documents'
#define color darkblue
#define glyph timeLapse

/*
Version History
—————————
2024-09-25 - v0.3.0: Adjusted default storage file
2024-09-25 - v0.2.0: Added simple localization
2024-09-25 - v0.1.6: Initial version
*/
@Language = "English"
@ApiKey = ""
@Model = "gpt-4o-mini"
@MaxTokens = 4000
const SystemMessageInput = "You're an helpful assistant. Respond with short to medium length answers unless I am asking for more details."
@Temperature = 0.7
const StorageFilePath = "ShortGPT/storage.json"
// Initialize localization data

@LocalizedTextsArray = nil
const LocalizationDictionary = {
	"English": {
		"DuplicatePrompt": "Prompt was identical to previous prompt. Stopping execution.",
		"EmptyPrompt": "Prompt was empty. Stopping execution.",
		"InitializedStorage": "Storage file '{StorageFilePath}' created under default Shortcuts directory."
	},
	"German": {
		"DuplicatePrompt": "Frage war identisch zu voriger Frage. Stoppe Ausführung.",
		"EmptyPrompt": "Frage war leer. Stoppe Ausführung",
		"InitializedStorage": "Speicherdatei '{StorageFilePath}' wurde im Standard Shortcuts Ordner angelegt."
	}
}
const DictionaryValue = getValue(LocalizationDictionary, @Language)

if DictionaryValue {
	for _ in DictionaryValue {
		@LocalizedTextsArray = @RepeatItem
	}
} else {
	const DictionaryValue1 = getValue(LocalizationDictionary, "English")
	for _ in DictionaryValue1 {
		@LocalizedTextsArray = @RepeatItem
	}
}
// Set all texts

const Dictionary = getDictionary(@LocalizedTextsArray)
@msgInitializedStorage = Dictionary['InitializedStorage']
@msgDuplicatePrompt = Dictionary['DuplicatePrompt']
@msgEmptyPrompt = Dictionary['EmptyPrompt']
// Initialize storage file

const StorageFile = getFileFromFolder(, StorageFilePath, false)

if !StorageFile {
	const StorageInitDataText = "{\\"history\\":[]}"
	const StorageInitDataDict = getDictionary(StorageInitDataText)
	const SavedFile = saveFile(StorageFilePath, StorageInitDataDict, true)
	showNotification(@msgInitializedStorage, SavedFile)
} else {
}
@previousPrompt = nil

repeat _ for 200 {
	/*
	Only allow eight most recent entries from history.
	To achieve this, the history array is iterated reversed.
	*/
	@reverseHistory = nil
	const StorageFile1 = getFile(StorageFilePath, false)
	const StorageFileDict = getDictionary(StorageFile1)
	const HistoryArray = getValue(StorageFileDict, "history")
	const HistoryItemsCount = count(HistoryArray)
	repeat _ for HistoryItemsCount {
		if @RepeatIndex2 < 9 {
			// TODO: Get Variable not supported: Assign variable here to 'HistoryItemsCount'.
			const CorrectedIndex = HistoryItemsCount + 1
			const CalculationResult = CorrectedIndex - @RepeatIndex2
			getListItem(HistoryArray, CalculationResult)
			@reverseHistory
		} else {
		}
	}
	// Now, revert the reverseHistory again, to get the correct order

	@history = nil
	const ReverseHistoryItemsCount = count(@reverseHistory)
	repeat _ for ReverseHistoryItemsCount {
		// TODO: Get Variable not supported: Assign variable here to 'ReverseHistoryItemsCount'.
		const CorrectedIndex1 = ReverseHistoryItemsCount + 1
		const CalculationResult1 = CorrectedIndex1 - @RepeatIndex2
		getListItem(@reverseHistory, CalculationResult1)
		@history
	}
	// Prepare messages array (which will be sent to OpenAI) with system message and content of history

	@messages = nil
	@messages = SystemMessageItem
	@messages = @history
	// User speech input

	const DictatedText = listen("On Tap", @Language)
	if DictatedText {
		if DictatedText == @previousPrompt {
			showNotification(@msgDuplicatePrompt, DictatedText)
			stop()
		} else {
			@previousPrompt = DictatedText
		}
	} else {
		showNotification(@msgEmptyPrompt, DictatedText)
		stop()
	}
	// Add user prompt to history and messages array

	@history += "{\\"role\\":\\"user\\",\\"content\\":\\"{DictatedText}\\"}"
	@messages
	// Create initial dictionary to build an OpenAI request payload

	const PayloadDictInit = {
		"max_tokens": "{@MaxTokens}",
		"model": "{@Model}",
		"n": 1,
		"temperature": "{@Temperature}"
	}
	// Concat messages array by comma

	joinText(@messages, ",")
	// Create a JSON object

	const WhatTheFuck = "{\\"messages\\":[{}]}"
	const Dictionary1 = getDictionary(WhatTheFuck)
	// Set messages JSON object to request payload dictionary

	const PayloadDictModified = setValue(PayloadDictInit, "messages")
	// Send request to OpenAI. Request body payload must be the last modified dictionary (not the initial PayloadDictInit).

	const ContentsOfURL = fileRequest("https://api.openai.com/v1/chat/completions", "POST", PayloadDictModified, {
		"Authorization": "Bearer {@ApiKey}",
		"Content-Type": "application/json;charset=utf-8"
	})
	const Dictionary3 = getDictionary(ContentsOfURL)
	// Store full response as lastResponse in storage file. The save command must use the last modified dictionary (not the initial StorageFileDict).

	const Dictionary2 = setValue(StorageFileDict, "lastResponse", Dictionary3)
	saveFile(StorageFilePath, Dictionary2, true)
	// Extract single answer from OpenAI response

	const DictionaryValue2 = getValue(Dictionary3, "choices")
	const AnswerText = DictionaryValue2['message.content']
	// Store plain answer to lastAnswer in storage file. The save command must use the last modified dictionary (not the initial StorageFileDict).

	const Dictionary4 = setValue(Dictionary2, "lastAnswer", AnswerText)
	saveFile(StorageFilePath, Dictionary4, true)
	// Sanitize answer and add it to the history array

	replaceText("\n", "\n", AnswerText)
	@history += "{\\"role\\":\\"assistant\\",\\"content\\":\\"{}\\"}"
	// Create a JSON object of the history array

	joinText(@history, ",")
	const Text = "{\\"history\\":[{}]}"
	const Dictionary5 = getDictionary(Text)
	// Store history to storage file. The save command must use the last modified dictionary (not the initial StorageFileDict).

	const Dictionary6 = setValue(Dictionary4, "history")
	saveFile(StorageFilePath, Dictionary6, true)
	// Respond to user

	setVolume(0.10000000149011612)
	speak(AnswerText, false, "en-US")
	confirm()
	speak("   ")
}
Descompilado com cherri 2.3.0 (GPL-2.0). Pode precisar de pequenos ajustes antes de compilar.

Avaliações e comentários

Escrever uma avaliação
–
de 5
★★★★★
★★★★
★★★
★★
★
0 ratings

Ainda não há avaliações. Seja o primeiro a compartilhar o que você pensa!

Publicidade

Você também pode gostar

Ver tudo
Publicidade