Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,40 @@ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
|
| 38 |
# Database configuration
|
| 39 |
DATABASE_PATH = '/tmp/chat_database.db'
|
| 40 |
|
| 41 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
@contextmanager
|
| 43 |
def get_db_connection():
|
| 44 |
"""Context manager for database connections"""
|
|
@@ -666,6 +699,10 @@ try:
|
|
| 666 |
print("Starting model initialization...")
|
| 667 |
llm = initialize_model()
|
| 668 |
print("Model initialized successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 669 |
except Exception as e:
|
| 670 |
print(f"Initialization error: {e}")
|
| 671 |
raise
|
|
|
|
| 38 |
# Database configuration
|
| 39 |
DATABASE_PATH = '/tmp/chat_database.db'
|
| 40 |
|
| 41 |
+
# Initialize prompt template
|
| 42 |
+
prompt_template = """
|
| 43 |
+
Role: You are Figr Code Assistant, specializing in providing clear, error-free Python code solutions.
|
| 44 |
+
|
| 45 |
+
Context:
|
| 46 |
+
{important_info}
|
| 47 |
+
|
| 48 |
+
Previous Conversation:
|
| 49 |
+
{chat_history}
|
| 50 |
+
|
| 51 |
+
Current Request:
|
| 52 |
+
{user_request}
|
| 53 |
+
|
| 54 |
+
Output Guidelines:
|
| 55 |
+
1. Code Format:
|
| 56 |
+
- Use ```python for code blocks
|
| 57 |
+
- Use `code` for inline code references
|
| 58 |
+
- Provide raw text without HTML formatting
|
| 59 |
+
- Strictly include explanation only after code blocks
|
| 60 |
+
|
| 61 |
+
2. Code Organization:
|
| 62 |
+
- Default to single, focused code snippets for clarity
|
| 63 |
+
- Only split into multiple snippets(each individually runnable) if:
|
| 64 |
+
a) Multiple distinct concepts are requested
|
| 65 |
+
b) Complex functionality requires modular explanation
|
| 66 |
+
|
| 67 |
+
- Mark critical information with [IMPORTANT] prefix and give small explanations with some bold headings if required and in white font always.
|
| 68 |
+
"""
|
| 69 |
+
|
| 70 |
+
prompt = PromptTemplate(
|
| 71 |
+
input_variables=["user_request", "chat_history", "important_info"],
|
| 72 |
+
template=prompt_template
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
@contextmanager
|
| 76 |
def get_db_connection():
|
| 77 |
"""Context manager for database connections"""
|
|
|
|
| 699 |
print("Starting model initialization...")
|
| 700 |
llm = initialize_model()
|
| 701 |
print("Model initialized successfully")
|
| 702 |
+
|
| 703 |
+
print("Creating LLM chain...")
|
| 704 |
+
llm_chain = LLMChain(llm=llm, prompt=prompt)
|
| 705 |
+
print("LLM chain created successfully")
|
| 706 |
except Exception as e:
|
| 707 |
print(f"Initialization error: {e}")
|
| 708 |
raise
|