Skip to content

Commit

Permalink
ollama compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
BorjaOteroFerreira committed Mar 10, 2024
1 parent d7e5031 commit 575c9f2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
19 changes: 8 additions & 11 deletions FlaskApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,16 @@ def setup_routes(self):
self.app.route('/load_model', methods=['POST'])(self.load_model)
self.app.route('/unload_model', methods=['POST'])(self.unload_model)
self.app.route('/stop_response', methods=['POST'])(self.stop_response)
self.app.route('/v1/chat/completions', methods=['POST'])(self.crew_response)
self.app.route('/v1/chat/completions', methods=['POST'])(self.ollama)


def crew_response(self):
try:
request_data = request.json
chat_history = request_data.get('messages', [])
print("Usuario dijo:", chat_history)
response = self.assistant.model.create_chat_completion(chat_history,stream=True)
return response

except Exception as e:
print(f"Error in handle_user_input_route: {e}")
def ollama(self):
request_data = request.json # Obtener los datos JSON del cuerpo de la solicitud
user_input = request_data.get('content')
user_input.pop(0) # Elimina el mensaje del sistema
self.assistant.emit_ollama_response_stream(user_input,self.socketio)
print(f'\n\nInput Usuario: {user_input}\n\n')
return 'Response finished'


def before_first_request(self):
Expand Down
1 change: 0 additions & 1 deletion appGUI.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import sys
from PyQt5 import *
from PyQt5.QtCore import Qt, QUrl
Expand Down
13 changes: 0 additions & 13 deletions static/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ class Chat {
console.error('Error al cargar el historial:', error); // Imprime el mensaje de error en la consola
}
});

}


loadMessages(){
const self = this;
$('#chat-list').empty();
Expand Down Expand Up @@ -159,11 +157,6 @@ class Chat {
if (self.chatId === nombreChat){
self.clearChat();
}





},
error: function(xhr, status, error) {
console.error(`Error al eliminar el historial ${nombreChat}: ${xhr.status}`);
Expand All @@ -172,7 +165,6 @@ class Chat {

}


removeFromConversationList(chatId) {
// Eliminar el elemento de la lista de conversaciones
const conversationListDiv = $('#conversations-list');
Expand Down Expand Up @@ -341,12 +333,9 @@ class Chat {
var userMessageCointainer = $('.assistant-message-container-' + this.n_responses);
userMessageCointainer.append(shareButton);
this.scrollToBottom();

}
}



addToConversationHistory() {
this.conversationHistory.push({'role': 'assistant', 'content': this.fullResponse});
this.fullResponse = '';
Expand Down Expand Up @@ -469,7 +458,6 @@ class Chat {


}

}
}

Expand Down Expand Up @@ -516,7 +504,6 @@ class Chat {
container.style.bottom = '20px';
document.body.appendChild(container);
}

const popup = document.createElement('div');
popup.className = 'popup-notification';
if (type === 'error') {
Expand Down

0 comments on commit 575c9f2

Please sign in to comment.