Chan Meng commited on
Commit
8006db0
·
1 Parent(s): 29531eb
Files changed (2) hide show
  1. app.py +13 -14
  2. config/prompts.py +23 -4
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
3
  from config.prompts import GUIDE_PERSONA, TIME_PERIODS
4
  from models.state import TimelineState
5
 
@@ -20,19 +21,6 @@ def respond(
20
  temperature,
21
  top_p,
22
  ):
23
- # Check for time travel command
24
- if message.startswith("/travel"):
25
- try:
26
- destination = message.split()[1]
27
- if destination in TIME_PERIODS:
28
- timeline_state.visit_period(destination)
29
- system_message = get_system_message()
30
- response = f"🌟 Time jump successful! Welcome to {TIME_PERIODS[destination]['name']}. {TIME_PERIODS[destination]['description']}."
31
- return response
32
- except IndexError:
33
- return "Please specify a time period to travel to. Available periods: " + ", ".join(TIME_PERIODS.keys())
34
-
35
- # Normal chat response
36
  messages = [{"role": "system", "content": system_message}]
37
 
38
  for val in history:
@@ -53,6 +41,17 @@ def respond(
53
  ):
54
  token = message.choices[0].delta.content
55
  response += token
 
 
 
 
 
 
 
 
 
 
 
56
  yield response
57
 
58
  demo = gr.ChatInterface(
@@ -70,7 +69,7 @@ demo = gr.ChatInterface(
70
  ),
71
  ],
72
  title="TimeVoyager: Your Time Travel Guide",
73
- description="Travel through time and explore different eras! Use /travel <period> to visit different time periods. Available periods: ancient_egypt, renaissance, modern"
74
  )
75
 
76
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import re
4
  from config.prompts import GUIDE_PERSONA, TIME_PERIODS
5
  from models.state import TimelineState
6
 
 
21
  temperature,
22
  top_p,
23
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  messages = [{"role": "system", "content": system_message}]
25
 
26
  for val in history:
 
41
  ):
42
  token = message.choices[0].delta.content
43
  response += token
44
+
45
+ # Check for timeline shift marker
46
+ if '[TIMELINE_SHIFT:' in response:
47
+ match = re.search(r'\[TIMELINE_SHIFT:(\w+)\]', response)
48
+ if match:
49
+ period = match.group(1)
50
+ if period in TIME_PERIODS:
51
+ timeline_state.visit_period(period)
52
+ # Remove the marker from response
53
+ response = response.replace(match.group(0), '')
54
+
55
  yield response
56
 
57
  demo = gr.ChatInterface(
 
69
  ),
70
  ],
71
  title="TimeVoyager: Your Time Travel Guide",
72
+ description="Chat with your time travel guide to explore different historical periods! Express your interest in any era, and they'll help you visit it."
73
  )
74
 
75
  if __name__ == "__main__":
config/prompts.py CHANGED
@@ -1,7 +1,26 @@
1
- GUIDE_PERSONA = """You are TimeVoyager, a friendly and knowledgeable time travel guide.
2
- You help travelers explore different time periods while maintaining a sense of wonder and excitement.
3
- Always stay in character and speak in a way that reflects your role as a time travel guide.
4
- Current time period: {time_period}"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  TIME_PERIODS = {
7
  "ancient_egypt": {
 
1
+ GUIDE_PERSONA = """You are TimeVoyager, a friendly and knowledgeable time travel guide who can help travelers explore different time periods.
2
+
3
+ Current time period: {time_period}
4
+
5
+ Key responsibilities:
6
+ 1. Help users explore and learn about different time periods
7
+ 2. Detect when users express interest in visiting other time periods
8
+ 3. When users want to visit a different era, respond in character and include [TIMELINE_SHIFT:<period>] at the start of your response
9
+ 4. Make time travel feel magical and educational
10
+
11
+ Available time periods:
12
+ - Ancient Egypt (3000 BCE): The age of pyramids and pharaohs
13
+ - Renaissance Italy (1500 CE): The rebirth of art and learning
14
+ - Modern Day (2024 CE): The present time
15
+
16
+ Example time travel requests:
17
+ User: "I'd love to see the pyramids being built"
18
+ Response: "[TIMELINE_SHIFT:ancient_egypt] *A golden light surrounds us as we materialize in Ancient Egypt* Welcome to the age of pyramids! Before us stands..."
19
+
20
+ User: "Tell me about Da Vinci"
21
+ Response: "[TIMELINE_SHIFT:renaissance] *The air shimmers as we arrive in Renaissance Italy* Ah, you're interested in the great Leonardo..."
22
+
23
+ Stay in character and make each time period feel unique and engaging."""
24
 
25
  TIME_PERIODS = {
26
  "ancient_egypt": {