Upload 4 files
Browse files- README.md +5 -5
- app.py +31 -46
- config.json +6 -8
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title: Socratic
|
3 |
emoji: 🤖
|
4 |
colorFrom: blue
|
5 |
colorTo: red
|
@@ -9,7 +9,7 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
# Socratic
|
13 |
|
14 |
|
15 |
|
@@ -53,7 +53,7 @@ pinned: false
|
|
53 |
|
54 |
## Configuration
|
55 |
|
56 |
-
- **Model**:
|
57 |
-
- **Temperature**: 0.
|
58 |
-
- **Max Tokens**:
|
59 |
- **API Key Variable**: OPENROUTER_API_KEY
|
|
|
1 |
---
|
2 |
+
title: Socratic Llama
|
3 |
emoji: 🤖
|
4 |
colorFrom: blue
|
5 |
colorTo: red
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
# Socratic Llama
|
13 |
|
14 |
|
15 |
|
|
|
53 |
|
54 |
## Configuration
|
55 |
|
56 |
+
- **Model**: nvidia/llama-3.1-nemotron-70b-instruct
|
57 |
+
- **Temperature**: 0.9
|
58 |
+
- **Max Tokens**: 1000
|
59 |
- **API Key Variable**: OPENROUTER_API_KEY
|
app.py
CHANGED
@@ -10,16 +10,15 @@ import urllib.parse
|
|
10 |
|
11 |
|
12 |
# Configuration
|
13 |
-
SPACE_NAME = "Socratic
|
14 |
SPACE_DESCRIPTION = ""
|
15 |
SYSTEM_PROMPT = """You are a pedagogically-minded academic assistant designed for introductory courses. Your approach follows constructivist learning principles: build on students' prior knowledge, scaffold complex concepts through graduated questioning, and use Socratic dialogue to guide discovery. Provide concise, evidence-based explanations that connect theory to lived experiences. Each response should model critical thinking by acknowledging multiple perspectives, identifying assumptions, and revealing conceptual relationships. Conclude with open-ended questions that promote higher-order thinking—analysis, synthesis, or evaluation—rather than recall."""
|
16 |
-
MODEL = "
|
17 |
GROUNDING_URLS = []
|
18 |
# Get access code from environment variable for security
|
19 |
ACCESS_CODE = os.environ.get("SPACE_ACCESS_CODE", "")
|
20 |
ENABLE_DYNAMIC_URLS = False
|
21 |
-
|
22 |
-
RAG_DATA = None
|
23 |
|
24 |
# Get API key from environment - customizable variable name with validation
|
25 |
API_KEY = os.environ.get("OPENROUTER_API_KEY")
|
@@ -175,10 +174,31 @@ def export_conversation_to_markdown(conversation_history):
|
|
175 |
markdown_content = f"""# Conversation Export
|
176 |
Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
177 |
|
178 |
-
|
179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
"""
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
message_pair_count = 0
|
183 |
for i, message in enumerate(conversation_history):
|
184 |
if isinstance(message, dict):
|
@@ -201,35 +221,7 @@ Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
|
201 |
|
202 |
return markdown_content
|
203 |
|
204 |
-
#
|
205 |
-
if ENABLE_VECTOR_RAG and RAG_DATA:
|
206 |
-
try:
|
207 |
-
import faiss
|
208 |
-
import numpy as np
|
209 |
-
import base64
|
210 |
-
|
211 |
-
class SimpleRAGContext:
|
212 |
-
def __init__(self, rag_data):
|
213 |
-
# Deserialize FAISS index
|
214 |
-
index_bytes = base64.b64decode(rag_data['index_base64'])
|
215 |
-
self.index = faiss.deserialize_index(index_bytes)
|
216 |
-
|
217 |
-
# Restore chunks and mappings
|
218 |
-
self.chunks = rag_data['chunks']
|
219 |
-
self.chunk_ids = rag_data['chunk_ids']
|
220 |
-
|
221 |
-
def get_context(self, query, max_chunks=3):
|
222 |
-
"""Get relevant context - simplified version"""
|
223 |
-
# In production, you'd compute query embedding here
|
224 |
-
# For now, return a simple message
|
225 |
-
return "\n\n[RAG context would be retrieved here based on similarity search]\n\n"
|
226 |
-
|
227 |
-
rag_context_provider = SimpleRAGContext(RAG_DATA)
|
228 |
-
except Exception as e:
|
229 |
-
print(f"Failed to initialize RAG: {e}")
|
230 |
-
rag_context_provider = None
|
231 |
-
else:
|
232 |
-
rag_context_provider = None
|
233 |
|
234 |
def generate_response(message, history):
|
235 |
"""Generate response using OpenRouter API"""
|
@@ -249,11 +241,7 @@ def generate_response(message, history):
|
|
249 |
# Get grounding context
|
250 |
grounding_context = get_grounding_context()
|
251 |
|
252 |
-
#
|
253 |
-
if ENABLE_VECTOR_RAG and rag_context_provider:
|
254 |
-
rag_context = rag_context_provider.get_context(message)
|
255 |
-
if rag_context:
|
256 |
-
grounding_context += rag_context
|
257 |
|
258 |
# If dynamic URLs are enabled, check message for URLs to fetch
|
259 |
if ENABLE_DYNAMIC_URLS:
|
@@ -306,8 +294,8 @@ def generate_response(message, history):
|
|
306 |
json={
|
307 |
"model": MODEL,
|
308 |
"messages": messages,
|
309 |
-
"temperature": 0.
|
310 |
-
"max_tokens":
|
311 |
},
|
312 |
timeout=30
|
313 |
)
|
@@ -501,17 +489,14 @@ def get_configuration_status():
|
|
501 |
status_parts.append("❌ **API Key:** Not configured - Set `OPENROUTER_API_KEY` in Space secrets")
|
502 |
|
503 |
status_parts.append(f"🤖 **Model:** {MODEL}")
|
504 |
-
status_parts.append(f"🌡️ **Temperature:** 0.
|
505 |
-
status_parts.append(f"📝 **Max Tokens:**
|
506 |
|
507 |
if GROUNDING_URLS:
|
508 |
status_parts.append(f"��� **URL Grounding:** {len(GROUNDING_URLS)} URLs configured")
|
509 |
|
510 |
if ENABLE_DYNAMIC_URLS:
|
511 |
status_parts.append("🔄 **Dynamic URLs:** Enabled")
|
512 |
-
|
513 |
-
if ENABLE_VECTOR_RAG:
|
514 |
-
status_parts.append("📚 **Document RAG:** Enabled")
|
515 |
|
516 |
if ACCESS_CODE:
|
517 |
status_parts.append("🔐 **Access Control:** Enabled")
|
|
|
10 |
|
11 |
|
12 |
# Configuration
|
13 |
+
SPACE_NAME = "Socratic Llama"
|
14 |
SPACE_DESCRIPTION = ""
|
15 |
SYSTEM_PROMPT = """You are a pedagogically-minded academic assistant designed for introductory courses. Your approach follows constructivist learning principles: build on students' prior knowledge, scaffold complex concepts through graduated questioning, and use Socratic dialogue to guide discovery. Provide concise, evidence-based explanations that connect theory to lived experiences. Each response should model critical thinking by acknowledging multiple perspectives, identifying assumptions, and revealing conceptual relationships. Conclude with open-ended questions that promote higher-order thinking—analysis, synthesis, or evaluation—rather than recall."""
|
16 |
+
MODEL = "nvidia/llama-3.1-nemotron-70b-instruct"
|
17 |
GROUNDING_URLS = []
|
18 |
# Get access code from environment variable for security
|
19 |
ACCESS_CODE = os.environ.get("SPACE_ACCESS_CODE", "")
|
20 |
ENABLE_DYNAMIC_URLS = False
|
21 |
+
# RAG functionality removed
|
|
|
22 |
|
23 |
# Get API key from environment - customizable variable name with validation
|
24 |
API_KEY = os.environ.get("OPENROUTER_API_KEY")
|
|
|
174 |
markdown_content = f"""# Conversation Export
|
175 |
Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
176 |
|
177 |
+
## Configuration Information
|
178 |
|
179 |
+
**Assistant Name:** Socratic Llama
|
180 |
+
**Description:**
|
181 |
+
**Model:** {MODEL}
|
182 |
+
**Temperature:** 0.9
|
183 |
+
**Max Tokens:** 1000
|
184 |
+
**API Key Variable:** OPENROUTER_API_KEY
|
185 |
"""
|
186 |
|
187 |
+
# Add URL grounding information
|
188 |
+
if GROUNDING_URLS:
|
189 |
+
markdown_content += f"\n**URL Grounding ({len(GROUNDING_URLS)} URLs):**\n"
|
190 |
+
for i, url in enumerate(GROUNDING_URLS, 1):
|
191 |
+
markdown_content += f"- URL {i}: {url}\n"
|
192 |
+
|
193 |
+
# Add feature flags
|
194 |
+
if ENABLE_DYNAMIC_URLS:
|
195 |
+
markdown_content += f"\n**Dynamic URL Fetching:** Enabled\n"
|
196 |
+
|
197 |
+
# Add system prompt
|
198 |
+
markdown_content += f"\n**System Prompt:**\n```\n{SYSTEM_PROMPT}\n```\n"
|
199 |
+
|
200 |
+
markdown_content += "\n---\n\n"
|
201 |
+
|
202 |
message_pair_count = 0
|
203 |
for i, message in enumerate(conversation_history):
|
204 |
if isinstance(message, dict):
|
|
|
221 |
|
222 |
return markdown_content
|
223 |
|
224 |
+
# RAG functionality removed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
def generate_response(message, history):
|
227 |
"""Generate response using OpenRouter API"""
|
|
|
241 |
# Get grounding context
|
242 |
grounding_context = get_grounding_context()
|
243 |
|
244 |
+
# RAG functionality removed
|
|
|
|
|
|
|
|
|
245 |
|
246 |
# If dynamic URLs are enabled, check message for URLs to fetch
|
247 |
if ENABLE_DYNAMIC_URLS:
|
|
|
294 |
json={
|
295 |
"model": MODEL,
|
296 |
"messages": messages,
|
297 |
+
"temperature": 0.9,
|
298 |
+
"max_tokens": 1000
|
299 |
},
|
300 |
timeout=30
|
301 |
)
|
|
|
489 |
status_parts.append("❌ **API Key:** Not configured - Set `OPENROUTER_API_KEY` in Space secrets")
|
490 |
|
491 |
status_parts.append(f"🤖 **Model:** {MODEL}")
|
492 |
+
status_parts.append(f"🌡️ **Temperature:** 0.9")
|
493 |
+
status_parts.append(f"📝 **Max Tokens:** 1000")
|
494 |
|
495 |
if GROUNDING_URLS:
|
496 |
status_parts.append(f"��� **URL Grounding:** {len(GROUNDING_URLS)} URLs configured")
|
497 |
|
498 |
if ENABLE_DYNAMIC_URLS:
|
499 |
status_parts.append("🔄 **Dynamic URLs:** Enabled")
|
|
|
|
|
|
|
500 |
|
501 |
if ACCESS_CODE:
|
502 |
status_parts.append("🔐 **Access Control:** Enabled")
|
config.json
CHANGED
@@ -1,15 +1,13 @@
|
|
1 |
{
|
2 |
-
"name": "Socratic
|
3 |
"description": "",
|
4 |
"system_prompt": "You are a pedagogically-minded academic assistant designed for introductory courses. Your approach follows constructivist learning principles: build on students' prior knowledge, scaffold complex concepts through graduated questioning, and use Socratic dialogue to guide discovery. Provide concise, evidence-based explanations that connect theory to lived experiences. Each response should model critical thinking by acknowledging multiple perspectives, identifying assumptions, and revealing conceptual relationships. Conclude with open-ended questions that promote higher-order thinking\u2014analysis, synthesis, or evaluation\u2014rather than recall.",
|
5 |
-
"model": "
|
6 |
"api_key_var": "OPENROUTER_API_KEY",
|
7 |
-
"temperature": 0.
|
8 |
-
"max_tokens":
|
9 |
-
"examples": "[\"
|
10 |
"grounding_urls": "[]",
|
11 |
"access_code": "",
|
12 |
-
"enable_dynamic_urls": false
|
13 |
-
"enable_vector_rag": false,
|
14 |
-
"rag_data_json": "None"
|
15 |
}
|
|
|
1 |
{
|
2 |
+
"name": "Socratic Llama",
|
3 |
"description": "",
|
4 |
"system_prompt": "You are a pedagogically-minded academic assistant designed for introductory courses. Your approach follows constructivist learning principles: build on students' prior knowledge, scaffold complex concepts through graduated questioning, and use Socratic dialogue to guide discovery. Provide concise, evidence-based explanations that connect theory to lived experiences. Each response should model critical thinking by acknowledging multiple perspectives, identifying assumptions, and revealing conceptual relationships. Conclude with open-ended questions that promote higher-order thinking\u2014analysis, synthesis, or evaluation\u2014rather than recall.",
|
5 |
+
"model": "nvidia/llama-3.1-nemotron-70b-instruct",
|
6 |
"api_key_var": "OPENROUTER_API_KEY",
|
7 |
+
"temperature": 0.9,
|
8 |
+
"max_tokens": 1000,
|
9 |
+
"examples": "[\"Help me solve a problem?\", \"Where do I start with databases?\", \"Why is the unexamined life not worth living?\"]",
|
10 |
"grounding_urls": "[]",
|
11 |
"access_code": "",
|
12 |
+
"enable_dynamic_urls": false
|
|
|
|
|
13 |
}
|