Skip to content

Commit

Permalink
added /clear command to purge history
Browse files Browse the repository at this point in the history
  • Loading branch information
mjfelis committed Nov 11, 2024
1 parent 1933b84 commit e7ffd66
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
@DynamicInsert
@NamedQueries({
@NamedQuery(name="History.find", query="SELECT h FROM History h where h.session=:session order by h.ts desc"),
@NamedQuery(name="History.delete", query="DELETE FROM History h where h.session=:session"),

})
public class History implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;
import jakarta.transaction.Transactional;


Expand Down Expand Up @@ -154,6 +155,8 @@ public class Service {

private static String CMD_ROOT_MENU_SET_MODEL = "/set";

private static String CMD_ROOT_MENU_CLEAR = "/clear";




Expand Down Expand Up @@ -504,7 +507,19 @@ public void userInput(BaseMessage message) throws Exception {
}
mtProducer.sendMessage(TextMessage.build(message.getConnectionId(), message.getThreadId() , this.getMessage("UNAUTHENTICATED")));

} else if (contextual && (content.startsWith(CMD_ROOT_MENU_SET_MODEL.toString()))) {
} else if (content.equals(CMD_ROOT_MENU_CLEAR.toString())) {

if (session != null) {
Query q = em.createNamedQuery("History.delete");
q.setParameter("session", session);
q.executeUpdate();

}

mtProducer.sendMessage(TextMessage.build(message.getConnectionId(), message.getThreadId() , this.getMessage("CLEANED_HISTORY")));

}
else if (contextual && (content.startsWith(CMD_ROOT_MENU_SET_MODEL.toString()))) {

content = content.replaceAll(CMD_ROOT_MENU_SET_MODEL.toString(), "").strip();

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/resources/Messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ USAGE=Ask me something.
ERROR_NOT_AUTHENTICATED=You need to prove you're human to use this service. Check the contextual menu and authenticate yourself.
CMD_ROOT_MENU_SET_MODEL_TEXT=Switch to MODEL model
SET_MODEL=Model set to MODEL. Use the contextual menu to switch to another model.
SET_MODEL_ERROR=Model MODEL not available in ollama service. Use the contextual menu to switch to another model.
SET_MODEL_ERROR=Model MODEL not available in ollama service. Use the contextual menu to switch to another model.
CLEANED_HISTORY=Cleaned history.
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/resources/Messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ USAGE=Pregúntame algo.
ERROR_NOT_AUTHENTICATED=Debes demostrar eres hunamo para usar este servicio. Accede al menú contextual para ver las opciones disponibles.
CMD_ROOT_MENU_SET_MODEL_TEXT=Usar el modelo MODEL
SET_MODEL=Modelo seleccionado: MODEL. Usar el menú contextual para cambiar de modelo.
SET_MODEL_ERROR=Modelo MODEL no disponible en el servidor ollama. Usar el menú contextual para cambiar de modelo.
SET_MODEL_ERROR=Modelo MODEL no disponible en el servidor ollama. Usar el menú contextual para cambiar de modelo.
CLEANED_HISTORY=Historial borrado.
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/resources/Messages_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ USAGE=Pose moi une question.
ERROR_NOT_AUTHENTICATED=Vous devez prouver que vous êtes humain pour utiliser ce service. Veuillez lancer l'autentication depuis le menu contextuel.
CMD_ROOT_MENU_SET_MODEL_TEXT=Utiliser le modèle MODEL
SET_MODEL=Modèle selectionné: MODEL. Utiliser le menu contextuel pour changer de modèle.
SET_MODEL_ERROR=Le modèle MODEL n'est pas disponible sur le serveur ollama. Utiliser le menu contextuel pour changer de modèle.
SET_MODEL_ERROR=Le modèle MODEL n'est pas disponible sur le serveur ollama. Utiliser le menu contextuel pour changer de modèle.
CLEANED_HISTORY=J'ai tout oublié.

0 comments on commit e7ffd66

Please sign in to comment.