Update: перенастройка сайта что бы открывать 1 порт на сайт
This commit is contained in:
@@ -5,6 +5,7 @@ import React, { useState, useEffect, useRef } from 'react';
|
||||
import { CurrentView } from '../types';
|
||||
import { NAVIGABLE_VIEWS } from '../constants';
|
||||
import { ArrowUpIcon } from './icons';
|
||||
import { STRAPI_URL } from '../strapiService';
|
||||
|
||||
const PLACEHOLDERS = [
|
||||
"Создайте мне сайт для моего бизнеса",
|
||||
@@ -81,32 +82,35 @@ const ChatInput: React.FC<ChatInputProps> = ({ setCurrentView, isSticky = false,
|
||||
Your entire response must be only the JSON object, with no other text, explanation, or markdown formatting.`;
|
||||
|
||||
try {
|
||||
const response = await fetch('https://ai.iieasy.ru/v1/chat/completions', {
|
||||
// Запрос через прокси Strapi (/api/ollama/chat) — один origin с фронтом, нет CORS и работает из любой сети
|
||||
const response = await fetch(`${STRAPI_URL}/api/ollama/chat`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
model: 'local-model',
|
||||
model: 'gemma3n:e4b',
|
||||
messages: [
|
||||
{ role: 'system', content: systemInstruction },
|
||||
{ role: 'user', content: prompt }
|
||||
],
|
||||
temperature: 0.1,
|
||||
stream: false,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Ошибка сети: ${response.status} ${response.statusText}. Убедитесь, что сервер LM Studio запущен.`);
|
||||
throw new Error(`Ошибка сети: ${response.status} ${response.statusText}. Убедитесь, что бэкенд и Ollama доступны.`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.error) {
|
||||
throw new Error(`LM Studio вернула ошибку: ${data.error.message}`);
|
||||
throw new Error(`Сервер ИИ вернул ошибку: ${typeof data.error === 'string' ? data.error : data.error.message || 'неизвестная ошибка'}`);
|
||||
}
|
||||
|
||||
const responseJsonString = data.choices?.[0]?.message?.content;
|
||||
// Ответ Ollama в /api/chat (без стриминга):
|
||||
// { message: { role: 'assistant', content: '...' }, ... }
|
||||
const responseJsonString = data.message?.content;
|
||||
if (!responseJsonString) {
|
||||
throw new Error("LM Studio вернула пустой ответ.");
|
||||
throw new Error("Сервер ИИ вернул пустой ответ.");
|
||||
}
|
||||
|
||||
// More robust JSON extraction
|
||||
@@ -127,8 +131,8 @@ const ChatInput: React.FC<ChatInputProps> = ({ setCurrentView, isSticky = false,
|
||||
setError("К сожалению, я не смог понять ваш запрос. Попробуйте переформулировать.");
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error("Ошибка при обращении к LM Studio:", err);
|
||||
setError(err.message || "Произошла ошибка. Убедитесь, что сервер LM Studio запущен и модель загружена. Пожалуйста, попробуйте еще раз.");
|
||||
console.error("Ошибка при обращении к серверу ИИ (Ollama):", err);
|
||||
setError(err.message || "Произошла ошибка. Убедитесь, что бэкенд и сервер Ollama доступны. Пожалуйста, попробуйте еще раз.");
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user