You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

33 lines
854 B

use ai_core::ai::{generate as ai_generate, Params};
use anyhow::Context;
use axum::Json;
use serde::Deserialize;
use crate::{utils::AppError, CONFIG};
#[derive(Deserialize)]
pub struct GenerationPayload {
ai: String,
params: Params,
}
pub async fn generate(Json(payload): Json<GenerationPayload>) -> Result<String, AppError> {
let ai = CONFIG
.ai
.iter()
.filter(|ai| ai.name == payload.ai)
.next()
.context(format!("Failed to get AI with name {}!", payload.ai))?
.clone();
let res = ai_generate(ai, payload.params).await?;
Ok(res.trim().to_string())
}
pub async fn get_ais() -> Result<Json<serde_json::Value>, AppError> {
let ais: Vec<String> = CONFIG.ai.iter().map(|ai| ai.name.clone()).collect();
Ok(Json(serde_json::to_value(ais)?))
}