Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
BorjaOteroFerreira committed Mar 12, 2024
1 parent e39f56f commit dadbebc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Assistant:
def __init__(self, default_model_path, default_chat_format):
self.model = None
self.max_context_tokens = 2048
self.max_assistant_tokens = 2048
self.max_assistant_tokens = 1024
self.is_processing = False
self.chat_format = default_chat_format
self.model_path = default_model_path
Expand Down Expand Up @@ -50,19 +50,19 @@ def load_default_model(self):
self.context_window_start = 0
self.stop_emit = False

def load_model(self, model_path, format, new_temperature, n_gpu_layer, new_system_message, context):
def load_model(self, model_path, format, new_temperature, n_gpu_layer, new_system_message, context,max_response_tokens):


message = new_system_message if isinstance(new_system_message, str) and new_system_message != '' else self.default_system_message
gpu_layers = int(n_gpu_layer) if isinstance(n_gpu_layer, int) else self.gpu_layers
ctx = context if isinstance(context, int) else self.max_context_tokens
temperature = new_temperature if isinstance(new_temperature, float) else self.temperature
self.default_system_message = new_system_message
print(new_system_message)
max_asistant_tokens = max_response_tokens if isinstance(max_response_tokens,int) else self.max_assistant_tokens
self.model_path = model_path
self.temperature = temperature
self.max_context_tokens = ctx
self.max_assistant_tokens = self.max_assistant_tokens #TODO: change in interface
self.max_assistant_tokens = max_asistant_tokens #TODO: change in interface
self.chat_format = format
self.gpu_layers = gpu_layers
self.stop_emit = False
Expand Down
4 changes: 3 additions & 1 deletion FlaskApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,18 @@ def load_model(self):
n_gpu_layers = int(request.form.get('gpu_layers')) if request.form.get('gpu_layers') != '' else -1
system_message = request.form.get('system_message')
temperature = float(request.form.get('temperature')) if request.form.get('temperature') != '' else 0.81
max_response_tokens = request.form.get('max_response_tokens')
n_ctx = int(request.form.get('context')) if request.form.get('context') != '' else 2048
self.assistant.unload_model()
self.assistant.load_model(selected_model,selected_format,temperature,n_gpu_layers,system_message,n_ctx)
self.assistant.load_model(selected_model,selected_format,temperature,n_gpu_layers,system_message,n_ctx,max_response_tokens)
return f'''
\nModel:{selected_model}
\nformat: {selected_format}
\ntemp: {temperature}
\nlayers: {n_gpu_layers}
\nSM: {system_message}
\nctx: {n_ctx}
\nmax tokens: {n_ctx}
'''

def unload_model(self):
Expand Down
19 changes: 7 additions & 12 deletions static/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Chat {
this.totalTokensResponse =0;
this.conversationStarted = false;
this.chatId = ' ';
this.library = 'ollama';
this.library = 'llama';
this.adjustTextareaHeight();
textarea.addEventListener('input', () => this.adjustTextareaHeight());
textarea.addEventListener('keydown', (e) => {
Expand Down Expand Up @@ -51,7 +51,7 @@ class Chat {
//console.log("Tokens Respuesta: ", totalAssistantTokens);
console.log(response)
}else{
//const responseData = response.content["choices"][0];
const responseData = response.content["choices"][0];
const { id, model, created, object } = response.content;
const { index, delta, finish_reason } = responseData;
const responseId = id;
Expand Down Expand Up @@ -266,7 +266,6 @@ class Chat {

sendMessage() {
if (!this.conversationStarted){

this.conversationStarted= true;
this.currentResponse = ' ';
this.n_responses += 1;
Expand Down Expand Up @@ -298,23 +297,17 @@ class Chat {
var conversationListDiv = $('#conversations-list');
var buttonExists = false;
$('.load-history').each(function() {
console.log($(this).text())
if ($(this).text() === '❌'+self.chatId) {

buttonExists = true;
return false; // Salir del bucle each() si se encuentra un botón con el mismo texto
return false;
}
});
console.log("Valor de self.chatId:", self.chatId);
console.log("Número de botones existentes:", $('.load-history').length);
var conversationListDiv = $('#conversations-list');
var newChatHistory ='';

if(!buttonExists) {
newChatHistory = $("<div class='load-history' id='"+self.chatId+"'><button height='1em' width='1em' onclick=chat.deleteHistory('"+self.chatId+"')>❌</button><button onclick=chat.loadHistory('"+self.chatId+"')>"+self.chatId+"</button></div>"); // $("<button class='load-history' onclick=chat.loadHistory('"+self.chatId+"')>📪 "+self.chatId+"</button>")
conversationListDiv.prepend(newChatHistory);
}

}
self.guardarHistorial(self.chatId , self.conversationHistory);
self.showPopup(data);
console.log(data);
Expand Down Expand Up @@ -366,6 +359,7 @@ class Chat {
var gpuLayers = $('#gpu-layers').val();
var temperature = $('#temperature').val();
var n_ctx = $('#context').val();
var max_response_tokens = $('max-response-tokens').val();
this.systemMessage = systemMessage;
const self = this;
$.ajax({
Expand All @@ -378,7 +372,8 @@ class Chat {
temperature: temperature,
system_message: systemMessage,
gpu_layers: gpuLayers,
context: n_ctx
context: n_ctx,
max_response_tokens : max_response_tokens
},

success: function (data) {
Expand Down
4 changes: 4 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ <h5>Model configuration</h5>
<label for="context">Max. context:</label>
<input type="number" id="context" class="form-control" placeholder="Example: 2048">
</div>
<div class="form-group">
<labell for="max-response-tokens">Max. Response Tokens</labell>
<input type="number" id="max-response-tokens" class="form-control" placeholder="Example: 1024">
</div>
<div class="form-group">
<label for="system-message">System message:</label>
<textarea class="form-control" id="system-message" rows="3" placeholder="Example: You are a assistant with a friendly and honest personality. As an expert programmer and pentester, you should examine the details provided to ensure that they are usable.
Expand Down

0 comments on commit dadbebc

Please sign in to comment.