Kukedlc commited on
Commit
80dbf79
verified
1 Parent(s): 170cb41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -3,19 +3,27 @@ from llama_cpp import Llama
3
 
4
  llm = Llama(model_path="model.gguf", n_ctx=8000, n_threads=2, chat_format="chatml")
5
 
6
- def generate(message, history,temperature=0.3,max_tokens=512):
7
  system_prompt = """You are a SQL virtual assistant, you will only create queries thinking step by step. Check that the syntax is perfect and don't miss any character. Pay attention to the names of the tables and fields. Do not make up fields that do not exist. I want you to give the query only. Do not speak and do not explain anything. Just provide the queries with no further words."""
8
  formatted_prompt = [{"role": "system", "content": system_prompt}]
9
- for user_prompt, bot_response in history:
10
  formatted_prompt.append({"role": "user", "content": user_prompt})
11
- formatted_prompt.append({"role": "assistant", "content": bot_response })
12
  formatted_prompt.append({"role": "user", "content": message})
13
  stream_response = llm.create_chat_completion(messages=formatted_prompt, temperature=temperature, max_tokens=max_tokens, stream=True)
14
- response = ""
 
15
  for chunk in stream_response:
16
  if len(chunk['choices'][0]["delta"]) != 0 and "content" in chunk['choices'][0]["delta"]:
17
- response += chunk['choices'][0]["delta"]["content"]
18
- yield response
 
 
 
 
 
 
 
19
 
20
  mychatbot = gr.Chatbot(
21
  avatar_images=["user.png", "botnb.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
 
3
 
4
  llm = Llama(model_path="model.gguf", n_ctx=8000, n_threads=2, chat_format="chatml")
5
 
6
+ def generate(message, history, temperature=0.3, max_tokens=512):
7
  system_prompt = """You are a SQL virtual assistant, you will only create queries thinking step by step. Check that the syntax is perfect and don't miss any character. Pay attention to the names of the tables and fields. Do not make up fields that do not exist. I want you to give the query only. Do not speak and do not explain anything. Just provide the queries with no further words."""
8
  formatted_prompt = [{"role": "system", "content": system_prompt}]
9
+ for user_prompt, bot_response in history:
10
  formatted_prompt.append({"role": "user", "content": user_prompt})
11
+ formatted_prompt.append({"role": "assistant", "content": bot_response})
12
  formatted_prompt.append({"role": "user", "content": message})
13
  stream_response = llm.create_chat_completion(messages=formatted_prompt, temperature=temperature, max_tokens=max_tokens, stream=True)
14
+
15
+ response = ""
16
  for chunk in stream_response:
17
  if len(chunk['choices'][0]["delta"]) != 0 and "content" in chunk['choices'][0]["delta"]:
18
+ chunk_content = chunk['choices'][0]["delta"]["content"]
19
+ stop_sequence_index = chunk_content.find(';---') # Busca el 铆ndice del patr贸n de detenci贸n
20
+ if stop_sequence_index != -1: # Si se encuentra el patr贸n, recorta la respuesta
21
+ response += chunk_content[:stop_sequence_index]
22
+ break # Termina el bucle ya que encontraste el punto de detenci贸n
23
+ else:
24
+ response += chunk_content
25
+ yield response
26
+
27
 
28
  mychatbot = gr.Chatbot(
29
  avatar_images=["user.png", "botnb.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)