fix loading
This commit is contained in:
@ -20,5 +20,5 @@ VITE_AI_ASK_AI=true
|
|||||||
VITE_AI_PROVIDER=ollama
|
VITE_AI_PROVIDER=ollama
|
||||||
VITE_AI_MODEL=gemma3:4b
|
VITE_AI_MODEL=gemma3:4b
|
||||||
VITE_AI_HOST=https://ollama.syui.ai
|
VITE_AI_HOST=https://ollama.syui.ai
|
||||||
VITE_AI_SYSTEM_PROMPT="You are a helpful AI assistant trained on this blog's content. You can answer questions about the articles, provide insights, and help users understand the topics discussed."
|
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||||
VITE_AI_DID=did:plc:4hqjfn7m6n5hno3doamuhgef
|
VITE_AI_DID=did:plc:4hqjfn7m6n5hno3doamuhgef
|
||||||
|
@ -40,13 +40,17 @@ export const AIChat: React.FC<AIChatProps> = ({ user, isEnabled }) => {
|
|||||||
console.log('Fetching AI profile with agent for DID:', aiConfig.aiDid);
|
console.log('Fetching AI profile with agent for DID:', aiConfig.aiDid);
|
||||||
const profile = await agent.getProfile({ actor: aiConfig.aiDid });
|
const profile = await agent.getProfile({ actor: aiConfig.aiDid });
|
||||||
console.log('AI profile fetched successfully:', profile.data);
|
console.log('AI profile fetched successfully:', profile.data);
|
||||||
setAiProfile({
|
const profileData = {
|
||||||
did: aiConfig.aiDid,
|
did: aiConfig.aiDid,
|
||||||
handle: profile.data.handle || 'ai-assistant',
|
handle: profile.data.handle || 'ai-assistant',
|
||||||
displayName: profile.data.displayName || 'AI Assistant',
|
displayName: profile.data.displayName || 'AI Assistant',
|
||||||
avatar: profile.data.avatar || null,
|
avatar: profile.data.avatar || null,
|
||||||
description: profile.data.description || null
|
description: profile.data.description || null
|
||||||
});
|
};
|
||||||
|
setAiProfile(profileData);
|
||||||
|
|
||||||
|
// Dispatch event to update Ask AI button
|
||||||
|
window.dispatchEvent(new CustomEvent('aiProfileLoaded', { detail: profileData }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,24 +60,32 @@ export const AIChat: React.FC<AIChatProps> = ({ user, isEnabled }) => {
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const profileData = await response.json();
|
const profileData = await response.json();
|
||||||
console.log('AI profile fetched via public API:', profileData);
|
console.log('AI profile fetched via public API:', profileData);
|
||||||
setAiProfile({
|
const profile = {
|
||||||
did: aiConfig.aiDid,
|
did: aiConfig.aiDid,
|
||||||
handle: profileData.handle || 'ai-assistant',
|
handle: profileData.handle || 'ai-assistant',
|
||||||
displayName: profileData.displayName || 'AI Assistant',
|
displayName: profileData.displayName || 'AI Assistant',
|
||||||
avatar: profileData.avatar || null,
|
avatar: profileData.avatar || null,
|
||||||
description: profileData.description || null
|
description: profileData.description || null
|
||||||
});
|
};
|
||||||
|
setAiProfile(profile);
|
||||||
|
|
||||||
|
// Dispatch event to update Ask AI button
|
||||||
|
window.dispatchEvent(new CustomEvent('aiProfileLoaded', { detail: profile }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Failed to fetch AI profile, using defaults:', error);
|
console.log('Failed to fetch AI profile, using defaults:', error);
|
||||||
setAiProfile({
|
const fallbackProfile = {
|
||||||
did: aiConfig.aiDid,
|
did: aiConfig.aiDid,
|
||||||
handle: 'ai-assistant',
|
handle: 'ai-assistant',
|
||||||
displayName: 'AI Assistant',
|
displayName: 'AI Assistant',
|
||||||
avatar: null,
|
avatar: null,
|
||||||
description: 'AI assistant for this blog'
|
description: 'AI assistant for this blog'
|
||||||
});
|
};
|
||||||
|
setAiProfile(fallbackProfile);
|
||||||
|
|
||||||
|
// Dispatch event even with fallback profile
|
||||||
|
window.dispatchEvent(new CustomEvent('aiProfileLoaded', { detail: fallbackProfile }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -178,11 +190,9 @@ export const AIChat: React.FC<AIChatProps> = ({ user, isEnabled }) => {
|
|||||||
if (aiConfig.provider === 'ollama') {
|
if (aiConfig.provider === 'ollama') {
|
||||||
const prompt = `${aiConfig.systemPrompt}
|
const prompt = `${aiConfig.systemPrompt}
|
||||||
|
|
||||||
${chatHistoryText ? `履歴: ${chatHistoryText}` : ''}
|
Question: ${question}
|
||||||
|
|
||||||
質問: ${question}
|
Answer:`;
|
||||||
|
|
||||||
簡潔に回答:`;
|
|
||||||
|
|
||||||
const response = await fetch(`${aiConfig.host}/api/generate`, {
|
const response = await fetch(`${aiConfig.host}/api/generate`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -194,9 +204,10 @@ ${chatHistoryText ? `履歴: ${chatHistoryText}` : ''}
|
|||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
stream: false,
|
stream: false,
|
||||||
options: {
|
options: {
|
||||||
temperature: 0.7,
|
temperature: 0.9,
|
||||||
top_p: 0.9,
|
top_p: 0.9,
|
||||||
num_predict: 80, // Shorter responses for faster generation
|
num_predict: 80, // Shorter responses for faster generation
|
||||||
|
repeat_penalty: 1.1,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@ -210,7 +221,6 @@ ${chatHistoryText ? `履歴: ${chatHistoryText}` : ''}
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 4. Immediately dispatch event to update UI
|
// 4. Immediately dispatch event to update UI
|
||||||
console.log('Dispatching AI response with profile:', aiProfile);
|
|
||||||
window.dispatchEvent(new CustomEvent('aiResponseReceived', {
|
window.dispatchEvent(new CustomEvent('aiResponseReceived', {
|
||||||
detail: {
|
detail: {
|
||||||
answer: aiAnswer,
|
answer: aiAnswer,
|
||||||
|
5
run.zsh
5
run.zsh
@ -18,7 +18,6 @@ function _env() {
|
|||||||
|
|
||||||
function _server() {
|
function _server() {
|
||||||
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
lsof -ti:$port | xargs kill -9 2>/dev/null || true
|
||||||
lsof -ti:11434 | xargs kill -9 2>/dev/null || true
|
|
||||||
cd $d/my-blog
|
cd $d/my-blog
|
||||||
cargo build --release
|
cargo build --release
|
||||||
$ailog build
|
$ailog build
|
||||||
@ -46,6 +45,7 @@ function _server_comment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _server_ollama(){
|
function _server_ollama(){
|
||||||
|
lsof -ti:11434 | xargs kill -9 2>/dev/null || true
|
||||||
brew services stop ollama
|
brew services stop ollama
|
||||||
OLLAMA_ORIGINS="https://log.syui.ai" ollama serve
|
OLLAMA_ORIGINS="https://log.syui.ai" ollama serve
|
||||||
}
|
}
|
||||||
@ -65,9 +65,6 @@ case "${1:-serve}" in
|
|||||||
ollama|ol)
|
ollama|ol)
|
||||||
_server_ollama
|
_server_ollama
|
||||||
;;
|
;;
|
||||||
proxy|p)
|
|
||||||
_server_proxy
|
|
||||||
;;
|
|
||||||
serve|s|*)
|
serve|s|*)
|
||||||
_server
|
_server
|
||||||
;;
|
;;
|
||||||
|
Reference in New Issue
Block a user