This commit is contained in:
2025-06-19 15:17:51 +09:00
parent 50516fee21
commit 1b7d37243c
2 changed files with 59 additions and 15 deletions

View File

@@ -44,7 +44,7 @@ body {
.oauth-header-content { .oauth-header-content {
display: flex; display: flex;
justify-content: space-between; justify-content: center;
align-items: center; align-items: center;
max-width: 800px; max-width: 800px;
margin: 0 auto; margin: 0 auto;
@@ -52,6 +52,10 @@ body {
width: 100%; width: 100%;
} }
.oauth-header-content:has(.oauth-user-profile) {
justify-content: space-between;
}
.oauth-app-title { .oauth-app-title {
font-size: 20px; font-size: 20px;
font-weight: 800; font-weight: 800;
@@ -62,6 +66,12 @@ body {
display: flex; display: flex;
gap: 8px; gap: 8px;
align-items: center; align-items: center;
flex: 1;
}
/* When user is logged in, actions take normal space */
.oauth-header-content:has(.oauth-user-profile) .oauth-header-actions {
flex: 0 0 auto;
} }
/* OAuth User Profile in Header */ /* OAuth User Profile in Header */
@@ -195,6 +205,7 @@ body {
padding: 0; padding: 0;
gap: 0; gap: 0;
width: 100%; width: 100%;
max-width: 400px;
} }
.auth-section.search-bar-layout .handle-input { .auth-section.search-bar-layout .handle-input {
@@ -532,7 +543,7 @@ body {
} }
.user-message .message-content { .user-message .message-content {
color: white; color: #000;
} }
.question-form { .question-form {

View File

@@ -9,8 +9,12 @@ export function useAskAI(adminData, userProfile, agent) {
const [error, setError] = useState(null) const [error, setError] = useState(null)
const [chatHistory, setChatHistory] = useState([]) const [chatHistory, setChatHistory] = useState([])
// ask-AIサーバーのURL環境変数から取得、フォールバック付き // AI設定を環境変数から取得
const askAIUrl = import.meta.env.VITE_ASK_AI_URL || 'http://localhost:3000/ask' const aiConfig = {
host: import.meta.env.VITE_AI_HOST || 'https://ollama.syui.ai',
model: import.meta.env.VITE_AI_MODEL || 'gemma3:1b',
systemPrompt: import.meta.env.VITE_AI_SYSTEM_PROMPT || 'あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。'
}
const askQuestion = async (question) => { const askQuestion = async (question) => {
if (!question.trim()) return if (!question.trim()) return
@@ -19,28 +23,47 @@ export function useAskAI(adminData, userProfile, agent) {
setError(null) setError(null)
try { try {
logger.log('Sending question to ask-AI:', question) logger.log('Sending question to Ollama:', question)
// ask-AIサーバーにリクエスト送信 // Ollamaに直接リクエスト送信oauth_oldと同じ方式
const response = await fetch(askAIUrl, { const prompt = `${aiConfig.systemPrompt}
Question: ${question}
Answer:`
// Add timeout to fetch request
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), 30000) // 30 second timeout
const response = await fetch(`${aiConfig.host}/api/generate`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Origin': 'https://syui.ai',
}, },
body: JSON.stringify({ body: JSON.stringify({
question: question.trim(), model: aiConfig.model,
context: { prompt: prompt,
url: window.location.href, stream: false,
timestamp: new Date().toISOString() options: {
temperature: 0.9,
top_p: 0.9,
num_predict: 200, // Longer responses for better answers
repeat_penalty: 1.1,
} }
}),
signal: controller.signal
}) })
})
clearTimeout(timeoutId)
if (!response.ok) { if (!response.ok) {
throw new Error(`ask-AI server error: ${response.status}`) throw new Error(`Ollama API error: ${response.status}`)
} }
const aiResponse = await response.json() const data = await response.json()
const aiResponse = { answer: data.response || 'エラーが発生しました' }
logger.log('Received AI response:', aiResponse) logger.log('Received AI response:', aiResponse)
// AI回答をチャット履歴に追加 // AI回答をチャット履歴に追加
@@ -81,7 +104,17 @@ export function useAskAI(adminData, userProfile, agent) {
} catch (err) { } catch (err) {
logError(err, 'useAskAI.askQuestion') logError(err, 'useAskAI.askQuestion')
setError(getErrorMessage(err))
let errorMessage = 'AI応答の生成に失敗しました'
if (err.name === 'AbortError') {
errorMessage = 'AI応答がタイムアウトしました30秒'
} else if (err.message.includes('Ollama API error')) {
errorMessage = `Ollama API エラー: ${err.message}`
} else if (err.message.includes('Failed to fetch')) {
errorMessage = 'AI サーバーに接続できませんでした'
}
setError(errorMessage)
throw err throw err
} finally { } finally {
setLoading(false) setLoading(false)