Created
December 29, 2024 10:13
-
-
Save DmitriyLyalyuev/aa6137850c86a7aeecb2d18d189d304e to your computer and use it in GitHub Desktop.
Mistral AI summarizer for Raycast
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 characters
#!/bin/bash | |
# @raycast.schemaVersion 1 | |
# @raycast.title Summarize Safari page | |
# @raycast.mode fullOutput | |
# | |
# Optional parameters: | |
# @raycast.icon ✨ | |
# | |
# @raycast.packageName Things | |
get_safari_content() { | |
osascript <<EOF | |
tell application "Safari" | |
set pageContent to do JavaScript "document.body.innerText" in document 1 | |
end tell | |
return pageContent | |
EOF | |
} | |
summarize_content() { | |
local content=$1 | |
local api_key="YOUR_API_KEY_HERE" | |
local api_url="https://api.mistral.ai/v1/chat/completions" | |
local prompt=$(cat <<EOF | |
Пожалуйста, проанализируй следующую статью и выполни следующие задачи: | |
1. Сделай краткую суммаризацию статьи. | |
2. Выдели 5 ключевых идей из статьи. | |
3. Оцени примерное время, необходимое для прочтения статьи. | |
Ответ должен быть структурирован следующим образом: | |
Суммаризация: | |
[Краткое резюме статьи] | |
Ключевые идеи: | |
1. [Первая ключевая идея] | |
2. [Вторая ключевая идея] | |
3. [Третья ключевая идея] | |
4. [Четвертая ключевая идея] | |
5. [Пятая ключевая идея] | |
Время прочтения: | |
[Оценка времени прочтения статьи] | |
Статья: | |
EOF) | |
local json_data=$(jq -n --arg prompt "$prompt" --arg content "$content" '{ | |
model: "mistral-small-latest", | |
messages: [ | |
{ | |
role: "user", | |
content: ($prompt + $content) | |
} | |
] | |
}') | |
local response=$(curl --location "$api_url" \ | |
--header 'Content-Type: application/json' \ | |
--header 'Accept: application/json' \ | |
--header "Authorization: Bearer $api_key" \ | |
--data "$json_data" -s) | |
echo "$response" | sed "s/\n/\\n/g" | jq -r '.choices[0].message.content' | |
} | |
content=$(get_safari_content) | |
summary=$(summarize_content "$content") | |
echo "$summary" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment