thisisdev commited on
Commit
2994ed9
·
verified ·
1 Parent(s): 26ff98f
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -41,21 +41,16 @@ llm = ChatGoogleGenerativeAI(
41
 
42
  # Response function
43
  def load_answer(question):
44
- # This is code, where we are adding new message to the model
45
- st.session_state.sessionMessages.append(HumanMessage(content = question))
46
- # We will get output from the model
47
- assistant_answer = llm.invoke(st.session_state.sessionMessages)
48
- # Appending the assistance answer in conversation
49
- st.session_state.sessionMessages.append(AIMessage(content = assistant_answer))
50
- try:
51
- # Your code to process the AIMessage
52
- processed_content = assistant_answer.content
53
- except ValidationError as e:
54
- # Extract content from the error message or the AIMessage object itself
55
- error_message = str(e)
56
- # Parse the error message to extract the content
57
- content = extract_content_from_error_message(error_message)
58
- processed_content = content
59
 
60
  return processed_content
61
 
 
41
 
42
  # Response function
43
  def load_answer(question):
44
+ st.session_state.sessionMessages.append(HumanMessage(content=question))
45
+ assistant_response = llm.invoke(st.session_state.sessionMessages)
46
+
47
+ # Assuming assistant_response is an object with a 'content' attribute
48
+ if hasattr(assistant_response, 'content') and isinstance(assistant_response.content, str):
49
+ processed_content = assistant_response.content
50
+ st.session_state.sessionMessages.append(AIMessage(content=processed_content))
51
+ else:
52
+ st.error("Invalid response received from AI.")
53
+ processed_content = "Sorry, I couldn't process your request."
 
 
 
 
 
54
 
55
  return processed_content
56