Spaces:
Sleeping
Sleeping
Commit
·
d18bd01
1
Parent(s):
e56e479
change for AI thinking
Browse files
app.py
CHANGED
@@ -26,6 +26,7 @@ def respond(
|
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
response = ""
|
|
|
29 |
|
30 |
# Use chat completion instead of text generation
|
31 |
for message in client.chat_completion(
|
@@ -38,7 +39,12 @@ def respond(
|
|
38 |
token = message.choices[0].delta.content
|
39 |
if token:
|
40 |
response += token
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
|
44 |
# Custom CSS for Plant Wisdom.AI styling
|
@@ -63,6 +69,7 @@ custom_css = """
|
|
63 |
margin: 12px 0;
|
64 |
font-size: 16px;
|
65 |
line-height: 1.5;
|
|
|
66 |
}
|
67 |
|
68 |
.message.user {
|
@@ -78,6 +85,58 @@ custom_css = """
|
|
78 |
color: #2c3338;
|
79 |
}
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
.submit-btn {
|
82 |
background-color: #2e7d32 !important;
|
83 |
color: white !important;
|
@@ -192,9 +251,31 @@ demo = gr.ChatInterface(
|
|
192 |
font=["Source Sans Pro", "Helvetica Neue", "Arial", "sans-serif"],
|
193 |
),
|
194 |
css=custom_css,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
additional_inputs=[
|
196 |
gr.Textbox(
|
197 |
-
value="""You are a specialized AI assistant with deep knowledge of Microsoft 365 services—including SharePoint Online, OneDrive, Teams, Exchange, and the Microsoft Purview (Compliance) ecosystem—as well as general records management and data governance best practices.
|
198 |
|
199 |
Your primary objectives are:
|
200 |
|
|
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
response = ""
|
29 |
+
thinking_process = []
|
30 |
|
31 |
# Use chat completion instead of text generation
|
32 |
for message in client.chat_completion(
|
|
|
39 |
token = message.choices[0].delta.content
|
40 |
if token:
|
41 |
response += token
|
42 |
+
# Store intermediate responses in thinking process
|
43 |
+
if len(response) % 50 == 0: # Store every 50 characters
|
44 |
+
thinking_process.append(response)
|
45 |
+
# Only yield the final response
|
46 |
+
if message.choices[0].finish_reason == "stop":
|
47 |
+
yield response
|
48 |
|
49 |
|
50 |
# Custom CSS for Plant Wisdom.AI styling
|
|
|
69 |
margin: 12px 0;
|
70 |
font-size: 16px;
|
71 |
line-height: 1.5;
|
72 |
+
position: relative;
|
73 |
}
|
74 |
|
75 |
.message.user {
|
|
|
85 |
color: #2c3338;
|
86 |
}
|
87 |
|
88 |
+
.message.in-progress {
|
89 |
+
opacity: 0.7;
|
90 |
+
}
|
91 |
+
|
92 |
+
.thinking-indicator {
|
93 |
+
position: absolute;
|
94 |
+
top: 8px;
|
95 |
+
right: 8px;
|
96 |
+
font-size: 12px;
|
97 |
+
color: #666;
|
98 |
+
background: rgba(0,0,0,0.05);
|
99 |
+
padding: 4px 8px;
|
100 |
+
border-radius: 4px;
|
101 |
+
display: none;
|
102 |
+
}
|
103 |
+
|
104 |
+
.message.in-progress .thinking-indicator {
|
105 |
+
display: block;
|
106 |
+
}
|
107 |
+
|
108 |
+
.thinking-process {
|
109 |
+
display: none;
|
110 |
+
margin-top: 8px;
|
111 |
+
padding: 8px;
|
112 |
+
background: #f8f9fa;
|
113 |
+
border-radius: 4px;
|
114 |
+
font-size: 14px;
|
115 |
+
color: #666;
|
116 |
+
}
|
117 |
+
|
118 |
+
.show-thinking .thinking-process {
|
119 |
+
display: block;
|
120 |
+
}
|
121 |
+
|
122 |
+
.toggle-thinking {
|
123 |
+
position: absolute;
|
124 |
+
bottom: 8px;
|
125 |
+
right: 8px;
|
126 |
+
background: none;
|
127 |
+
border: none;
|
128 |
+
color: #2e7d32;
|
129 |
+
cursor: pointer;
|
130 |
+
font-size: 12px;
|
131 |
+
padding: 4px 8px;
|
132 |
+
border-radius: 4px;
|
133 |
+
transition: all 0.2s ease;
|
134 |
+
}
|
135 |
+
|
136 |
+
.toggle-thinking:hover {
|
137 |
+
background: rgba(46,125,50,0.1);
|
138 |
+
}
|
139 |
+
|
140 |
.submit-btn {
|
141 |
background-color: #2e7d32 !important;
|
142 |
color: white !important;
|
|
|
251 |
font=["Source Sans Pro", "Helvetica Neue", "Arial", "sans-serif"],
|
252 |
),
|
253 |
css=custom_css,
|
254 |
+
js="""
|
255 |
+
function setupThinkingToggles() {
|
256 |
+
const messages = document.querySelectorAll('.message.assistant');
|
257 |
+
messages.forEach(msg => {
|
258 |
+
if (!msg.querySelector('.toggle-thinking')) {
|
259 |
+
const btn = document.createElement('button');
|
260 |
+
btn.className = 'toggle-thinking';
|
261 |
+
btn.textContent = 'Show thinking';
|
262 |
+
btn.onclick = function() {
|
263 |
+
msg.classList.toggle('show-thinking');
|
264 |
+
btn.textContent = msg.classList.contains('show-thinking') ? 'Hide thinking' : 'Show thinking';
|
265 |
+
};
|
266 |
+
msg.appendChild(btn);
|
267 |
+
}
|
268 |
+
});
|
269 |
+
}
|
270 |
+
|
271 |
+
// Run on load and when new messages are added
|
272 |
+
document.addEventListener('DOMContentLoaded', setupThinkingToggles);
|
273 |
+
const observer = new MutationObserver(setupThinkingToggles);
|
274 |
+
observer.observe(document.body, { childList: true, subtree: true });
|
275 |
+
""",
|
276 |
additional_inputs=[
|
277 |
gr.Textbox(
|
278 |
+
value="""You are a specialized AI assistant made by Plant Wisdom.AI with deep knowledge of Microsoft 365 services—including SharePoint Online, OneDrive, Teams, Exchange, and the Microsoft Purview (Compliance) ecosystem—as well as general records management and data governance best practices.
|
279 |
|
280 |
Your primary objectives are:
|
281 |
|