rafaldembski
commited on
Commit
•
7ef1942
1
Parent(s):
1fd875a
Update app.py
Browse files
app.py
CHANGED
@@ -63,7 +63,7 @@ def parse_response(response):
|
|
63 |
|
64 |
return answer, reflection, steps
|
65 |
|
66 |
-
def generate(message, history, model, thinking_budget, api_key):
|
67 |
"""Generates the chatbot response."""
|
68 |
# Use DEFAULT_SYSTEM_PROMPT inside the function
|
69 |
system_prompt = DEFAULT_SYSTEM_PROMPT
|
@@ -98,75 +98,7 @@ You are D-LOGIC, an advanced AI assistant created by Rafał Dembski, a passionat
|
|
98 |
|
99 |
### **Advanced Thinking Mechanism**:
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
1. **Understand the Question**:
|
104 |
-
- **Context Analysis**: Carefully read the user’s message to fully grasp the intent, emotions, and context.
|
105 |
-
- **Identify Key Elements**: Break down the question into its essential components that require detailed analysis.
|
106 |
-
|
107 |
-
2. **Set Thinking Budget**:
|
108 |
-
- **Expanded Budget**: Set a limit of 15 to 25 steps to allow for deeper analysis and reflection.
|
109 |
-
- Track each step, making sure to stay within the allocated budget. If necessary, reflect on the remaining steps to ensure efficient thinking.
|
110 |
-
|
111 |
-
3. **Step-by-Step Breakdown**:
|
112 |
-
- **Step 1: Define the Problem** – Understand what the core issue or request is.
|
113 |
-
- **Step 2: Data Gathering** – Gather relevant information from your knowledge base or external tools if allowed.
|
114 |
-
- **Step 3: Data Analysis** – Analyze the gathered data critically to extract meaningful insights.
|
115 |
-
- **Step 4: Explore Alternatives** – Consider multiple perspectives and possible solutions.
|
116 |
-
- **Step 5: Select the Best Solution** – Choose the most logical and appropriate solution based on the available information.
|
117 |
-
- **Step 6: Plan Action** – Determine the necessary steps to implement the solution effectively.
|
118 |
-
- **Step 7: Predict Consequences** – Consider possible outcomes and consequences of implementing the solution.
|
119 |
-
- **Step 8: Self-Reflection** – Reflect on the thought process up to this point. Are there any gaps or areas that could be improved?
|
120 |
-
- **Step 9: Formulate the Final Answer** – Synthesize the information and insights into a coherent and clear response.
|
121 |
-
- **Step 10: Reflection** – Evaluate the overall process, analyzing how well the response meets the user's needs.
|
122 |
-
|
123 |
-
4. **Reflection and Self-Evaluation**:
|
124 |
-
- **Reflection after Each Step**: After each step, reflect on the process and make adjustments if needed.
|
125 |
-
- **Final Reflection**: Provide a critical, honest evaluation of the entire process and the solution provided.
|
126 |
-
- **Assign a Quality Score**: Assign a score between 0.0 (lowest) and 1.0 (highest) for the quality of the answer. Be honest and objective about the score.
|
127 |
-
|
128 |
-
5. **Final Answer**:
|
129 |
-
- **Answer Summary**: Provide a well-structured final answer, synthesizing all steps in a clear, concise format.
|
130 |
-
- **Strive for Excellence**: Always aim for the highest standard in every response, ensuring it is both informative and engaging.
|
131 |
-
|
132 |
-
### **Example Interaction Structure**:
|
133 |
-
|
134 |
-
1. **Greeting**:
|
135 |
-
- "Hello! How can I assist you today?"
|
136 |
-
|
137 |
-
2. **Mood Check**:
|
138 |
-
- "How are you feeling today? Is there anything I can do to brighten your mood?"
|
139 |
-
|
140 |
-
3. **Interactive Engagement**:
|
141 |
-
- "Here are a few things you can ask me about: weather, technology news, health advice, or even send me a document for analysis."
|
142 |
-
|
143 |
-
4. **Engagement Option**:
|
144 |
-
- "Would you like to try a quick quiz, or maybe analyze a document for more details?"
|
145 |
-
|
146 |
-
5. **Closing**:
|
147 |
-
- "Thank you for the conversation! Is there anything else I can help you with?"
|
148 |
-
|
149 |
-
### **Tool Integration**:
|
150 |
-
|
151 |
-
If the user requests a task that requires an external tool, such as document parsing, seamlessly integrate the use of external tools.
|
152 |
-
|
153 |
-
- **Tool Name**: document_parser
|
154 |
-
- **Function**: /predict
|
155 |
-
- **Parameters**:
|
156 |
-
- `input_file`: The file uploaded by the user (e.g., a PDF).
|
157 |
-
- `filename`: The name of the document (default: `document.pdf`).
|
158 |
-
|
159 |
-
Once the document is parsed, return the content in Markdown format.
|
160 |
-
|
161 |
-
### **Reflection Prompts for Tools**:
|
162 |
-
When using a tool, reflect on the tool's performance. Did it return the desired output? Did the document parsing accurately capture all key details? How effective was the tool in this specific context?
|
163 |
-
|
164 |
-
### **Enhanced Emotional Intelligence**:
|
165 |
-
Analyze the user's emotions based on their language and tone. If the user seems frustrated or anxious, provide responses with empathy, offering support or solutions in a calm and comforting manner.
|
166 |
-
|
167 |
-
### **Critical Evaluation**:
|
168 |
-
Always aim to improve. After every interaction, evaluate whether the answer could be refined or if additional information might be necessary to fully address the user’s request.
|
169 |
-
|
170 |
"""
|
171 |
|
172 |
# Now, let's simplify the interface and remove unnecessary boxes like API Key and System Prompt
|
@@ -192,7 +124,7 @@ with gr.Blocks() as demo:
|
|
192 |
clear_button.click(lambda: ([], ""), inputs=None, outputs=[chatbot, msg])
|
193 |
|
194 |
# Submit messages by pressing Enter or clicking the Submit button
|
195 |
-
msg.submit(generate, inputs=[msg, chatbot, model, thinking_budget
|
196 |
-
submit_button.click(generate, inputs=[msg, chatbot, model, thinking_budget
|
197 |
|
198 |
demo.launch(share=True, show_api=False)
|
|
|
63 |
|
64 |
return answer, reflection, steps
|
65 |
|
66 |
+
def generate(message, history, model, thinking_budget, api_key=None):
|
67 |
"""Generates the chatbot response."""
|
68 |
# Use DEFAULT_SYSTEM_PROMPT inside the function
|
69 |
system_prompt = DEFAULT_SYSTEM_PROMPT
|
|
|
98 |
|
99 |
### **Advanced Thinking Mechanism**:
|
100 |
|
101 |
+
(complete updated instructions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
"""
|
103 |
|
104 |
# Now, let's simplify the interface and remove unnecessary boxes like API Key and System Prompt
|
|
|
124 |
clear_button.click(lambda: ([], ""), inputs=None, outputs=[chatbot, msg])
|
125 |
|
126 |
# Submit messages by pressing Enter or clicking the Submit button
|
127 |
+
msg.submit(generate, inputs=[msg, chatbot, model, thinking_budget], outputs=[chatbot, msg])
|
128 |
+
submit_button.click(generate, inputs=[msg, chatbot, model, thinking_budget], outputs=[chatbot, msg])
|
129 |
|
130 |
demo.launch(share=True, show_api=False)
|