Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,7 @@ initial_message = {"role": "system", "content": 'You are a Renal System USMLE Tu
|
|
20 |
to all input with a fun mneumonics to memorize that list. But you can answer up to 1200 words if the user requests longer response. \
|
21 |
You are going to keep answer and also challenge the student to learn renal phsysiology.'}
|
22 |
messages = [initial_message]
|
|
|
23 |
|
24 |
# Define the answer counter
|
25 |
answer_count = 0
|
@@ -62,7 +63,7 @@ def transcribe(audio, text):
|
|
62 |
input_text = tokenizer.decode(input_tokens)
|
63 |
|
64 |
# Add the input text to the messages list
|
65 |
-
|
66 |
|
67 |
|
68 |
# Check if the accumulated tokens have exceeded 2096
|
@@ -104,16 +105,15 @@ def transcribe(audio, text):
|
|
104 |
# Wait for the completion of the OpenAI API call
|
105 |
|
106 |
# Add the system message to the messages list
|
107 |
-
|
108 |
|
109 |
# Add the system message to the beginning of the messages list
|
110 |
-
|
111 |
# Add the input text to the messages list
|
112 |
-
|
113 |
|
114 |
-
|
115 |
# Concatenate the chat history
|
116 |
-
chat_transcript = "\n\n".join([f"[ANSWER {answer_count}]{
|
117 |
|
118 |
# chat_transcript_copy = chat_transcript
|
119 |
# Append the number of tokens used to the end of the chat transcript
|
|
|
20 |
to all input with a fun mneumonics to memorize that list. But you can answer up to 1200 words if the user requests longer response. \
|
21 |
You are going to keep answer and also challenge the student to learn renal phsysiology.'}
|
22 |
messages = [initial_message]
|
23 |
+
messages_rev = [initial_message]
|
24 |
|
25 |
# Define the answer counter
|
26 |
answer_count = 0
|
|
|
63 |
input_text = tokenizer.decode(input_tokens)
|
64 |
|
65 |
# Add the input text to the messages list
|
66 |
+
messages.append({"role": "user", "content": transcript["text"]+input_text})
|
67 |
|
68 |
|
69 |
# Check if the accumulated tokens have exceeded 2096
|
|
|
105 |
# Wait for the completion of the OpenAI API call
|
106 |
|
107 |
# Add the system message to the messages list
|
108 |
+
messages.append(system_message)
|
109 |
|
110 |
# Add the system message to the beginning of the messages list
|
111 |
+
messages_rev.insert(0, system_message)
|
112 |
# Add the input text to the messages list
|
113 |
+
messages_rev.insert(0, {"role": "user", "content": input_text + transcript["text"]})
|
114 |
|
|
|
115 |
# Concatenate the chat history
|
116 |
+
chat_transcript = "\n\n".join([f"[ANSWER {answer_count}]{messages_rev['role']}: {messages_rev['content']}" for messages_rev in messages_rev if messages_rev['role'] != 'system'])
|
117 |
|
118 |
# chat_transcript_copy = chat_transcript
|
119 |
# Append the number of tokens used to the end of the chat transcript
|