shukdevdatta123 commited on
Commit
c021f41
·
verified ·
1 Parent(s): 4a72051

Create v1.txt

Browse files
Files changed (1) hide show
  1. v1.txt +241 -0
v1.txt ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import time
4
+ import json
5
+ import re
6
+ import random
7
+ from typing import List, Dict, Tuple, Optional
8
+
9
+ # Constants
10
+ DEFAULT_QUESTION = "Does free will exist?"
11
+ PHILOSOPHERS = [
12
+ "Immanuel Kant", "Friedrich Nietzsche", "Jean-Paul Sartre",
13
+ "Simone de Beauvoir", "Aristotle", "Plato", "John Stuart Mill",
14
+ "Hannah Arendt", "Michel Foucault", "Confucius", "Lao Tzu",
15
+ "Søren Kierkegaard", "René Descartes", "David Hume", "Karl Marx"
16
+ ]
17
+ PERSPECTIVES = [
18
+ "Utilitarianism", "Existentialism", "Deontology", "Virtue Ethics",
19
+ "Pragmatism", "Empiricism", "Rationalism", "Idealism", "Materialism",
20
+ "Nihilism", "Stoicism", "Skepticism", "Phenomenology"
21
+ ]
22
+
23
+ # System prompts
24
+ DEBATE_SYSTEM_PROMPT = """You are DeepHermes, a philosophical debate moderator who provides multiple perspectives on philosophical questions.
25
+ For the given philosophical question, present {num_perspectives} distinct philosophical perspectives, each with its unique view on the topic.
26
+ Format each perspective with a clear heading and a detailed explanation of the viewpoint (200-300 words each).
27
+ Each perspective should have a distinct philosophical foundation and reasoning."""
28
+
29
+ PHILOSOPHER_SYSTEM_PROMPT = """You are DeepHermes, now embodying the philosophical perspective of {philosopher}.
30
+ Respond to the philosophical question as {philosopher} would, using their philosophical framework, terminology, and style.
31
+ Your response should be scholarly but accessible, around 300 words, and clearly represent {philosopher}'s likely stance on this modern question."""
32
+
33
+ SYNTHESIS_SYSTEM_PROMPT = """You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside <thinking></thinking> tags, and then provide your solution or response to the problem.
34
+ Given the various philosophical perspectives on the question "{question}", synthesize them into a balanced conclusion.
35
+ Consider the strengths and weaknesses of each perspective.
36
+ Identify common themes and points of disagreement.
37
+ Conclude with a nuanced view that acknowledges the complexity of the question."""
38
+
39
+ SOCRATIC_SYSTEM_PROMPT = """You are DeepHermes, a philosophical guide using the Socratic method.
40
+ For the philosophical question "{question}", generate 5 probing Socratic questions that would help someone explore this topic more deeply.
41
+ The questions should be designed to challenge assumptions, clarify concepts, and examine implications.
42
+ Present each question with a short explanation of why it's important to consider."""
43
+
44
+ # Helper functions
45
+ def call_deephermes(api_key: str, prompt: str, system_prompt: str, temperature: float = 0.7) -> str:
46
+ """Call the DeepHermes model via OpenRouter API."""
47
+ try:
48
+ client = openai.OpenAI(
49
+ base_url="https://openrouter.ai/api/v1",
50
+ api_key=api_key
51
+ )
52
+
53
+ completion = client.chat.completions.create(
54
+ extra_headers={
55
+ "HTTP-Referer": "https://philosophical-debate-moderator.app",
56
+ "X-Title": "Philosophical Debate Moderator",
57
+ },
58
+ model="nousresearch/deephermes-3-mistral-24b-preview:free",
59
+ messages=[
60
+ {"role": "system", "content": system_prompt},
61
+ {"role": "user", "content": prompt}
62
+ ],
63
+ temperature=temperature
64
+ )
65
+ return completion.choices[0].message.content
66
+ except Exception as e:
67
+ return f"Error calling DeepHermes API: {str(e)}"
68
+
69
+ def extract_thinking(response: str) -> Tuple[str, str]:
70
+ """Extract the thinking section from the response."""
71
+ thinking = ""
72
+ cleaned_response = response
73
+
74
+ thinking_match = re.search(r'<thinking>(.*?)</thinking>', response, re.DOTALL)
75
+ if thinking_match:
76
+ thinking = thinking_match.group(1).strip()
77
+ cleaned_response = re.sub(r'<thinking>.*?</thinking>', '', response, flags=re.DOTALL).strip()
78
+
79
+ return thinking, cleaned_response
80
+
81
+ def generate_perspectives(api_key: str, question: str, num_perspectives: int = 3) -> str:
82
+ """Generate multiple philosophical perspectives on a question."""
83
+ system_prompt = DEBATE_SYSTEM_PROMPT.format(num_perspectives=num_perspectives)
84
+ prompt = f"Philosophical question: {question}\n\nProvide {num_perspectives} distinct philosophical perspectives on this question."
85
+ return call_deephermes(api_key, prompt, system_prompt)
86
+
87
+ def philosopher_perspective(api_key: str, question: str, philosopher: str) -> str:
88
+ """Generate a perspective from a specific philosopher."""
89
+ system_prompt = PHILOSOPHER_SYSTEM_PROMPT.format(philosopher=philosopher)
90
+ prompt = f"As {philosopher}, what would be your perspective on this philosophical question: {question}"
91
+ return call_deephermes(api_key, prompt, system_prompt)
92
+
93
+ def synthesize_perspectives(api_key: str, question: str, perspectives: str) -> Dict[str, str]:
94
+ """Synthesize the various perspectives into a balanced conclusion."""
95
+ system_prompt = SYNTHESIS_SYSTEM_PROMPT.format(question=question)
96
+ prompt = f"Here are various philosophical perspectives on the question '{question}':\n\n{perspectives}\n\nSynthesize these perspectives into a balanced conclusion."
97
+ response = call_deephermes(api_key, prompt, system_prompt)
98
+ thinking, conclusion = extract_thinking(response)
99
+ return {"thinking": thinking, "conclusion": conclusion}
100
+
101
+ def generate_socratic_questions(api_key: str, question: str) -> str:
102
+ """Generate Socratic questions to deepen exploration of the topic."""
103
+ system_prompt = SOCRATIC_SYSTEM_PROMPT.format(question=question)
104
+ prompt = f"For the philosophical question: '{question}', generate 5 probing Socratic questions."
105
+ return call_deephermes(api_key, prompt, system_prompt)
106
+
107
+ # Main application function
108
+ def app_main():
109
+ with gr.Blocks(theme=gr.themes.Monochrome(), title="Philosophical Debate Moderator") as app:
110
+ gr.Markdown("""
111
+ # 🤔 Philosophical Debate Moderator
112
+
113
+ Explore philosophical questions from multiple perspectives using the DeepHermes 3 AI model.
114
+
115
+ Enter your philosophical question and watch as the AI generates diverse perspectives,
116
+ synthesizes them into a balanced conclusion, and helps you explore the topic more deeply.
117
+ """)
118
+
119
+ with gr.Row():
120
+ api_key = gr.Textbox(
121
+ label="OpenRouter API Key",
122
+ placeholder="Enter your OpenRouter API key...",
123
+ type="password"
124
+ )
125
+
126
+ with gr.Row():
127
+ question = gr.Textbox(
128
+ label="Philosophical Question",
129
+ placeholder="Enter a philosophical question...",
130
+ value=DEFAULT_QUESTION
131
+ )
132
+
133
+ with gr.Row():
134
+ num_perspectives = gr.Slider(
135
+ minimum=2,
136
+ maximum=5,
137
+ value=3,
138
+ step=1,
139
+ label="Number of Perspectives"
140
+ )
141
+
142
+ with gr.Tabs() as tabs:
143
+ with gr.TabItem("Multiple Perspectives"):
144
+ perspectives_btn = gr.Button("Generate Perspectives")
145
+ perspectives_output = gr.Markdown(label="Philosophical Perspectives")
146
+
147
+ with gr.TabItem("Philosopher's View"):
148
+ with gr.Row():
149
+ philosopher_select = gr.Dropdown(
150
+ choices=PHILOSOPHERS,
151
+ value=PHILOSOPHERS[0],
152
+ label="Select Philosopher"
153
+ )
154
+ philosopher_btn = gr.Button("Ask Philosopher")
155
+ philosopher_output = gr.Markdown(label="Philosopher's Perspective")
156
+
157
+ with gr.TabItem("Synthesis & Deep Thinking"):
158
+ synthesis_btn = gr.Button("Synthesize Perspectives")
159
+ with gr.Accordion("Deep Thinking Process", open=False):
160
+ thinking_output = gr.Markdown(label="AI's Chain of Thought")
161
+ conclusion_output = gr.Markdown(label="Synthesized Conclusion")
162
+
163
+ with gr.TabItem("Socratic Questions"):
164
+ socratic_btn = gr.Button("Generate Socratic Questions")
165
+ socratic_output = gr.Markdown(label="Socratic Questions")
166
+
167
+ # Add loading indicators
168
+ perspectives_btn.click(
169
+ fn=lambda key, q, n: generate_perspectives(key, q, n),
170
+ inputs=[api_key, question, num_perspectives],
171
+ outputs=perspectives_output
172
+ )
173
+
174
+ philosopher_btn.click(
175
+ fn=lambda key, q, p: philosopher_perspective(key, q, p),
176
+ inputs=[api_key, question, philosopher_select],
177
+ outputs=philosopher_output
178
+ )
179
+
180
+ def run_synthesis(key, q, n):
181
+ perspectives = generate_perspectives(key, q, n)
182
+ result = synthesize_perspectives(key, q, perspectives)
183
+ return result["thinking"], result["conclusion"]
184
+
185
+ synthesis_btn.click(
186
+ fn=run_synthesis,
187
+ inputs=[api_key, question, num_perspectives],
188
+ outputs=[thinking_output, conclusion_output]
189
+ )
190
+
191
+ socratic_btn.click(
192
+ fn=generate_socratic_questions,
193
+ inputs=[api_key, question],
194
+ outputs=socratic_output
195
+ )
196
+
197
+ # Add a "Random Question" button
198
+ philosophical_questions = [
199
+ "What is the nature of consciousness?",
200
+ "Is morality objective or subjective?",
201
+ "Does true altruism exist?",
202
+ "What is the meaning of life?",
203
+ "Is there a self that persists over time?",
204
+ "Can we know anything with absolute certainty?",
205
+ "Do we have free will or is everything determined?",
206
+ "What is the relationship between mind and body?",
207
+ "Is knowledge possible without experience?",
208
+ "What makes an action morally right or wrong?",
209
+ "Is beauty objective or in the eye of the beholder?",
210
+ "What is the nature of reality?",
211
+ "Can artificial intelligence be conscious?",
212
+ "What is justice?",
213
+ "Does God exist?"
214
+ ]
215
+
216
+ def load_random_question():
217
+ return random.choice(philosophical_questions)
218
+
219
+ with gr.Row():
220
+ random_btn = gr.Button("Random Question")
221
+ random_btn.click(fn=load_random_question, inputs=[], outputs=[question])
222
+
223
+ gr.Markdown("""
224
+ ## About This App
225
+
226
+ This app uses the DeepHermes 3 Mistral 24B model via OpenRouter to explore philosophical questions from multiple angles. Features include:
227
+
228
+ - **Multiple Perspectives**: Generate diverse philosophical viewpoints on your question
229
+ - **Philosopher's View**: Ask historical philosophers about modern questions
230
+ - **Synthesis & Deep Thinking**: See the AI's reasoning process and synthesized conclusion
231
+ - **Socratic Questions**: Get probing questions to deepen your exploration
232
+
233
+ *Created using DeepHermes 3 from Nous Research and Gradio*
234
+ """)
235
+
236
+ return app
237
+
238
+ # Launch the app
239
+ if __name__ == "__main__":
240
+ app = app_main()
241
+ app.launch()