|
|
|
@ -1,6 +1,10 @@
|
|
|
|
|
use ai_core::ai::{generate as ai_generate, Params};
|
|
|
|
|
use ai_core::{
|
|
|
|
|
ai::{generate as ai_generate, Params},
|
|
|
|
|
history::{write_history, HistoryEntry, read_all_history},
|
|
|
|
|
};
|
|
|
|
|
use anyhow::Context;
|
|
|
|
|
use axum::Json;
|
|
|
|
|
use chrono::Local;
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
|
|
use crate::{utils::AppError, CONFIG};
|
|
|
|
@ -20,7 +24,19 @@ pub async fn generate(Json(payload): Json<GenerationPayload>) -> Result<String,
|
|
|
|
|
.context(format!("Failed to get AI with name {}!", payload.ai))?
|
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
|
|
let res = ai_generate(ai, payload.params).await?;
|
|
|
|
|
let res = ai_generate(ai.clone(), payload.params.clone()).await?;
|
|
|
|
|
|
|
|
|
|
if let Some(history_dir) = CONFIG.app.history_dir.clone() {
|
|
|
|
|
write_history(
|
|
|
|
|
HistoryEntry {
|
|
|
|
|
date: Local::now(),
|
|
|
|
|
selected_ai: ai.name,
|
|
|
|
|
params: payload.params,
|
|
|
|
|
result: res.clone(),
|
|
|
|
|
},
|
|
|
|
|
history_dir,
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(res.trim().to_string())
|
|
|
|
|
}
|
|
|
|
@ -30,3 +46,9 @@ pub async fn get_ais() -> Result<Json<serde_json::Value>, AppError> {
|
|
|
|
|
|
|
|
|
|
Ok(Json(serde_json::to_value(ais)?))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn get_history() -> Result<Json<Vec<HistoryEntry>>, AppError> {
|
|
|
|
|
let history_dir = CONFIG.app.history_dir.clone().context("No history dir has been specified!")?;
|
|
|
|
|
|
|
|
|
|
Ok(Json(read_all_history(history_dir)?))
|
|
|
|
|
}
|
|
|
|
|