Escanea con tu iPhone para instalar
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
Novedades
Versión 1.0
First release
Qué hace
125 acciones-
CommentVersion 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
-
Text
-
Set VariableLanguage
-
Text
-
Set VariableApiKey
-
Text
-
Set VariableModel
-
Number
-
Set VariableMaxTokens
-
Text
-
Text
-
Number
-
Set VariableTemperature
-
Text
-
CommentInitialize localization data
-
Set VariableLocalizedTextsArray
-
Dictionary
-
Get Dictionary Value
-
If
-
Repeat with Each
-
Add to Variable
-
If
-
Get Dictionary Value
-
Repeat with Each
-
Add to Variable
-
CommentSet all texts
-
Get Dictionary from Input
-
Get Dictionary Value
-
Set VariablemsgInitializedStorage
-
Get Dictionary Value
-
Set VariablemsgDuplicatePrompt
-
Get Dictionary Value
-
Set VariablemsgEmptyPrompt
-
CommentInitialize storage file
-
Get File
-
If
-
Text
-
Get Dictionary from Input
-
Save File
-
Show Notification…
-
If
-
Set VariablepreviousPrompt
-
Repeat
-
CommentOnly allow eight most recent entries from history. To achieve this, the history array is iterated reversed.
-
Set VariablereverseHistory
-
Get File
-
Get Dictionary from Input
-
Get Dictionary Value
-
Count
-
Repeat
-
If
-
Get Variable
-
Calculate
-
Calculate
-
Get Item from List
-
Add to Variable
-
If
-
CommentNow, revert the reverseHistory again, to get the correct order
-
Set Variablehistory
-
Count
-
Repeat
-
Get Variable
-
Calculate
-
Calculate
-
Get Item from List
-
Add to Variable
-
CommentPrepare messages array (which will be sent to OpenAI) with system message and content of history
-
Set Variablemessages
-
Add to Variable
-
Add to Variable
-
CommentUser speech input
-
Dictate Text
-
If
-
If
-
Show Notification…
-
Stop This Shortcut
-
If
-
Set VariablepreviousPrompt
-
If
-
Show Notification…
-
Stop This Shortcut
-
CommentAdd user prompt to history and messages array
-
Text
-
Add to Variable
-
Add to Variable
-
CommentCreate initial dictionary to build an OpenAI request payload
-
Dictionary
-
CommentConcat messages array by comma
-
Combine Text
-
CommentCreate a JSON object
-
Text
-
Get Dictionary from Input
-
Get Dictionary Value
-
CommentSet messages JSON object to request payload dictionary
-
Set Dictionary Value
-
CommentSend request to OpenAI. Request body payload must be the last modified dictionary (not the initial PayloadDictInit).
-
Get Contents of URLhttps://api.openai.com/v1/chat/completions
-
Get Dictionary from Input
-
CommentStore full response as lastResponse in storage file. The save command must use the last modified dictionary (not the initial StorageFileDict).
-
Set Dictionary Value
-
Save File
-
CommentExtract single answer from OpenAI response
-
Get Dictionary Value
-
Get Dictionary Value
-
CommentStore plain answer to lastAnswer in storage file. The save command must use the last modified dictionary (not the initial StorageFileDict).
-
Set Dictionary Value
-
Save File
-
CommentSanitize answer and add it to the history array
-
Replace Text
-
Text
-
Add to Variable
-
CommentCreate a JSON object of the history array
-
Combine Text
-
Text
-
Get Dictionary from Input
-
Get Dictionary Value
-
CommentStore history to storage file. The save command must use the last modified dictionary (not the initial StorageFileDict).
-
Set Dictionary Value
-
Save File
-
CommentRespond to user
-
Set Volume
-
Speak Text
-
Text
-
Show Alert
-
Speak Text
Ver como código
Todas las acciones de este atajo escritas en Cherri, un lenguaje de programación para Atajos. Ideal para aprender cómo 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 con cherri 2.3.0 (GPL-2.0). Puede que necesite pequeños ajustes antes de compilarse.
Valoraciones y reseñas
Escribe una reseña–
de 5
★★★★★
★★★★
★★★
★★
★
0 ratings
Aún no hay reseñas. ¡Sé el primero en compartir tu opinión!
Publicidad
También te puede gustar
Publicidad