Spaces:
Sleeping
Sleeping
Commit
·
373601c
1
Parent(s):
8f87470
Fix chunk jumping
Browse files- backend/app.py +9 -3
- backend/prompts/transition_prompt.txt +2 -2
backend/app.py
CHANGED
|
@@ -195,12 +195,12 @@ async def chat_stream(request: ChatRequest):
|
|
| 195 |
print(f"include_document: {include_document} (messages: {len(request.messages)}, action: {action})")
|
| 196 |
print(f"current_chunk: {current_chunk[:100] if current_chunk else 'None'}")
|
| 197 |
print(f"next_chunk: {next_chunk[:100] if next_chunk else 'None'}")
|
|
|
|
| 198 |
if is_transition:
|
| 199 |
system_prompt = TRANSITION_PROMPT_TEMPLATE.format(
|
| 200 |
action=action,
|
| 201 |
current_chunk=current_chunk,
|
| 202 |
next_chunk=next_chunk,
|
| 203 |
-
document=document
|
| 204 |
)
|
| 205 |
print(f"Transition system prompt: {system_prompt[:200]}...")
|
| 206 |
else:
|
|
@@ -230,8 +230,14 @@ async def chat_stream(request: ChatRequest):
|
|
| 230 |
if msg.role in ["user", "assistant"]
|
| 231 |
]
|
| 232 |
print(anthropic_messages)
|
| 233 |
-
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
if is_transition:
|
| 236 |
anthropic_messages.append({"role": "user", "content": "Please continue to the next section."})
|
| 237 |
else:
|
|
|
|
| 195 |
print(f"include_document: {include_document} (messages: {len(request.messages)}, action: {action})")
|
| 196 |
print(f"current_chunk: {current_chunk[:100] if current_chunk else 'None'}")
|
| 197 |
print(f"next_chunk: {next_chunk[:100] if next_chunk else 'None'}")
|
| 198 |
+
print(f"user_goal: {user_goal if user_goal else 'None'}")
|
| 199 |
if is_transition:
|
| 200 |
system_prompt = TRANSITION_PROMPT_TEMPLATE.format(
|
| 201 |
action=action,
|
| 202 |
current_chunk=current_chunk,
|
| 203 |
next_chunk=next_chunk,
|
|
|
|
| 204 |
)
|
| 205 |
print(f"Transition system prompt: {system_prompt[:200]}...")
|
| 206 |
else:
|
|
|
|
| 230 |
if msg.role in ["user", "assistant"]
|
| 231 |
]
|
| 232 |
print(anthropic_messages)
|
| 233 |
+
|
| 234 |
+
# Ensure the conversation ends with a user message for thinking mode
|
| 235 |
+
if anthropic_messages and anthropic_messages[-1]["role"] == "assistant":
|
| 236 |
+
if is_transition:
|
| 237 |
+
anthropic_messages.append({"role": "user", "content": "Please continue to the next section."})
|
| 238 |
+
else:
|
| 239 |
+
anthropic_messages.append({"role": "user", "content": "Please continue."})
|
| 240 |
+
elif not any(msg["role"] == "user" for msg in anthropic_messages):
|
| 241 |
if is_transition:
|
| 242 |
anthropic_messages.append({"role": "user", "content": "Please continue to the next section."})
|
| 243 |
else:
|
backend/prompts/transition_prompt.txt
CHANGED
|
@@ -3,7 +3,6 @@ The user has just chosen to "{action}" the previous section and is moving to a n
|
|
| 3 |
|
| 4 |
Previous Section: {current_chunk}
|
| 5 |
New Section: {next_chunk}
|
| 6 |
-
Full Document: {document}
|
| 7 |
|
| 8 |
TRANSITION INSTRUCTIONS:
|
| 9 |
|
|
@@ -26,4 +25,5 @@ TRANSITION INSTRUCTIONS:
|
|
| 26 |
- Maintain momentum - this is a continuation, not a restart
|
| 27 |
- Stay focused on phenomenological understanding and observables
|
| 28 |
|
| 29 |
-
Start by acknowledging their {action} choice, then smoothly transition to introducing the new section and begin your first question about {next_chunk}.
|
|
|
|
|
|
| 3 |
|
| 4 |
Previous Section: {current_chunk}
|
| 5 |
New Section: {next_chunk}
|
|
|
|
| 6 |
|
| 7 |
TRANSITION INSTRUCTIONS:
|
| 8 |
|
|
|
|
| 25 |
- Maintain momentum - this is a continuation, not a restart
|
| 26 |
- Stay focused on phenomenological understanding and observables
|
| 27 |
|
| 28 |
+
Start by acknowledging their {action} choice, then smoothly transition to introducing the new section and begin your first question about {next_chunk}. Don't get ahead of yourself, and adapt the difficulty of your questions based on the user's previous answers.
|
| 29 |
+
Also, don't ask questions about material that you haven't talked about.
|