Widget:OllamaChat: различия между версиями

Материал из ultracity
Перейти к навигации Перейти к поиску
Нет описания правки
Нет описания правки
 
(не показаны 3 промежуточные версии этого же участника)
Строка 9: Строка 9:
             <option value="deepseek-r1:1.5b">DeepSeek-R1 1.5b (логическая)</option>
             <option value="deepseek-r1:1.5b">DeepSeek-R1 1.5b (логическая)</option>
         </select>
         </select>
        <span style="margin-left: 10px; font-size: 12px; color: #666;">
            Сервер: 82.148.28.75:11434
        </span>
         <div style="display: flex; gap: 10px; margin-top: 10px;">
         <div style="display: flex; gap: 10px; margin-top: 10px;">
             <input type="text" id="ollama-input" placeholder="Введите сообщение..." style="flex: 1; padding: 8px; border: 1px solid #ccc; border-radius: 4px;">
             <input type="text" id="ollama-input" placeholder="Введите сообщение..." style="flex: 1; padding: 8px; border: 1px solid #ccc; border-radius: 4px;">
Строка 25: Строка 22:
     const sendButton = document.getElementById('ollama-send');
     const sendButton = document.getElementById('ollama-send');
     const modelSelect = document.getElementById('ollama-model');
     const modelSelect = document.getElementById('ollama-model');
   
     const OLLAMA_URL = 'http://82.148.28.75:11434/api/generate';
     const OLLAMA_URL = '/ollama-proxy.php/api/generate';
      
      
     function addMessage(text, isUser) {
     function addMessage(text, isUser) {
Строка 106: Строка 103:
              
              
             let answer = data.response || 'Извините, не удалось получить ответ.';
             let answer = data.response || 'Извините, не удалось получить ответ.';
            // Для DeepSeek-R1 убираем внутренние рассуждения, если нужно
             if (modelSelect.value === 'deepseek-r1:1.5b') {
             if (modelSelect.value === 'deepseek-r1:1.5b') {
                 answer = answer.replace(/<thinking>[\s\S]*?<\/thinking>/g, '').trim();
                 answer = answer.replace(/<thinking>[\s\S]*?<\/thinking>/g, '').trim();
                if (!answer) answer = 'Ответ не сформирован.';
             }
             }
             addMessage(answer, false);
             addMessage(answer, false);
Строка 114: Строка 111:
         } catch (error) {
         } catch (error) {
             hideTyping();
             hideTyping();
             let errorMsg = 'Ошибка: ' + error.message;
             addMessage('❌ Ошибка: ' + error.message, false);
            if (error.message.includes('Failed to fetch')) {
                errorMsg = '❌ Ошибка: не удалось подключиться к серверу Ollama (82.148.28.75:11434).\n\nПроверьте:\n1. Доступность сервера: curl http://82.148.28.75:11434/api/tags\n2. Настройки CORS на сервере Ollama (нужно OLLAMA_ORIGINS="*")\n3. Брандмауэр и открытый порт 11434';
            } else if (error.message.includes('404')) {
                errorMsg = '❌ Модель "' + modelSelect.value + '" не найдена. Установите её командой: ollama pull ' + modelSelect.value;
            }
            addMessage(errorMsg, false);
         } finally {
         } finally {
             inputField.disabled = false;
             inputField.disabled = false;
Строка 133: Строка 124:
     });
     });
      
      
    // Фокус на поле ввода при загрузке
     inputField.focus();
     inputField.focus();
})();
})();

Текущая версия от 08:45, 25 марта 2026