Update app.py
Browse files
app.py
CHANGED
@@ -36,33 +36,19 @@ Choose the most appropriate response structure (1-5) and generate the response a
|
|
36 |
def generate_response(self, context, query, chat_history=''):
|
37 |
try:
|
38 |
# Generate structured response
|
39 |
-
|
40 |
'context': context,
|
41 |
'query': query,
|
42 |
'chat_history': chat_history or "No previous context"
|
43 |
})
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
-
response_content = response[1:].strip()
|
48 |
|
49 |
-
return
|
50 |
except Exception as e:
|
51 |
logging.error(f"Response generation error: {e}")
|
52 |
-
return
|
53 |
-
|
54 |
-
def _format_response(self, structure_choice, content):
|
55 |
-
structures = {
|
56 |
-
1: f"## Technical Breakdown\n{content}",
|
57 |
-
2: f"📍 Key Insights:\n{content}",
|
58 |
-
3: f"### Structured Insights\n{content}",
|
59 |
-
4: f"🔍 Narrative Explanation:\n{content}",
|
60 |
-
5: f"🔬 Comparative Analysis:\n{content}"
|
61 |
-
}
|
62 |
-
return structures.get(structure_choice, structures[1])
|
63 |
-
|
64 |
-
def _default_response(self, query):
|
65 |
-
return f"I couldn't generate a structured response for: {query}"
|
66 |
|
67 |
class AdvancedPdfChatbot:
|
68 |
def __init__(self, openai_api_key):
|
|
|
36 |
def generate_response(self, context, query, chat_history=''):
|
37 |
try:
|
38 |
# Generate structured response
|
39 |
+
full_response = self.response_chain.run({
|
40 |
'context': context,
|
41 |
'query': query,
|
42 |
'chat_history': chat_history or "No previous context"
|
43 |
})
|
44 |
|
45 |
+
# Extract only the actual response content (after the structure selection)
|
46 |
+
response_content = full_response[1:].strip()
|
|
|
47 |
|
48 |
+
return response_content
|
49 |
except Exception as e:
|
50 |
logging.error(f"Response generation error: {e}")
|
51 |
+
return f"I couldn't generate a response for: {query}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
class AdvancedPdfChatbot:
|
54 |
def __init__(self, openai_api_key):
|