File tree Expand file tree Collapse file tree 2 files changed +1
-10
lines changed
samples/agentic-strands/app Expand file tree Collapse file tree 2 files changed +1
-10
lines changed Original file line number Diff line number Diff line change 35
35
)
36
36
37
37
def parse_assistant_response (** kwargs ):
38
- # print(json.dumps(kwargs["message"], indent=2)) # Debugging line
39
-
40
- # Extract the assistant's text message
38
+ # Extract the assistant's text message from JSON
41
39
assistant_text = kwargs ["message" ]["content" ][0 ]["text" ]
42
40
43
41
print ("Assistant Text: " , assistant_text )
@@ -129,7 +127,6 @@ def search_for_books(query, filters=None) -> str:
129
127
130
128
print ("Agent model:" , agent .model .config )
131
129
132
-
133
130
# Flask routes
134
131
@app .route ('/' )
135
132
def index ():
@@ -145,24 +142,19 @@ def chat():
145
142
return jsonify ({"error" : "No JSON data received" }), 400
146
143
147
144
user_message = data .get ('message' )
148
-
149
145
if not user_message :
150
146
return jsonify ({"error" : "No message provided" }), 400
151
-
152
147
print (f"Received message: { user_message } " )
153
148
154
149
agent (f"Continue the conversation with the user. The user says: { user_message } " )
155
150
156
- # # Return the response from latest_response
157
151
response_content = latest_response .get ("message" , "I'm thinking about your question..." )
158
152
159
153
return jsonify ({
160
154
"response" : response_content
161
155
})
162
156
163
157
except Exception as e :
164
- import traceback
165
- traceback .print_exc ()
166
158
print (f"Error in /chat endpoint: { str (e )} " )
167
159
return jsonify ({"error" : str (e ), "response" : str (e )}), 500
168
160
Original file line number Diff line number Diff line change @@ -65,7 +65,6 @@ <h1>Library Assistant AI</h1>
65
65
< p > Chat with our AI Library Assistant to get personalized book recommendations.</ p >
66
66
67
67
< div class ="chat-container " id ="chat-container ">
68
- <!-- Messages will appear here -->
69
68
< div class ="message agent-message ">
70
69
Hello! I'm your library assistant. How can I help you with your reading today?
71
70
</ div >
You can’t perform that action at this time.
0 commit comments