-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from CrawKatt/dev
Dev
- Loading branch information
Showing
9 changed files
with
156 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ pub mod moderation; | |
pub mod audio; | ||
pub mod info; | ||
pub mod lessons; | ||
pub mod ai; | ||
pub mod ai; | ||
pub mod translate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use crate::utils::{CommandResult, Context}; | ||
use openai_api_rs::v1::api::Client; | ||
use openai_api_rs::v1::chat_completion; | ||
use openai_api_rs::v1::chat_completion::ChatCompletionRequest; | ||
use poise::CreateReply; | ||
use serenity::all::{ButtonStyle, CreateButton}; | ||
use serenity::builder::CreateActionRow; | ||
use crate::utils::debug::IntoUnwrapResult; | ||
|
||
const SYSTEM_PROMPT: &str = | ||
"Eres un traductor multilingüe que convierte texto de un idioma a otro. Responde únicamente\ | ||
con la traducción exacta del texto proporcionado, utilizando el alfabeto nativo del idioma de salida.\ | ||
No uses transliteraciones (como romanji en japonés) ni caracteres que no sean propios del idioma de salida.\ | ||
La respuesta debe ser limpia, sin paréntesis, notas, ni comentarios adicionales. Ejemplo:\ | ||
Texto de entrada: 'Hola, ¿cómo estás?'\ | ||
Traducción esperada (japonés): 'こんにちは、お元気ですか?'\ | ||
Traducción incorrecta: 'Konnichiwa, ogenki desu ka?'"; | ||
|
||
#[poise::command( | ||
prefix_command, | ||
slash_command, | ||
guild_only, | ||
category = "Info", | ||
aliases("tr"), | ||
guild_cooldown = 15, | ||
)] | ||
pub async fn translate( | ||
ctx: Context<'_>, | ||
lang: String, | ||
#[description = "Texto a enviar al modelo de IA"] | ||
#[rest] | ||
prompt: String | ||
) -> CommandResult { | ||
let loading = ctx.say("Cargando...").await?; | ||
let url = dotenvy::var("OPENAI_API_BASE")?; | ||
let api_key = dotenvy::var("OPENAI_API_KEY")?; | ||
let model = dotenvy::var("AI_MODEL")?; | ||
let client = Client::new_with_endpoint(url, api_key); | ||
|
||
let req = ChatCompletionRequest::new( | ||
model, | ||
vec![ | ||
chat_completion::ChatCompletionMessage { | ||
role: chat_completion::MessageRole::system, | ||
content: chat_completion::Content::Text(format!("{SYSTEM_PROMPT}. Idioma de salida: {lang}")), | ||
name: None, | ||
}, | ||
chat_completion::ChatCompletionMessage { | ||
role: chat_completion::MessageRole::user, | ||
content: chat_completion::Content::Text(prompt), | ||
name: None, | ||
} | ||
], | ||
).max_tokens(1024); | ||
|
||
let result = client.chat_completion(req)?; | ||
let message = result.choices[0].message.content.as_ref().into_result()?; | ||
|
||
let action_row = vec![CreateActionRow::Buttons(vec![ | ||
CreateButton::new("close") | ||
.style(ButtonStyle::Danger) | ||
.label("Cerrar") | ||
]) | ||
]; | ||
|
||
let reply = CreateReply::default() | ||
.content(message) | ||
.components(action_row); | ||
|
||
loading.edit(ctx, reply).await?; | ||
|
||
Ok(()) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.