Update app.py
Browse files
app.py
CHANGED
@@ -11,11 +11,11 @@ def respond(
|
|
11 |
temperature,
|
12 |
top_p,
|
13 |
):
|
14 |
-
#
|
15 |
if not history:
|
16 |
greeting = "Привет, помощник врача EMS штата Alta."
|
17 |
history.append((None, greeting))
|
18 |
-
|
19 |
|
20 |
messages = [{"role": "system", "content": system_message}]
|
21 |
|
@@ -29,21 +29,18 @@ def respond(
|
|
29 |
|
30 |
response = ""
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
yield response
|
43 |
-
except Exception as e:
|
44 |
-
yield f"Произошла ошибка: {e}"
|
45 |
|
46 |
-
#
|
47 |
diagnosis_start = response.find("Предварительный диагноз:")
|
48 |
if diagnosis_start != -1:
|
49 |
diagnosis_end = response.find("\n", diagnosis_start)
|
@@ -52,7 +49,7 @@ def respond(
|
|
52 |
diagnosis = response[diagnosis_start:diagnosis_end]
|
53 |
response = response[:diagnosis_start] + f"<b>{diagnosis}</b>" + response[diagnosis_end:]
|
54 |
|
55 |
-
#
|
56 |
final_response = f"{response}\n\nСоздано больницей EMS штата Alta"
|
57 |
yield final_response
|
58 |
|
|
|
11 |
temperature,
|
12 |
top_p,
|
13 |
):
|
14 |
+
# Send a default greeting message if the chat history is empty
|
15 |
if not history:
|
16 |
greeting = "Привет, помощник врача EMS штата Alta."
|
17 |
history.append((None, greeting))
|
18 |
+
yield greeting
|
19 |
|
20 |
messages = [{"role": "system", "content": system_message}]
|
21 |
|
|
|
29 |
|
30 |
response = ""
|
31 |
|
32 |
+
for message in client.chat_completion(
|
33 |
+
messages,
|
34 |
+
max_tokens=max_tokens,
|
35 |
+
stream=True,
|
36 |
+
temperature=temperature,
|
37 |
+
top_p=top_p,
|
38 |
+
):
|
39 |
+
token = message.choices[0].delta.content
|
40 |
+
response += token
|
41 |
+
yield response
|
|
|
|
|
|
|
42 |
|
43 |
+
# Highlight the diagnosis in bold
|
44 |
diagnosis_start = response.find("Предварительный диагноз:")
|
45 |
if diagnosis_start != -1:
|
46 |
diagnosis_end = response.find("\n", diagnosis_start)
|
|
|
49 |
diagnosis = response[diagnosis_start:diagnosis_end]
|
50 |
response = response[:diagnosis_start] + f"<b>{diagnosis}</b>" + response[diagnosis_end:]
|
51 |
|
52 |
+
# Add an identification message to the response
|
53 |
final_response = f"{response}\n\nСоздано больницей EMS штата Alta"
|
54 |
yield final_response
|
55 |
|