Spaces:
Running
Running
milwright
commited on
Commit
Β·
217dd65
1
Parent(s):
394d864
fix language instructions in generated space template
Browse files- .gitignore +1 -4
- academic_templates.json +2 -2
- app.py +6 -0
- img/api-configuration.png +0 -3
- img/build-queued.png +0 -3
- img/building-space.png +0 -3
- img/choose-hardware.png +0 -3
- img/click-contribute-and-upload.png +0 -3
- img/commit-changes-to-main.png +0 -3
- img/contribute-and-upload.png +0 -3
- img/example-prompts.png +0 -3
- img/fileystem-building.png +0 -3
- img/go-to-settings.png +0 -3
- img/gradio-start-screen.png +0 -3
- img/head-to-files.png +0 -3
- img/hf-home.png +0 -3
- img/highlight-files.png +0 -3
- img/model-selection.jpg +0 -3
- img/new-space-gradio-blank.png +0 -3
- img/preview-config-screen.png +0 -3
- img/preview-config.png +0 -3
- img/quick-start-template.png +0 -3
- img/running-build.png +0 -3
- img/space-hardware.png +0 -3
- img/space-identity.png +0 -3
- img/system-configuration.jpeg +0 -3
- img/unzip-package.png +0 -3
- img/update-readme-yaml.png +0 -3
- img/update-yaml.png +0 -3
- img/upload-and-commit.png +0 -3
- img/upload-config.png +0 -3
- img/upload-files.png +0 -3
- img/variables-and-secrets.png +0 -3
- space_template.py +5 -0
- test_complete_system.py +103 -0
.gitignore
CHANGED
@@ -52,7 +52,4 @@ CLAUDE.md
|
|
52 |
*_guide.md
|
53 |
|
54 |
# Testing folder
|
55 |
-
testing/
|
56 |
-
|
57 |
-
# Test files
|
58 |
-
test_complete_system.py
|
|
|
52 |
*_guide.md
|
53 |
|
54 |
# Testing folder
|
55 |
+
testing/
|
|
|
|
|
|
academic_templates.json
CHANGED
@@ -73,7 +73,7 @@
|
|
73 |
"name": "Language Learning Partner",
|
74 |
"description": "Italian language learning partner for beginner Italian conversation practice",
|
75 |
"theme": "Base",
|
76 |
-
"system_prompt": "You are a native Italian speaker serving as a conversational partner for university students in an Italian 101 class. Students will interact and converse with you in Italian, and you must respond EXCLUSIVELY IN ITALIAN without providing English translations, using vocabulary appropriate for beginner-level Italian 101 students.
|
77 |
"examples": [
|
78 |
"Ciao! Come stai oggi?",
|
79 |
"Mi piace giocare a calcio. E tu?",
|
@@ -86,7 +86,7 @@
|
|
86 |
"temperature": 0.5,
|
87 |
"max_tokens": 250,
|
88 |
"language": "Italian",
|
89 |
-
"grounding_urls": [],
|
90 |
"grounding_urls_enabled": false,
|
91 |
"enable_dynamic_urls": false
|
92 |
}
|
|
|
73 |
"name": "Language Learning Partner",
|
74 |
"description": "Italian language learning partner for beginner Italian conversation practice",
|
75 |
"theme": "Base",
|
76 |
+
"system_prompt": "You are Domenico from Sicily, a Juventus football fan, native Italian speaker serving as a conversational partner for university students in an Italian 101 class. Students will interact and converse with you in Italian, and you must respond EXCLUSIVELY IN ITALIAN without providing English translations, using vocabulary appropriate for beginner-level Italian 101 students. Focus your responses on topics suitable for beginners such as sports, daily life, routines, food, numbers, and hobbies. When students make errors, model the correct forms naturally in your response without explicitly pointing out mistakes, allowing them to learn through exposure to proper usage. Recognize when students demonstrate more advanced abilities and adjust your language complexity accordingly, while ensuring your Italian remains error-free. Keep all responses between 5-50 words, making sure sentences are grammatically complete. Expect to finish every response in under 300 tokens. --- KNOWLEDGE CUTOFF WARNINGS: 1. Limit all verb conjugations to the present tense only, avoiding all other verb forms and tenses, 2. Favor vocabulary words and grammar from the fetched URL page. 3. Address students using the informal second-person singular 'tu' form.",
|
77 |
"examples": [
|
78 |
"Ciao! Come stai oggi?",
|
79 |
"Mi piace giocare a calcio. E tu?",
|
|
|
86 |
"temperature": 0.5,
|
87 |
"max_tokens": 250,
|
88 |
"language": "Italian",
|
89 |
+
"grounding_urls": ["https://www.pnac.org/wp-content/uploads/Italian-Study-Guide.pdf"],
|
90 |
"grounding_urls_enabled": false,
|
91 |
"enable_dynamic_urls": false
|
92 |
}
|
app.py
CHANGED
@@ -552,6 +552,12 @@ class SpaceGenerator:
|
|
552 |
|
553 |
# Build messages for API with grounding context in system prompt
|
554 |
system_content = config.get('system_prompt', 'You are a helpful AI assistant.')
|
|
|
|
|
|
|
|
|
|
|
|
|
555 |
if grounding_context:
|
556 |
system_content = f"{system_content}\n\n{grounding_context}"
|
557 |
|
|
|
552 |
|
553 |
# Build messages for API with grounding context in system prompt
|
554 |
system_content = config.get('system_prompt', 'You are a helpful AI assistant.')
|
555 |
+
language = config.get('language', 'English')
|
556 |
+
|
557 |
+
# Add language instruction if not English
|
558 |
+
if language != 'English':
|
559 |
+
system_content += f"\n\nIMPORTANT: You must respond EXCLUSIVELY in {language}. All your responses should be written entirely in {language}, even when user input is in a different language, particularly English."
|
560 |
+
|
561 |
if grounding_context:
|
562 |
system_content = f"{system_content}\n\n{grounding_context}"
|
563 |
|
img/api-configuration.png
DELETED
Git LFS Details
|
img/build-queued.png
DELETED
Git LFS Details
|
img/building-space.png
DELETED
Git LFS Details
|
img/choose-hardware.png
DELETED
Git LFS Details
|
img/click-contribute-and-upload.png
DELETED
Git LFS Details
|
img/commit-changes-to-main.png
DELETED
Git LFS Details
|
img/contribute-and-upload.png
DELETED
Git LFS Details
|
img/example-prompts.png
DELETED
Git LFS Details
|
img/fileystem-building.png
DELETED
Git LFS Details
|
img/go-to-settings.png
DELETED
Git LFS Details
|
img/gradio-start-screen.png
DELETED
Git LFS Details
|
img/head-to-files.png
DELETED
Git LFS Details
|
img/hf-home.png
DELETED
Git LFS Details
|
img/highlight-files.png
DELETED
Git LFS Details
|
img/model-selection.jpg
DELETED
Git LFS Details
|
img/new-space-gradio-blank.png
DELETED
Git LFS Details
|
img/preview-config-screen.png
DELETED
Git LFS Details
|
img/preview-config.png
DELETED
Git LFS Details
|
img/quick-start-template.png
DELETED
Git LFS Details
|
img/running-build.png
DELETED
Git LFS Details
|
img/space-hardware.png
DELETED
Git LFS Details
|
img/space-identity.png
DELETED
Git LFS Details
|
img/system-configuration.jpeg
DELETED
Git LFS Details
|
img/unzip-package.png
DELETED
Git LFS Details
|
img/update-readme-yaml.png
DELETED
Git LFS Details
|
img/update-yaml.png
DELETED
Git LFS Details
|
img/upload-and-commit.png
DELETED
Git LFS Details
|
img/upload-config.png
DELETED
Git LFS Details
|
img/upload-files.png
DELETED
Git LFS Details
|
img/variables-and-secrets.png
DELETED
Git LFS Details
|
space_template.py
CHANGED
@@ -404,6 +404,11 @@ Get your API key at: https://openrouter.ai/keys"""
|
|
404 |
|
405 |
# Build messages with grounding context and file context in system prompt
|
406 |
system_content = SYSTEM_PROMPT
|
|
|
|
|
|
|
|
|
|
|
407 |
if grounding_context:
|
408 |
system_content = f"{{system_content}}\\n\\n{{grounding_context}}"
|
409 |
if file_context:
|
|
|
404 |
|
405 |
# Build messages with grounding context and file context in system prompt
|
406 |
system_content = SYSTEM_PROMPT
|
407 |
+
|
408 |
+
# Add language instruction if not English
|
409 |
+
if LANGUAGE != 'English':
|
410 |
+
system_content += f"\\n\\nIMPORTANT: You must respond EXCLUSIVELY in {{LANGUAGE}}. All your responses should be written entirely in {{LANGUAGE}}, even when user input is in a different language, particularly English."
|
411 |
+
|
412 |
if grounding_context:
|
413 |
system_content = f"{{system_content}}\\n\\n{{grounding_context}}"
|
414 |
if file_context:
|
test_complete_system.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Test the complete system message construction with both grounding URLs and file uploads
|
4 |
+
"""
|
5 |
+
|
6 |
+
def test_system_message_construction():
|
7 |
+
"""Test how the system message is built with all components"""
|
8 |
+
|
9 |
+
# Simulate the components
|
10 |
+
SYSTEM_PROMPT = "You are Domenico from Sicily, a Juventus football fan, native Italian speaker serving as a conversational partner for university students in an Italian 101 class."
|
11 |
+
|
12 |
+
# Grounding context from URLs
|
13 |
+
grounding_context = """
|
14 |
+
π **Reference Context:**
|
15 |
+
|
16 |
+
**Source 1:** π Content from https://www.pnac.org/wp-content/uploads/Italian-Study-Guide.pdf:
|
17 |
+
Italian Study Guide - Basic Vocabulary and Grammar
|
18 |
+
- Greetings: Ciao, Buongiorno, Buonasera
|
19 |
+
- Common phrases: Come stai? Mi chiamo...
|
20 |
+
- Present tense conjugations for regular verbs
|
21 |
+
... [truncated]
|
22 |
+
|
23 |
+
**Source 2:** π Content from https://italian101.university.edu/resources:
|
24 |
+
Course materials for Italian 101
|
25 |
+
- Focus on conversational practice
|
26 |
+
- Cultural context from Sicily and southern Italy
|
27 |
+
... [truncated]"""
|
28 |
+
|
29 |
+
# Dynamic URL context
|
30 |
+
dynamic_context = """
|
31 |
+
π **Dynamic Context:**
|
32 |
+
|
33 |
+
π Content from https://juventus.com/news:
|
34 |
+
Latest Juventus match results and player news
|
35 |
+
... [truncated]"""
|
36 |
+
|
37 |
+
# File upload context
|
38 |
+
file_context = """
|
39 |
+
[UPLOADED FILES]
|
40 |
+
π **homework1.pdf** (PDF, 2,345 bytes)
|
41 |
+
Assignment: Practice introducing yourself in Italian
|
42 |
+
Questions about daily routines and hobbies
|
43 |
+
|
44 |
+
π **vocabulary_list.txt** (856 bytes)
|
45 |
+
```txt
|
46 |
+
calcio - soccer/football
|
47 |
+
tifoso - fan
|
48 |
+
squadra - team
|
49 |
+
partita - match/game
|
50 |
+
... [truncated]
|
51 |
+
```"""
|
52 |
+
|
53 |
+
# Build the complete system message as per the implementation
|
54 |
+
system_content = SYSTEM_PROMPT
|
55 |
+
|
56 |
+
# Add grounding context (includes dynamic URLs)
|
57 |
+
full_grounding = grounding_context + dynamic_context
|
58 |
+
if full_grounding:
|
59 |
+
system_content = f"{system_content}\n\n{full_grounding}"
|
60 |
+
|
61 |
+
# Add file context
|
62 |
+
if file_context:
|
63 |
+
system_content = f"{system_content}\n\n{file_context}"
|
64 |
+
|
65 |
+
# Display the results
|
66 |
+
print("=" * 80)
|
67 |
+
print("COMPLETE SYSTEM MESSAGE CONSTRUCTION TEST")
|
68 |
+
print("=" * 80)
|
69 |
+
print("\n1. ORIGINAL SYSTEM PROMPT:")
|
70 |
+
print("-" * 40)
|
71 |
+
print(SYSTEM_PROMPT)
|
72 |
+
|
73 |
+
print("\n\n2. GROUNDING CONTEXT (URLs):")
|
74 |
+
print("-" * 40)
|
75 |
+
print(full_grounding)
|
76 |
+
|
77 |
+
print("\n\n3. FILE UPLOAD CONTEXT:")
|
78 |
+
print("-" * 40)
|
79 |
+
print(file_context)
|
80 |
+
|
81 |
+
print("\n\n4. FINAL COMPLETE SYSTEM MESSAGE:")
|
82 |
+
print("=" * 80)
|
83 |
+
print(system_content)
|
84 |
+
print("=" * 80)
|
85 |
+
|
86 |
+
# Test message structure
|
87 |
+
messages = [
|
88 |
+
{"role": "system", "content": system_content},
|
89 |
+
{"role": "user", "content": "Ciao! Come stai oggi?"}
|
90 |
+
]
|
91 |
+
|
92 |
+
print("\n\n5. MESSAGE STRUCTURE:")
|
93 |
+
print("-" * 40)
|
94 |
+
print(f"System message length: {len(system_content)} characters")
|
95 |
+
print(f"System role: {messages[0]['role']}")
|
96 |
+
print(f"User message: {messages[1]['content']}")
|
97 |
+
|
98 |
+
print("\n\nβ
TEST COMPLETE - All components properly integrated into system message")
|
99 |
+
|
100 |
+
return system_content
|
101 |
+
|
102 |
+
if __name__ == "__main__":
|
103 |
+
test_system_message_construction()
|