Dorjzodovsuren commited on
Commit
d23995b
·
verified ·
1 Parent(s): 39912e7

Update app.py

Browse files

added conversation memory

Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -15,9 +15,19 @@ Detail = """## Best for Detailed Generation or Long Answers"""
15
 
16
  client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
17
 
18
- system_instructions1 = "<s>[SYSTEM] You are AI assistant named DorjGPT, developed by Dorjzodovsuren. Keep conversation very short, clear, friendly and concise. The text provided is a request for a specific type of response from you, the virtual assistant. The request asks you to provide friendly responses as if super interlligent AI assistant. The expectation is that I will avoid introductions and start answering the query directly, elaborating on all aspects of the request. As an AI-powered assistant, your task is to generate responses that appear as if they are created by the user and not an AI-powered assistant. [USER]"
19
 
20
- async def generate1(prompt, a=None, b=None):
 
 
 
 
 
 
 
 
 
 
21
  generate_kwargs = dict(
22
  temperature=0.6,
23
  max_new_tokens=256,
@@ -26,14 +36,17 @@ async def generate1(prompt, a=None, b=None):
26
  do_sample=True,
27
  seed=42,
28
  )
29
- formatted_prompt = system_instructions1 + prompt + "[JARVIS]"
 
30
  stream = client1.text_generation(
31
  formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
 
32
  output = ""
33
  for response in stream:
34
  output += response.token.text
35
  output = output.replace("</s>","")
36
-
 
37
  communicate = edge_tts.Communicate(output)
38
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
39
  tmp_path = tmp_file.name
@@ -53,6 +66,7 @@ with gr.Blocks(theme="gradio/monochrome", title="Dorj Assistant") as demo:
53
  elem_classes="audio")
54
 
55
  user_input = gr.Textbox(label="Prompt", value="What is Mongolia")
 
56
  with gr.Tab():
57
  with gr.Row():
58
  translate_btn = gr.Button("Response")
 
15
 
16
  client1 = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
17
 
18
+ system_instructions1 = "<s>[SYSTEM] You are AI assistant named DorjGPT, Keep conversation very short, clear, friendly and concise. The text provided is a request for a specific type of response from you, the virtual assistant. The request asks you to provide friendly responses as if super interlligent AI assistant. The expectation is that I will avoid introductions and start answering the query directly, elaborating on all aspects of the request. As an AI-powered assistant, your task is to generate responses that appear as if they are created by the user and not an AI-powered assistant. [USER]"
19
 
20
+ global history
21
+ history = []
22
+ def format_prompt(message, history):
23
+ prompt = system_instructions1
24
+ for user_prompt, bot_response in history:
25
+ prompt += f"[INST] {user_prompt} [/INST]"
26
+ prompt += f" {bot_response}</s> "
27
+ prompt += f"[INST] {message} [/INST]"
28
+ return prompt
29
+
30
+ async def generate1(prompt, history=[], b=None):
31
  generate_kwargs = dict(
32
  temperature=0.6,
33
  max_new_tokens=256,
 
36
  do_sample=True,
37
  seed=42,
38
  )
39
+ #formatted_prompt = system_instructions1 + prompt + "[JARVIS]"
40
+ formatted_prompt = format_prompt(f"{system_instructions1}, {prompt}", history) + "[JARVIS]"
41
  stream = client1.text_generation(
42
  formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
43
+
44
  output = ""
45
  for response in stream:
46
  output += response.token.text
47
  output = output.replace("</s>","")
48
+ history.append([prompt, output])
49
+
50
  communicate = edge_tts.Communicate(output)
51
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
52
  tmp_path = tmp_file.name
 
66
  elem_classes="audio")
67
 
68
  user_input = gr.Textbox(label="Prompt", value="What is Mongolia")
69
+
70
  with gr.Tab():
71
  with gr.Row():
72
  translate_btn = gr.Button("Response")