aboutsummaryrefslogtreecommitdiffstats
path: root/crates/asist-llm/src/chat.rs
diff options
context:
space:
mode:
authorelvis <elvis@claros.ar>2026-09-26 20:20:19 -0300
committerelvis <elvis@claros.ar>2026-09-26 20:20:19 -0300
commit8518a63f55153e7f45fd49ad6caff5555f4e374f (patch)
tree636684eea3fa6f35d78282ab95eb687ef49154af /crates/asist-llm/src/chat.rs
parent69de76dc9cbedc6092d1e5ce84094a8030de1470 (diff)
downloadasist-p-main.tar.gz
asist-p-main.zip
Translate code, comments, logs and terminal UI to English; add English README; rename scriptsHEADmain
Diffstat (limited to 'crates/asist-llm/src/chat.rs')
-rw-r--r--crates/asist-llm/src/chat.rs46
1 files changed, 23 insertions, 23 deletions
diff --git a/crates/asist-llm/src/chat.rs b/crates/asist-llm/src/chat.rs
index 01a9a74..d8fa1f5 100644
--- a/crates/asist-llm/src/chat.rs
+++ b/crates/asist-llm/src/chat.rs
@@ -1,4 +1,4 @@
-//! Historial de conversación en el formato que espera la API de chat.
+//! Conversation history in the format the chat API expects.
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
@@ -29,9 +29,9 @@ impl Role {
pub struct Message {
pub role: Role,
pub content: String,
- /// Herramientas que el asistente pidió en este turno.
+ /// Tools the assistant asked for in this turn.
pub tool_calls: Vec<ToolCall>,
- /// Para los mensajes de rol `tool`: a qué llamada responden.
+ /// For `tool` role messages: which call they answer.
pub tool_call_id: Option<String>,
}
@@ -57,7 +57,7 @@ impl Message {
}
}
- /// Turno del asistente que en vez de hablar pidió herramientas.
+ /// Assistant turn that asked for tools instead of speaking.
pub fn tool_request(content: String, tool_calls: Vec<ToolCall>) -> Self {
Self {
role: Role::Assistant,
@@ -67,7 +67,7 @@ impl Message {
}
}
- /// Resultado devuelto al modelo.
+ /// Result handed back to the model.
pub fn tool_result(outcome: &ToolOutcome) -> Self {
Self {
role: Role::Tool,
@@ -100,8 +100,8 @@ impl Message {
}
}
-/// Historial con la instrucción de sistema fija y una ventana deslizante de
-/// turnos, para que la conversación no crezca sin fin.
+/// History with a fixed system prompt and a sliding window of turns, so
+/// the conversation does not grow without end.
#[derive(Debug, Clone)]
pub struct Conversation {
system: Message,
@@ -118,11 +118,11 @@ impl Conversation {
}
}
- /// Cambia la instrucción de sistema sin tocar el historial.
+ /// Changes the system prompt without touching the history.
///
- /// El turno alterna entre la guía de herramientas y la de estilo, y el
- /// historial tiene que sobrevivir al cambio: si se reiniciara, el modelo
- /// perdería los resultados que acaba de pedir.
+ /// The turn alternates between the tool guide and the style guide, and the
+ /// history must survive the switch: if it were reset, the model would lose
+ /// the results it just asked for.
pub fn set_system(&mut self, prompt: &str) {
self.system = Message::system(prompt);
}
@@ -137,9 +137,9 @@ impl Conversation {
self.trim();
}
- /// Recorta a `max_turns` intervenciones de usuario, sin dejar nunca un
- /// mensaje de rol `tool` huérfano al principio: la API lo rechaza si no
- /// va precedido de la llamada que lo originó.
+ /// Trims to `max_turns` user utterances, never leaving an orphan `tool`
+ /// role message at the start: the API rejects it unless it comes right
+ /// after the call that caused it.
fn trim(&mut self) {
if self.max_turns == 0 {
self.turns.clear();
@@ -187,7 +187,7 @@ mod tests {
use super::*;
#[test]
- fn la_instruccion_de_sistema_va_siempre_delante() {
+ fn system_prompt_always_goes_first() {
let mut chat = Conversation::new("sé breve", 4);
chat.push(Message::user("hola"));
let json = chat.to_json();
@@ -197,7 +197,7 @@ mod tests {
}
#[test]
- fn cambiar_la_instruccion_de_sistema_conserva_el_historial() {
+ fn changing_the_system_prompt_keeps_the_history() {
let mut chat = Conversation::new("primera", 4);
chat.push(Message::user("hola"));
chat.set_system("segunda");
@@ -205,12 +205,12 @@ mod tests {
assert_eq!(json[0]["content"], "segunda");
assert_eq!(
json[1]["content"], "hola",
- "el historial no puede perderse al cambiar"
+ "the history must not be lost on the switch"
);
}
#[test]
- fn el_historial_se_recorta_por_turnos_de_usuario() {
+ fn history_is_trimmed_by_user_turns() {
let mut chat = Conversation::new("s", 2);
for i in 0..5 {
chat.push(Message::user(format!("p{i}")));
@@ -226,9 +226,9 @@ mod tests {
}
#[test]
- fn el_recorte_no_deja_un_resultado_de_herramienta_huerfano() {
- // La API rechaza un mensaje `tool` que no venga detrás de la llamada
- // que lo pidió, así que el corte tiene que caer en un turno de usuario.
+ fn trimming_does_not_orphan_a_tool_result() {
+ // The API rejects a `tool` message that does not follow the call that
+ // asked for it, so the cut must land on a user turn.
let mut chat = Conversation::new("s", 1);
chat.push(Message::user("p0"));
chat.push(Message::tool_request(
@@ -252,14 +252,14 @@ mod tests {
}
#[test]
- fn con_cero_turnos_no_hay_memoria() {
+ fn zero_turns_means_no_memory() {
let mut chat = Conversation::new("s", 0);
chat.push(Message::user("hola"));
assert_eq!(chat.messages().len(), 1);
}
#[test]
- fn una_llamada_a_herramienta_se_serializa_como_espera_la_api() {
+ fn tool_call_is_serialized_as_the_api_expects() {
let message = Message::tool_request(
String::new(),
vec![ToolCall {