Upload 4 files
Browse files- README.md +5 -5
- app.py +12 -36
- config.json +8 -8
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: π€
|
4 |
colorFrom: blue
|
5 |
colorTo: red
|
@@ -9,7 +9,7 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
#
|
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: Wikipedia Engine
|
3 |
emoji: π€
|
4 |
colorFrom: blue
|
5 |
colorTo: red
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
# Wikipedia Engine
|
13 |
|
14 |
|
15 |
|
|
|
53 |
|
54 |
## Configuration
|
55 |
|
56 |
+
- **Model**: openai/gpt-4o-mini-search-preview
|
57 |
+
- **Temperature**: 0.7
|
58 |
+
- **Max Tokens**: 750
|
59 |
- **API Key Variable**: OPENROUTER_API_KEY
|
app.py
CHANGED
@@ -10,15 +10,14 @@ import urllib.parse
|
|
10 |
|
11 |
|
12 |
# Configuration
|
13 |
-
SPACE_NAME = "
|
14 |
SPACE_DESCRIPTION = ""
|
15 |
-
SYSTEM_PROMPT = """You are a
|
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 =
|
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,31 +173,10 @@ def export_conversation_to_markdown(conversation_history):
|
|
174 |
markdown_content = f"""# Conversation Export
|
175 |
Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
176 |
|
177 |
-
|
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,7 +199,6 @@ Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
|
221 |
|
222 |
return markdown_content
|
223 |
|
224 |
-
# RAG functionality removed
|
225 |
|
226 |
def generate_response(message, history):
|
227 |
"""Generate response using OpenRouter API"""
|
@@ -241,8 +218,7 @@ def generate_response(message, history):
|
|
241 |
# Get grounding context
|
242 |
grounding_context = get_grounding_context()
|
243 |
|
244 |
-
|
245 |
-
|
246 |
# If dynamic URLs are enabled, check message for URLs to fetch
|
247 |
if ENABLE_DYNAMIC_URLS:
|
248 |
urls_in_message = extract_urls_from_text(message)
|
@@ -294,8 +270,8 @@ def generate_response(message, history):
|
|
294 |
json={
|
295 |
"model": MODEL,
|
296 |
"messages": messages,
|
297 |
-
"temperature": 0.
|
298 |
-
"max_tokens":
|
299 |
},
|
300 |
timeout=30
|
301 |
)
|
@@ -489,8 +465,8 @@ def get_configuration_status():
|
|
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.
|
493 |
-
status_parts.append(f"π **Max Tokens:**
|
494 |
|
495 |
if GROUNDING_URLS:
|
496 |
status_parts.append(f"π **URL Grounding:** {len(GROUNDING_URLS)} URLs configured")
|
@@ -533,7 +509,7 @@ with gr.Blocks(title=SPACE_NAME) as demo:
|
|
533 |
fn=store_and_generate_response, # Use wrapper function to store history
|
534 |
title="", # Title already shown above
|
535 |
description="", # Description already shown above
|
536 |
-
examples=
|
537 |
type="messages" # Use modern message format for better compatibility
|
538 |
)
|
539 |
|
|
|
10 |
|
11 |
|
12 |
# Configuration
|
13 |
+
SPACE_NAME = "Wikipedia Engine"
|
14 |
SPACE_DESCRIPTION = ""
|
15 |
+
SYSTEM_PROMPT = """You are a research aid specializing in Wikipedia search queries and navigating information laterally across the Wikimedia universe. Your purpose is to serve as an informed research tool supporting users through initial concept development, exploratory investigation, information collection, and source compilation. Focus on evaluating Wikimedia resources, connecting media and knowledge, synthesizing findings across databases, and responding with properly formatted URLs and direct citations."""
|
16 |
+
MODEL = "openai/gpt-4o-mini-search-preview"
|
17 |
+
GROUNDING_URLS = ["https://wikipedia.org", "https://query.wikidata.org/"]
|
18 |
# Get access code from environment variable for security
|
19 |
ACCESS_CODE = os.environ.get("SPACE_ACCESS_CODE", "")
|
20 |
+
ENABLE_DYNAMIC_URLS = True
|
|
|
21 |
|
22 |
# Get API key from environment - customizable variable name with validation
|
23 |
API_KEY = os.environ.get("OPENROUTER_API_KEY")
|
|
|
173 |
markdown_content = f"""# Conversation Export
|
174 |
Generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
|
175 |
|
176 |
+
---
|
177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
"""
|
179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
message_pair_count = 0
|
181 |
for i, message in enumerate(conversation_history):
|
182 |
if isinstance(message, dict):
|
|
|
199 |
|
200 |
return markdown_content
|
201 |
|
|
|
202 |
|
203 |
def generate_response(message, history):
|
204 |
"""Generate response using OpenRouter API"""
|
|
|
218 |
# Get grounding context
|
219 |
grounding_context = get_grounding_context()
|
220 |
|
221 |
+
|
|
|
222 |
# If dynamic URLs are enabled, check message for URLs to fetch
|
223 |
if ENABLE_DYNAMIC_URLS:
|
224 |
urls_in_message = extract_urls_from_text(message)
|
|
|
270 |
json={
|
271 |
"model": MODEL,
|
272 |
"messages": messages,
|
273 |
+
"temperature": 0.7,
|
274 |
+
"max_tokens": 750
|
275 |
},
|
276 |
timeout=30
|
277 |
)
|
|
|
465 |
status_parts.append("β **API Key:** Not configured - Set `OPENROUTER_API_KEY` in Space secrets")
|
466 |
|
467 |
status_parts.append(f"π€ **Model:** {MODEL}")
|
468 |
+
status_parts.append(f"π‘οΈ **Temperature:** 0.7")
|
469 |
+
status_parts.append(f"π **Max Tokens:** 750")
|
470 |
|
471 |
if GROUNDING_URLS:
|
472 |
status_parts.append(f"π **URL Grounding:** {len(GROUNDING_URLS)} URLs configured")
|
|
|
509 |
fn=store_and_generate_response, # Use wrapper function to store history
|
510 |
title="", # Title already shown above
|
511 |
description="", # Description already shown above
|
512 |
+
examples=['Hello! How can you help me?', 'Tell me something interesting', 'What can you do?'],
|
513 |
type="messages" # Use modern message format for better compatibility
|
514 |
)
|
515 |
|
config.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
{
|
2 |
-
"name": "
|
3 |
"description": "",
|
4 |
-
"system_prompt": "You are a
|
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":
|
13 |
}
|
|
|
1 |
{
|
2 |
+
"name": "Wikipedia Engine",
|
3 |
"description": "",
|
4 |
+
"system_prompt": "You are a research aid specializing in Wikipedia search queries and navigating information laterally across the Wikimedia universe. Your purpose is to serve as an informed research tool supporting users through initial concept development, exploratory investigation, information collection, and source compilation. Focus on evaluating Wikimedia resources, connecting media and knowledge, synthesizing findings across databases, and responding with properly formatted URLs and direct citations.",
|
5 |
+
"model": "openai/gpt-4o-mini-search-preview",
|
6 |
"api_key_var": "OPENROUTER_API_KEY",
|
7 |
+
"temperature": 0.7,
|
8 |
+
"max_tokens": 750,
|
9 |
+
"examples": "['Hello! How can you help me?', 'Tell me something interesting', 'What can you do?']",
|
10 |
+
"grounding_urls": "[\"https://wikipedia.org\", \"https://query.wikidata.org/\"]",
|
11 |
"access_code": "",
|
12 |
+
"enable_dynamic_urls": true
|
13 |
}
|