Skip to content

Instantly share code, notes, and snippets.

@oboenikui
Last active December 21, 2023 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oboenikui/a3378e1f7baffe5f778dedc563845c67 to your computer and use it in GitHub Desktop.
Save oboenikui/a3378e1f7baffe5f778dedc563845c67 to your computer and use it in GitHub Desktop.
CherriでSiriショートカットを実装
#define glyph chatbox
#define color yellow
#define inputs text
#define from menubar, sleepmode, sharesheet, watch
#define name ダジャレで返信する
@input0 = "{ShortcutInput}"
@input = input0
@inputLength = countChars(input)
if inputLength == 0 {
menu "入力方法を選択" {
// item "音声入力":
// @input1 = listen("After Pause", "Japanese")
// @input = input1
item "テキスト入力":
@input2 = prompt("テキストを入力")
@input = input2
item "クリップボード":
@input3 = "{Clipboard}"
@input = input3
}
}
@inputLength = countChars(input)
if inputLength == 0 {
stop()
}
@bracket = "{"
@prompt = "ダジャレとは、同じ読み方で別の意味の単語やフレーズを使った文のことです。\n以下に良いダジャレと悪いダジャレの例を挙げます。\n\n|ダジャレ|良し悪し|理由|\n|------|-----|-----|\n|布団が吹っ飛んだ|良い|「布団」と「吹っ飛ん」が似た読み方で別の意味であるため|\n|ふとんな布団|悪い|「ふとんな」というフレーズは日本語として不適切|\n\n|布団は布団|悪い|同じ意味の単語の繰り返し|ダジャレを考える時のフローは以下の通りです。\n1. 【入力】文の中から特徴的な単語を1個抽出します。\n2. 抽出した単語語と読み方が完全に一致、もしくは同じ読みを含む、実在する単語やフレーズを10個まで探します。元と同じ単語は除外してください。\n例えば、「蜜柑」と同じ読みを含む単語として、「未刊」や「未完成」、「アルミ缶」を得られます。\n3. 見つけた単語を使って【入力】への返信として適切な文章を作成します。より意味が通っているほど好ましいです。\n以上の情報に従って、ダジャレの返信文を5文作成してください。\n\n出力は、以下のJSON形式で行います。JSON以外は出力しないでください。\n{bracket} \"result\": [{bracket}\"text\": \"作成した文\", \"keyword\": \"作成した文で使用した単語\"}, ...] }\n\n【入力】「{input}」"
@bodyJson = {
"model": "gpt-4-1106-preview",
"response_format": { "type": "json_object" },
"messages": [
{ "role": "user", "content": "{prompt}" }
]
}
@body = "{bodyJson}"
// APIトークンを別のショートカットにまとめて管理している場合
// @KEY_OPENAI = "OPENAI_TOKEN"
// @apiToken = run(".env", KEY_OPENAI)
// @headers = {
// "Authorization": "Bearer {apiToken}",
// "Content-Type": "application/json"
// }
@headers = {
"Authorization": "Bearer (OpenAIのトークン)",
"Content-Type": "application/json"
}
@response = fileRequest("https://api.openai.com/v1/chat/completions", "POST", body, headers)
@responseJson = getDictionary(response)
@choices = getValue(responseJson, "choices")
@firstChoice = getListItem(choices, 0)
@resultMessage = getValue(firstChoice, "message")
@resultContent = getValue(resultMessage, "content")
@resultContentJson = getDictionary(resultContent)
@results = getValue(resultContentJson, "result")
@outputs = []
@resultsCount = count(results)
repeat i for resultsCount {
@result = getListItem(results, i)
@resultDict = getDictionary(result)
@text = getValue(resultDict, "text")
@keyword = getValue(resultDict, "keyword")
@outputs += "{text}"
}
@chooseArg = outputs
@selected = chooseFromList(chooseArg, "ダジャレを選択してください。")
copyToClipboard(selected)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment