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 3535)
3636
3737def 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
4139 assistant_text = kwargs ["message" ]["content" ][0 ]["text" ]
4240
4341 print ("Assistant Text: " , assistant_text )
@@ -129,7 +127,6 @@ def search_for_books(query, filters=None) -> str:
129127
130128print ("Agent model:" , agent .model .config )
131129
132-
133130# Flask routes
134131@app .route ('/' )
135132def index ():
@@ -145,24 +142,19 @@ def chat():
145142 return jsonify ({"error" : "No JSON data received" }), 400
146143
147144 user_message = data .get ('message' )
148-
149145 if not user_message :
150146 return jsonify ({"error" : "No message provided" }), 400
151-
152147 print (f"Received message: { user_message } " )
153148
154149 agent (f"Continue the conversation with the user. The user says: { user_message } " )
155150
156- # # Return the response from latest_response
157151 response_content = latest_response .get ("message" , "I'm thinking about your question..." )
158152
159153 return jsonify ({
160154 "response" : response_content
161155 })
162156
163157 except Exception as e :
164- import traceback
165- traceback .print_exc ()
166158 print (f"Error in /chat endpoint: { str (e )} " )
167159 return jsonify ({"error" : str (e ), "response" : str (e )}), 500
168160
Original file line number Diff line number Diff line change @@ -65,7 +65,6 @@ <h1>Library Assistant AI</h1>
6565 < p > Chat with our AI Library Assistant to get personalized book recommendations.</ p >
6666
6767 < div class ="chat-container " id ="chat-container ">
68- <!-- Messages will appear here -->
6968 < div class ="message agent-message ">
7069 Hello! I'm your library assistant. How can I help you with your reading today?
7170 </ div >
You can’t perform that action at this time.
0 commit comments