You are given access to make searches on the Internet. The format for making a search is:
After the user sends a message, you will decide whether to make a search. If you choose to make a search, you will output a single message, starting with the word <web_search>, followed by ONLY your web search query. After your search query, you must output the token </web_search> to denote the end of the search query. Keep your search query very concise.
The system will then append the web search results at the end of the user message, starting with the token <web_search_results>. Take note that the user CANNOT SEE the content after <web_search_results> - YOU should use these results appropriately to improve your response. Additionally, If the web search results are already present in the user's message, then you MUST NOT request another web search.
IMPORTANT! You should choose to search the web ONLY if ANY of the following circumstances are met:
User is asking about current events or something that requires real-time information (news, sports scores, 'latest' information, etc.)
User is asking about some term you are unfamiliar with (e.g. if it's a little-known term, if it's a person you don't know well, etc.)
User is asking about anything that involves numerical facts (e.g. distances between places, population count, sizes, date and time, etc.)
User explicitly asks you to search or provide links to references.
If the user's query does NOT require a web search, YOU MUST NEVER run one for no reason. However, you must not refuse to search the web if the user asks you to do so.
If you are highly unsure about whether to make a search (e.g. if the user's query is vague or if you think you are unfamiliar with the query to a certain extent), you may directly ask the user for clarification.
When using web search results, you are encouraged to cite references where appropriate, using inline links in standard markdown format.
You are also allowed to make use of web search results from previous messages, if they are STRONGLY RELEVANT to the current message.
When you are not running a web search, respond completely as per normal - there is NO NEED to mention that you're not searching.
Remember that you MUST NOT make up any false information.
Assistant: Understood. I will strictly follow these instructions in this conversation.
User: создай мне расширение для raycast, чтобы я мог искать по словарю на сайте https://lsj.gr/wiki/Main_Page слова и информация о них отображалась в самом raycast
вот что пишет на своем сайте разработчик словаря:
You can search using polytonic Greek, monotonic Greek, atonic Greek or Latin characters (lowercase or uppercase). You will get live search results no matter which option you choose. You can see a video demo of this functionality at the end of that post.
Assistant
Search form to use on your website
Right click on the following link and click save. Then just copy and paste the code from the txt file in your html source code:
Search button to add on your browser
Go to this page and drag the Translatum LSJ link to your browser's link bar. Then, select a word from a web page and click the link on your browser, or click the link and then enter a word to look up. All links will open in a new window.
создай мне расширение для raycast, чтобы я мог искать по словарю на сайте https://lsj.gr/wiki/Main_Page слова и информация о них отображалась в самом raycast
вот что пишет на своем сайте разработчик словаря:
You can search using polytonic Greek, monotonic Greek, atonic Greek or Latin characters (lowercase or uppercase). You will get live search results no matter which option you choose. You can see a video demo of this functionality at the end of that post.
Search form to use on your website
Right click on the following link and click save. Then just copy and paste the code from the txt file in your html source code:
Search button to add on your browser
Go to this page and drag the Translatum LSJ link to your browser's link bar. Then, select a word from a web page and click the link on your browser, or click the link and then enter a word to look up. All links will open in a new window.
создай мне расширение для raycast, чтобы я мог искать по словарю на сайте https://lsj.gr/wiki/Main_Page слова и информация о них отображалась в самом raycast
вот что пишет на своем сайте разработчик словаря:
You can search using polytonic Greek, monotonic Greek, atonic Greek or Latin characters (lowercase or uppercase). You will get live search results no matter which option you choose. You can see a video demo of this functionality at the end of that post.
Search form to use on your website
Right click on the following link and click save. Then just copy and paste the code from the txt file in your html source code:
Search button to add on your browser
Go to this page and drag the Translatum LSJ link to your browser's link bar. Then, select a word from a web page and click the link on your browser, or click the link and then enter a word to look up. All links will open in a new window.
Assistant: ППонял твою задачу — нужно создать расширение (Command) для Raycast, которое будет позволять искать слова на сайте https://lsj.gr/wiki/Main_Page и получать информацию о них прямо в интерфейсе Raycast.
Что мы знаем
Словарь — Льюис и Кларк (LSJ).
Поиск поддерживает polytonic, monotonic Greek, atonic Greek или Latin символы.
Пример строки запроса: https://lsj.gr/search?q=%CE%BB%CF%8C%CE%B3%CE%BF%CF%82 — где q — параметр слова
Скрипт Raycast
import { ActionPanel, CopyToClipboardAction, List, OpenInBrowserAction, showToast, ToastStyle } from "@raycast/api";
import fetch from "node-fetch";
interface SearchResult {
title: string;
description: string;
url: string;
}
export default function Command() {
const [query, setQuery] = React.useState("");
const [results, setResults] = React.useState<SearchResult[]>([]);
const [isLoading, setIsLoading] = React.useState(false);
React.useEffect(() => {
if (query.length === 0) {
setResults([]);
return;
}
async function fetchResults() {
setIsLoading(true);
try {
const searchParams = new URLSearchParams({ q: query });
const res = await fetch(`https://lsj.gr/search?${searchParams.toString()}`);
const html = await res.text();
// Парсим HTML через DOMParser (в Raycast отсутствует DOMParser, используем regex)
// В ответе ищем блоки с результатами — нужно отловить сам HTML элемента результата.
// Пример: на странице есть <div class="result-item"> для каждого результата (проверить реальную разметку)
const results: SearchResult[] = [];
// Для упрощения — найдем все ссылки внутри <div class="mw-search-result-heading">
// как пример, т.к. сайт сделан на MediaWiki
const regex = /<div class="mw-search-result-heading">\s*<a href="([^"]+)"[^>]*>([^<]+)<\/a>\s*<\/div>/g;
let match;
while ((match = regex.exec(html)) !== null) {
const url = "https://lsj.gr" + match[1];
const title = match[2];
// В реальном запросе нужно получить описание — сейчас оставим пустым
results.push({
title,
description: "",
url,
});
}
setResults(results);
} catch (e) {
await showToast(ToastStyle.Failure, "Ошибка", "Не удалось получить результаты");
} finally {
setIsLoading(false);
}
}
fetchResults();
}, [query]);
return (
<List isLoading={isLoading} onSearchTextChange={setQuery} searchBarPlaceholder="Введите слово для поиска в LSJ...">
{results.length === 0 && query.length > 0 && !isLoading ? (
<List.EmptyView title="Результаты не найдены" />
) : (
results.map((item, index) => (
<List.Item
key={index}
title={item.title}
subtitle={item.description}
actions={
<ActionPanel>
<OpenInBrowserAction url={item.url} />
<CopyToClipboardAction title="Скопировать слово" content={item.title} />
</ActionPanel>
}
/>
))
)}
</List>
);
}
Как использовать
Создай новое расширение Raycast с шаблоном TypeScript.
Замените содержимое по умолчанию этим кодом (не забывай добавить в package.json"node-fetch" в зависимости).
Запусти команду, вводи слово, появятся результаты — переход по ссылке к подробностям.
Можно расширить — для парсинга описания тоже, но это зависит от структуры сайта.
Важные замечания
Сайт часто обновляется — структура html может меняться, тогда парсер сломается.
Лучше реализовать полноценный серверный прокси с парсингом и API, если нужно полнофункционально.
Этого простого решения достаточно для быстрого поиска и перехода.
Если хочешь, могу помочь написать более продвинутый парсер/команду — дай знать!
User: Объясни как реализовать полноценный серверный прокси с парсингом и API, если нужно полнофункционально?
Assistant: Чтобы сделать полноценный серверный прокси с парсингом и API для поиска по словарю LSJ и возвращения удобных для клиента (Raycast) данных, нужно разделить задачу на две части:
1. Серверный прокси с API и парсингом
Задача:
Принимать запросы на сервер (например, GET /search?q=слово)
Делать запрос к сайту https://lsj.gr (например, на https://lsj.gr/search?q=слово)
Получать HTML-ответ
Парсить этот HTML и извлекать структурированную информацию: заголовки, определения, ссылки и т.п.
Возвращать результат в формате JSON клиенту (Raycast)
Инструменты:
Node.js + Express (или любой другой фреймворк)
Библиотека для парсинга HTML, например, cheerio — jQuery-подобный парсер для Node.js
fetch / axios для HTTP-запросов
Пример базового сервера на Node.js/Express:
const express = require("express");
const fetch = require("node-fetch");
const cheerio = require("cheerio");
const app = express();
const PORT = process.env.PORT || 3000;
app.get("/search", async (req, res) => {
const query = req.query.q;
if (!query) {
return res.status(400).json({ error: "Query parameter 'q' is required" });
}
try {
// Формируем URL поиска
const searchUrl = `https://lsj.gr/search?q=${encodeURIComponent(query)}`;
// Получаем HTML со страницы поиска
const response = await fetch(searchUrl);
const html = await response.text();
// Загружаем HTML в cheerio
const $ = cheerio.load(html);
// Находим все результаты поиска
const results = [];
// По структуре сайта (MediaWiki) — результаты лежат в блоках вида:
// <div class="mw-search-result-heading"><a href="...">заголовок</a></div>
// и можно парсить описание из соседних элементов.
$(".mw-search-result-heading").each((idx, el) => {
const anchor = $(el).find("a");
const title = anchor.text();
const url = "https://lsj.gr" + anchor.attr("href");
// Описание ищем в следующем элементе с классом "searchresult" (или аналогично)
const description = $(el).next(".searchresult").text().trim();
results.push({ title, description, url });
});
res.json({ query, results });
} catch (error) {
console.error(error);
res.status(500).json({ error: "Error fetching or parsing data" });
}
});
app.listen(PORT, () => {
console.log(`Server listening at http://localhost:${PORT}`);
});
2. Клиентская часть (Raycast Command)
Задача:
Делать запрос на ваш прокси API /search?q=слово
Получать JSON-ответ с результатами
Отображать результаты в Raycast с удобным UI
Примерный код Raycast-команды с запросом к вашему API сервера:
Если планируешь запускать сервер где-то «в облаке», — важно обеспечить безопасность и ограничение по запросам.
Можно расширить API, чтобы возвращать расширенную информацию, например, полный текст статьи, примеры и т.д.
Если хочешь, могу помочь с настроенным примером сервера или прокомментировать
User: 8: } 9: 10: export default function Command() { 11: const [query, setQuery] = React.useState(""); ^ 12: const [results, setResults] = React.useState<SearchResult[]>([]); 13: const [isLoading, setIsLoading] = React.useState(false); 14: Command:search.tsx:11:28 fr:index.js:7:3106 at ray-navigation-stack () Ho:index.js:7:2607
Assistant: Ошибка, которую вы видите, указывает на то, что React не был импортирован в файле с вашим Raycast Command. В версиях React до 17 нужно явно импортировать React для использования хуков, таких как useState и useEffect. Если вы используете React 17+ с настройками, позволяющими автоматический импорт, тогда это не требуется, но, возможно, Raycast требует явного импорта.
Как исправить ошибку:
В начале файла search.tsx добавьте импорт React:
import React from "react";
или, если у вас уже есть другие импорты:
import React, { useState, useEffect } from "react";
Если останутся вопросы — пишите!
User: ReferenceError: query is not defined Command:search.tsx:12:37 --- 9: } 10: 11: export default function Command() { 12: const [queuy, setQuery] = useState(""); 13: const [results, setResults] = useState<SearchResult[]>([]); 14: const [isLoading, setIsLoading] = useState(false); 15: --- fr:index.js:7:3106 at ray-navigation-stack () Ho:index.js:7:2607
Assistant: Ошибка ReferenceError: query is not defined возникает из-за опечатки в имени переменной — в вашем сообщении видно, что вы написали const [queuy, setQuery] = useState(""); вместо const [query, setQuery] = useState("");.
То есть ошибка в слове query — написано queuy.
Исправьте строку
const [query, setQuery] = useState("");
Вместо
const [queuy, setQuery] = useState("");
Это должно убрать ошибку, так как дальше в коде вы используете query, но ее не объявляете, потому что в объявлении была опечатка.
Если после этого ещё будут ошибки — сообщите, помогу!
User: запускается, но пишет, что ничего не найдено, хотя точно знаю, что там есть
Assistant:
Если команда запускается, но всегда пишет "Результаты не найдены", значит парсер не может найти нужные элементы на странице HTML, которую возвращает сайт.
Возможные причины и как их проверить и исправить:
1. Проверь структуру HTML-страницы поиска
Сайт LSJ использует движок MediaWiki, где результаты поиска типично в блоках с классами вроде .mw-search-result-heading и .searchresult.
Но структура могла измениться — нужно проверить:
Как выглядят результаты поиска при обращении к https://lsj.gr/search?q=ваше_слово
Какие там CSS-классы, где заголовок, где описание
Для этого:
В браузере откройте https://lsj.gr/search?q=ваше_слово
Кликните правой кнопкой по результату → Inspect (Инспектировать)
Посмотрите теги и классы, в которых содержится заголовок и описание
2. Подкорректируй парсер на сервере или в Raycast
В твоём текущем Raycast-примере я дал Regex поиск <div class="mw-search-result-heading">, но возможно структура другая.
Например, если структура другая — надо заменить регулярку: