add ask AI

This commit is contained in:
2025-06-13 15:01:08 +09:00
parent 962017f922
commit fb0e5107cf
14 changed files with 506 additions and 383 deletions

View File

@ -30,6 +30,7 @@ title = "My Blog"
description = "A blog powered by ailog"
base_url = "https://example.com"
language = "ja"
author = "Your Name"
[build]
highlight_code = true
@ -88,7 +89,7 @@ comment_moderation = false
</div>
<footer class="main-footer">
<p>&copy; 2025 {{ config.title }}</p>
<p>&copy; {{ config.author | default(value=config.title) }}</p>
</footer>
<script>

View File

@ -53,6 +53,39 @@ pub async fn build(project_dir: PathBuf) -> Result<()> {
.and_then(|v| v.as_str())
.unwrap_or("ai.syui.log.user");
let collection_chat = oauth_config.get("collection_chat")
.and_then(|v| v.as_str())
.unwrap_or("ai.syui.log.chat");
// Extract AI config if present
let ai_config = config.get("ai")
.and_then(|v| v.as_table());
let ai_enabled = ai_config
.and_then(|ai| ai.get("enabled"))
.and_then(|v| v.as_bool())
.unwrap_or(false);
let ai_ask_ai = ai_config
.and_then(|ai| ai.get("ask_ai"))
.and_then(|v| v.as_bool())
.unwrap_or(false);
let ai_provider = ai_config
.and_then(|ai| ai.get("provider"))
.and_then(|v| v.as_str())
.unwrap_or("ollama");
let ai_model = ai_config
.and_then(|ai| ai.get("model"))
.and_then(|v| v.as_str())
.unwrap_or("gemma2:2b");
let ai_host = ai_config
.and_then(|ai| ai.get("host"))
.and_then(|v| v.as_str())
.unwrap_or("https://ollama.syui.ai");
// 4. Create .env.production content
let env_content = format!(
r#"# Production environment variables
@ -64,10 +97,19 @@ VITE_ADMIN_DID={}
# Collection names for OAuth app
VITE_COLLECTION_COMMENT={}
VITE_COLLECTION_USER={}
VITE_COLLECTION_CHAT={}
# Collection names for ailog (backward compatibility)
AILOG_COLLECTION_COMMENT={}
AILOG_COLLECTION_USER={}
AILOG_COLLECTION_CHAT={}
# AI Configuration
VITE_AI_ENABLED={}
VITE_AI_ASK_AI={}
VITE_AI_PROVIDER={}
VITE_AI_MODEL={}
VITE_AI_HOST={}
"#,
base_url,
base_url, client_id_path,
@ -75,8 +117,15 @@ AILOG_COLLECTION_USER={}
admin_did,
collection_comment,
collection_user,
collection_chat,
collection_comment,
collection_user
collection_user,
collection_chat,
ai_enabled,
ai_ask_ai,
ai_provider,
ai_model,
ai_host
);
// 5. Find oauth directory (relative to current working directory)

View File

@ -17,6 +17,7 @@ pub struct SiteConfig {
pub description: String,
pub base_url: String,
pub language: String,
pub author: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
@ -30,6 +31,12 @@ pub struct AiConfig {
pub enabled: bool,
pub auto_translate: bool,
pub comment_moderation: bool,
pub ask_ai: Option<bool>,
pub provider: Option<String>,
pub model: Option<String>,
pub host: Option<String>,
pub system_prompt: Option<String>,
pub ai_did: Option<String>,
pub api_key: Option<String>,
pub gpt_endpoint: Option<String>,
pub atproto_config: Option<AtprotoConfig>,
@ -135,6 +142,7 @@ impl Default for Config {
description: "A blog powered by ailog".to_string(),
base_url: "https://example.com".to_string(),
language: "ja".to_string(),
author: None,
},
build: BuildConfig {
highlight_code: true,
@ -144,6 +152,12 @@ impl Default for Config {
enabled: false,
auto_translate: false,
comment_moderation: false,
ask_ai: Some(false),
provider: Some("ollama".to_string()),
model: Some("gemma3:4b".to_string()),
host: None,
system_prompt: Some("You are a helpful AI assistant trained on this blog's content.".to_string()),
ai_did: None,
api_key: None,
gpt_endpoint: None,
atproto_config: None,