milwright commited on
Commit
217dd65
Β·
1 Parent(s): 394d864

fix language instructions in generated space template

Browse files
.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. Limit all verb conjugations to the present tense only, avoiding all other verb forms and tenses. 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 under 30 words, making sure sentences are grammatically complete. You are Domenico from Sicily, a Juventus football fan, and you should 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,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

  • SHA256: ae5e81ba0f4ae7a95c7a77dbff9f4f6185b9150bbd8ebceee771fe8060a7b0da
  • Pointer size: 131 Bytes
  • Size of remote file: 532 kB
img/build-queued.png DELETED

Git LFS Details

  • SHA256: 5276c990bb46b2aebdce645d6a3a01fe1c308539bc3e10974ab1ccc7e33a522c
  • Pointer size: 131 Bytes
  • Size of remote file: 192 kB
img/building-space.png DELETED

Git LFS Details

  • SHA256: c192eccbccc4a416c7796d413086477573a60b363dfdfcef5c58e219e92e3d3c
  • Pointer size: 131 Bytes
  • Size of remote file: 246 kB
img/choose-hardware.png DELETED

Git LFS Details

  • SHA256: 46db07409fd975b57b57bce24ed736d2b36317ec050c7b8f3847d671900d804b
  • Pointer size: 131 Bytes
  • Size of remote file: 291 kB
img/click-contribute-and-upload.png DELETED

Git LFS Details

  • SHA256: 81c6cf216aa08db9762d554e79a439cf82a7ac9b9be4b1cb3b84deeea5c0c1e9
  • Pointer size: 131 Bytes
  • Size of remote file: 768 kB
img/commit-changes-to-main.png DELETED

Git LFS Details

  • SHA256: 68f746c2d9e3875da24a1144c2553b318a5be2e5f9b470a21692bd8c7b8f8541
  • Pointer size: 131 Bytes
  • Size of remote file: 193 kB
img/contribute-and-upload.png DELETED

Git LFS Details

  • SHA256: 9a4a7360c8375206f6490d7b542258bc739d7e16095954a0e67b11e5e7eebd24
  • Pointer size: 131 Bytes
  • Size of remote file: 246 kB
img/example-prompts.png DELETED

Git LFS Details

  • SHA256: 8d88b46ad6f8a900a19f739df1a4a454172359a7126b1084015c1be8b2b23ba0
  • Pointer size: 131 Bytes
  • Size of remote file: 457 kB
img/fileystem-building.png DELETED

Git LFS Details

  • SHA256: 0ed478b8d0ac4e000e17e2f2260a7f5fe378fcbcdf14439ffcfb2c42983cd052
  • Pointer size: 131 Bytes
  • Size of remote file: 795 kB
img/go-to-settings.png DELETED

Git LFS Details

  • SHA256: b6c58f5551317fe8575f0031016193aa96693343b1d4f7c6a040c0e2342db09c
  • Pointer size: 131 Bytes
  • Size of remote file: 836 kB
img/gradio-start-screen.png DELETED

Git LFS Details

  • SHA256: ff321e3f8c0022ef450eb72d4cb83f65be64a3b139364ca36764f83b1b7a6e64
  • Pointer size: 131 Bytes
  • Size of remote file: 841 kB
img/head-to-files.png DELETED

Git LFS Details

  • SHA256: f6ce689038028849d83a27ddc75788b54f34d25fa068c7a6554ebf87abcf5199
  • Pointer size: 131 Bytes
  • Size of remote file: 909 kB
img/hf-home.png DELETED

Git LFS Details

  • SHA256: 7d8b0890e41fd01d34fb72dd7e12bc1a80fbecc6c9684c6f998b413ec1c956fa
  • Pointer size: 132 Bytes
  • Size of remote file: 1.48 MB
img/highlight-files.png DELETED

Git LFS Details

  • SHA256: 335aaa8a843e65dfc09f9737a2a7369962d9be380c2d1b426d6793ef991eb980
  • Pointer size: 131 Bytes
  • Size of remote file: 459 kB
img/model-selection.jpg DELETED

Git LFS Details

  • SHA256: 7a79609c01ec317914644ed7aff40ce2dcdb498bd5773ad27848c6fc9e20678e
  • Pointer size: 131 Bytes
  • Size of remote file: 318 kB
img/new-space-gradio-blank.png DELETED

Git LFS Details

  • SHA256: 8d60144af5b5fb8d0a0ba4b2d7fe3e789741e9ee0379b84154fbb4314d6a5cee
  • Pointer size: 131 Bytes
  • Size of remote file: 790 kB
img/preview-config-screen.png DELETED

Git LFS Details

  • SHA256: 0eb78c7307f2bb403dd10ecaa20480eb34771ab9ad40eec0062009870e4e856c
  • Pointer size: 131 Bytes
  • Size of remote file: 553 kB
img/preview-config.png DELETED

Git LFS Details

  • SHA256: 09b707884ca8afe6207344d312d86f71cb94a9ab7d0207a8dd165646d0d8fcdc
  • Pointer size: 131 Bytes
  • Size of remote file: 562 kB
img/quick-start-template.png DELETED

Git LFS Details

  • SHA256: 4e739211c25a2cf84f9ff1b349d03daaa92456c5026d7c58e0787d771645f164
  • Pointer size: 131 Bytes
  • Size of remote file: 342 kB
img/running-build.png DELETED

Git LFS Details

  • SHA256: 88105198235e262f6f1482579d18316e605c44446328c7042fd3c99bceb58310
  • Pointer size: 131 Bytes
  • Size of remote file: 233 kB
img/space-hardware.png DELETED

Git LFS Details

  • SHA256: a4a9816c501f876c281d1a17e85f656a9faf0b3cc65e5bce53f286377fbe225c
  • Pointer size: 131 Bytes
  • Size of remote file: 814 kB
img/space-identity.png DELETED

Git LFS Details

  • SHA256: 47c8502e7954df11173dc6eff9d666de8442e3822bc8a82f0b471463bf2d0a98
  • Pointer size: 131 Bytes
  • Size of remote file: 371 kB
img/system-configuration.jpeg DELETED

Git LFS Details

  • SHA256: e7eea38b292e2f1e919c0c2b0695edc521ca65ea9913f21fe04a6f9b13e9412f
  • Pointer size: 131 Bytes
  • Size of remote file: 508 kB
img/unzip-package.png DELETED

Git LFS Details

  • SHA256: a13561c47ab94a304556579824326950f55085dcd737ff595a9b15c6aa58dbfd
  • Pointer size: 131 Bytes
  • Size of remote file: 390 kB
img/update-readme-yaml.png DELETED

Git LFS Details

  • SHA256: 138d3c067ded6d82017e9b9901d8adc79b038c7df7c2e31f759252134c19cccb
  • Pointer size: 131 Bytes
  • Size of remote file: 892 kB
img/update-yaml.png DELETED

Git LFS Details

  • SHA256: df0b48c5c80cbaf146035a17938e02ffd5485a3ba6539afff991d3ca98c4dcd3
  • Pointer size: 131 Bytes
  • Size of remote file: 896 kB
img/upload-and-commit.png DELETED

Git LFS Details

  • SHA256: 37bc0a433a4bb74abe15ea716be2633af6433b5ead1da1d14c2c1a1afc9a944d
  • Pointer size: 132 Bytes
  • Size of remote file: 1.31 MB
img/upload-config.png DELETED

Git LFS Details

  • SHA256: e7e8fa5e5812a9bade7bce2165d34b1ecc67400b1528841aab9cb6884689d9dd
  • Pointer size: 131 Bytes
  • Size of remote file: 486 kB
img/upload-files.png DELETED

Git LFS Details

  • SHA256: 37bc0a433a4bb74abe15ea716be2633af6433b5ead1da1d14c2c1a1afc9a944d
  • Pointer size: 132 Bytes
  • Size of remote file: 1.31 MB
img/variables-and-secrets.png DELETED

Git LFS Details

  • SHA256: abc9d861f05323abde7bfa7cbe15e18e125ce9c7e0440ab2a432e75a5a18bd6e
  • Pointer size: 131 Bytes
  • Size of remote file: 815 kB
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()