ShareShortcuts

ShortGPT

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

cyb3rfr3ak
Dupliquer « ShortGPT »

Tu as créé quelque chose de nouveau à partir de ce raccourci ? Partage-le comme version dérivée : il devient un raccourci à toi, que tu gères, et les deux pages renvoient l’une vers l’autre pour que cyb3rfr3ak soit crédité.

  1. 1Obtenez le raccourci et modifiez-le dans l’app Raccourcis. Donnez-lui un nom bien à lui.
  2. 2Partage-le depuis l’app Raccourcis et copie le lien iCloud.
  3. 3Reviens ici, colle le lien et décris ce qui change, par exemple : « Ajout d’une étape qui utilise Apple Intelligence pour personnaliser le texte. »
Créer mon fork
Téléchargements
20K
Enregistré
0
Actions
125
Catégorie
Utilities
Version
1.0
Langue
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

Nouveautés

Version 1.0

First release

Historique des versions
1.0 25 sept. 2024

First release

Ce qu’il fait

125 actions
  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

Afficher en tant que code
Bêta

Chaque action de ce raccourci écrite en Cherri, un langage de programmation pour Raccourcis. Idéal pour comprendre son fonctionnement.

#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("   ")
}
Décompilé avec cherri 2.3.0 (GPL-2.0). Quelques corrections peuvent être nécessaires avant la compilation.

Notes et avis

Écrire un avis
–
sur 5
★★★★★
★★★★
★★★
★★
★
0 ratings

Aucun avis pour le moment. Sois le premier à partager ton avis !

Publicité

Ça pourrait aussi te plaire

Tout afficher
Publicité