braunaleMPG commited on
Commit
8feb6f6
·
verified ·
1 Parent(s): 78a1061

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -10,6 +10,7 @@ client = Groq(
10
  with gr.Blocks() as app:
11
 
12
  dialog_state_var = gr.State([])
 
13
 
14
  def api_call(prompt, model_id):
15
  completion = client.chat.completions.create(
@@ -34,16 +35,18 @@ with gr.Blocks() as app:
34
  else:
35
  return "XXX COULD NOT PARSE.. \n\nOriginal Response: \n"+response
36
 
37
- def next(input, model,tutor, base_prompt, dialog_state, prompt_summary, memory):
38
  dialog_state.append("Schüler: "+input)
39
  dialog = "\n\n".join(dialog_state)
40
 
41
- last_2 = "\n".join(dialog.split("\n")[-2:])
42
- prompt_summary = prompt_summary.format(dialog=last_2)
43
- response_summary = api_call(prompt_summary, model)
44
- if not "[KEINE_INFORMATIONEN]" in response_summary:
45
- memory+="\n"+response_summary
46
-
 
 
47
 
48
  prompt = base_prompt.format(tutor=tutor, dialog=dialog, response_student=input, memory=memory)
49
 
@@ -58,7 +61,7 @@ with gr.Blocks() as app:
58
  file.write(dialog)
59
 
60
  print(txt_input, txt_model, txt_tutor, txt_prompt, dialog_state)
61
- return dialog, dialog_state, "", response_full, gr.DownloadButton(label="Download Dialog", value=file_path, visible=True), memory
62
 
63
 
64
  tutor_val = """Du bist ein intelligenter KI-Tutor der speziell für die Unterstützung
 
10
  with gr.Blocks() as app:
11
 
12
  dialog_state_var = gr.State([])
13
+ counter_memory = gr.State([1])
14
 
15
  def api_call(prompt, model_id):
16
  completion = client.chat.completions.create(
 
35
  else:
36
  return "XXX COULD NOT PARSE.. \n\nOriginal Response: \n"+response
37
 
38
+ def next(input, model,tutor, base_prompt, dialog_state, prompt_summary, memory, counter):
39
  dialog_state.append("Schüler: "+input)
40
  dialog = "\n\n".join(dialog_state)
41
 
42
+ counter = counter[0]
43
+ if counter%2 == 0:
44
+ last_4 = "\n".join(dialog.split("\n")[-4:])
45
+ prompt_summary = prompt_summary.format(dialog=last_4)
46
+ response_summary = api_call(prompt_summary, model)
47
+ if not "[KEINE_INFORMATIONEN]" in response_summary:
48
+ memory+="\n"+response_summary
49
+ counter += 1
50
 
51
  prompt = base_prompt.format(tutor=tutor, dialog=dialog, response_student=input, memory=memory)
52
 
 
61
  file.write(dialog)
62
 
63
  print(txt_input, txt_model, txt_tutor, txt_prompt, dialog_state)
64
+ return dialog, dialog_state, "", response_full, gr.DownloadButton(label="Download Dialog", value=file_path, visible=True), memory, [counter]
65
 
66
 
67
  tutor_val = """Du bist ein intelligenter KI-Tutor der speziell für die Unterstützung