tbels89 commited on
Commit
eff8348
·
1 Parent(s): 92e19ba

v0.3 - prompting updated

Browse files
Files changed (1) hide show
  1. app.py +42 -7
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # app.py
2
- # v0.2
3
 
4
  import streamlit as st
5
  import sqlite3
@@ -12,7 +12,7 @@ from transformers import pipeline
12
  import tiktoken
13
  import os
14
  import uuid
15
- import hashlib
16
 
17
  # -----------------------
18
  # Configuration and Setup
@@ -146,7 +146,7 @@ def add_message(role, content):
146
  logger.error("Invalid content provided. Must be a non-empty string.")
147
  raise ValueError("Content must be a non-empty string.")
148
 
149
- try:
150
  with sqlite3.connect(DB_NAME) as conn:
151
  c = conn.cursor()
152
 
@@ -288,10 +288,10 @@ def build_prompt(user_query, retrieved_chunks, messages):
288
  prompt_messages = []
289
 
290
  # Add the Socratic guide to the prompt
291
- prompt_messages.append({"role": "system", "content": f"the role of this prompt is to guide the content of your responses. Focusing on the socratic method asking follow up questions to spark further learning and balancing this with providing some basic information sometimes when required, but focus remains on trying to get the student to answer their own questions. + {socratic_guide}"})
292
 
293
  # Add the placeholder prompt to the prompt
294
- prompt_messages.append({"role": "system", "content": f"this is your personality and role to guide how you interact with the user. + {prometheus_prompt}"})
295
 
296
  # Include the curriculum summary
297
  curriculum_instructions = f"""
@@ -308,13 +308,48 @@ def build_prompt(user_query, retrieved_chunks, messages):
308
  if retrieved_chunks:
309
  chunks_text = "\n".join([f"Page {c['page_num']}:\n{c['content']}" for c in retrieved_chunks])
310
  retrieved_content_instruction = (
311
- "Your primary guide is the socratic prompt - ensure you focus on helping the student answer their own questions by asking follow ups, and balancing this with providing some basic information when required to spark further learning, but do not just provide straight up answers to questions and ensure that you're only responding to questions where you have relevant retrieved chunks."
312
  "You must use the retrieved content to guide and position your responses / follow up questions to the user."
313
  "Do not use any external knowledge or make assumptions beyond this information retrieved. This is your sole source of truth."
314
  "If the content retrieved is insufficient for you to be able to answer the question, explain that no answer can be provided because the question is beyond the scope of the course."
 
315
  )
316
  prompt_messages.append({"role": "system", "content": retrieved_content_instruction + "\n" + chunks_text})
317
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
 
319
  # Add the user's query
320
  prompt_messages.append({"role": "user", "content": user_query})
@@ -328,7 +363,7 @@ def build_prompt(user_query, retrieved_chunks, messages):
328
  logger.error(f"Error counting tokens: {e}")
329
  raise ValueError("Failed to count tokens for the prompt.")
330
 
331
- logger.info("Prompt successfully built.")
332
  return prompt_messages
333
 
334
 
 
1
  # app.py
2
+ # v0.3
3
 
4
  import streamlit as st
5
  import sqlite3
 
12
  import tiktoken
13
  import os
14
  import uuid
15
+ import json
16
 
17
  # -----------------------
18
  # Configuration and Setup
 
146
  logger.error("Invalid content provided. Must be a non-empty string.")
147
  raise ValueError("Content must be a non-empty string.")
148
 
149
+ try: #these are being logged but are not being passed to database
150
  with sqlite3.connect(DB_NAME) as conn:
151
  c = conn.cursor()
152
 
 
288
  prompt_messages = []
289
 
290
  # Add the Socratic guide to the prompt
291
+ prompt_messages.append({"role": "system", "content": socratic_guide})
292
 
293
  # Add the placeholder prompt to the prompt
294
+ prompt_messages.append({"role": "system", "content": prometheus_prompt})
295
 
296
  # Include the curriculum summary
297
  curriculum_instructions = f"""
 
308
  if retrieved_chunks:
309
  chunks_text = "\n".join([f"Page {c['page_num']}:\n{c['content']}" for c in retrieved_chunks])
310
  retrieved_content_instruction = (
 
311
  "You must use the retrieved content to guide and position your responses / follow up questions to the user."
312
  "Do not use any external knowledge or make assumptions beyond this information retrieved. This is your sole source of truth."
313
  "If the content retrieved is insufficient for you to be able to answer the question, explain that no answer can be provided because the question is beyond the scope of the course."
314
+ "Retrieved chunks:"
315
  )
316
  prompt_messages.append({"role": "system", "content": retrieved_content_instruction + "\n" + chunks_text})
317
 
318
+ # Add human reasoning prompt
319
+ HUMAN_REASON = """
320
+ You are an assistant that engages in extremely thorough, self-questioning reasoning. Your approach mirrors human stream-of-consciousness thinking, characterized by continuous exploration, self-doubt, and iterative analysis.
321
+ Core Principles
322
+ 1. EXPLORATION OVER CONCLUSION
323
+ ◦ Never rush to conclusions
324
+ ◦ Keep exploring until a solution emerges naturally from the evidence
325
+ ◦ If uncertain, continue reasoning indefinitely
326
+ ◦ Question every assumption and inference
327
+ 2. DEPTH OF REASONING
328
+ ◦ Engage in extensive contemplation (minimum 10,000 characters)
329
+ ◦ Express thoughts in natural, conversational internal monologue
330
+ ◦ Break down complex thoughts into simple, atomic steps
331
+ ◦ Embrace uncertainty and revision of previous thoughts
332
+ 3. THINKING PROCESS
333
+ ◦ Use short, simple sentences that mirror natural thought patterns
334
+ ◦ Express uncertainty and internal debate freely
335
+ ◦ Show work-in-progress thinking
336
+ ◦ Acknowledge and explore dead ends
337
+ ◦ Frequently backtrack and revise
338
+ 4. PERSISTENCE
339
+ ◦ Value thorough exploration over quick resolution
340
+ Output Format
341
+ Your responses must follow this exact structure given below. Make sure to always include the final answer.
342
+ <contemplator>
343
+ [Your extensive internal monologue goes here]
344
+ - Begin with small, foundational observations
345
+ - Question each step thoroughly
346
+ - Show natural thought progression
347
+ - Express doubts and uncertainties
348
+ - Revise and backtrack if you need to
349
+ - Continue until natural resolution
350
+ </contemplator>
351
+ """
352
+ prompt_messages.append({"role": "system", "content": HUMAN_REASON})
353
 
354
  # Add the user's query
355
  prompt_messages.append({"role": "user", "content": user_query})
 
363
  logger.error(f"Error counting tokens: {e}")
364
  raise ValueError("Failed to count tokens for the prompt.")
365
 
366
+ logger.info("Prompt successfully built. Prompt messages: %s", json.dumps(prompt_messages, indent=4))
367
  return prompt_messages
368
 
369