Spaces:
Sleeping
Sleeping
Commit
·
cde7d1a
1
Parent(s):
e09ca8b
change for AI thinking
Browse files
app.py
CHANGED
@@ -25,8 +25,10 @@ def respond(
|
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
|
31 |
# Use chat completion instead of text generation
|
32 |
for message in client.chat_completion(
|
@@ -38,8 +40,20 @@ def respond(
|
|
38 |
):
|
39 |
token = message.choices[0].delta.content
|
40 |
if token:
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
|
45 |
# Custom CSS for Plant Wisdom.AI styling
|
@@ -77,6 +91,7 @@ custom_css = """
|
|
77 |
margin-right: 15%;
|
78 |
border: 1px solid #e0ede0;
|
79 |
color: #2c3338;
|
|
|
80 |
}
|
81 |
|
82 |
.submit-btn {
|
|
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
+
# Track generation state
|
29 |
+
full_response = ""
|
30 |
+
is_complete = False
|
31 |
+
generation_complete = False
|
32 |
|
33 |
# Use chat completion instead of text generation
|
34 |
for message in client.chat_completion(
|
|
|
40 |
):
|
41 |
token = message.choices[0].delta.content
|
42 |
if token:
|
43 |
+
full_response += token
|
44 |
+
|
45 |
+
# Check if generation is complete
|
46 |
+
if message.choices[0].finish_reason == "stop" or not token:
|
47 |
+
generation_complete = True
|
48 |
+
|
49 |
+
# Only yield the final complete response
|
50 |
+
if generation_complete and not is_complete:
|
51 |
+
is_complete = True
|
52 |
+
yield full_response
|
53 |
+
|
54 |
+
# Ensure we always yield the final response
|
55 |
+
if not is_complete:
|
56 |
+
yield full_response
|
57 |
|
58 |
|
59 |
# Custom CSS for Plant Wisdom.AI styling
|
|
|
91 |
margin-right: 15%;
|
92 |
border: 1px solid #e0ede0;
|
93 |
color: #2c3338;
|
94 |
+
transition: opacity 0.5s ease;
|
95 |
}
|
96 |
|
97 |
.submit-btn {
|