Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion conversational-agent-app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,17 @@ def get_model_response(trigger_data, current_messages, chat_history):
try:
headers = request.headers
user_token = headers.get('X-Forwarded-Access-Token')
response, query_text = genie_query(user_input, user_token, GENIE_SPACE_ID)

# Get conversation_id from chat history if continuing a conversation
conversation_id = None
if chat_history and len(chat_history) > 0:
conversation_id = chat_history[0].get("conversation_id")

conversation_id, response, query_text = genie_query(user_input, user_token, GENIE_SPACE_ID, conversation_id)

# Store the conversation_id in chat history
if chat_history and len(chat_history) > 0:
chat_history[0]["conversation_id"] = conversation_id

if isinstance(response, str):
# Escape square brackets to prevent markdown auto-linking
Expand Down
18 changes: 12 additions & 6 deletions conversational-agent-app/genie_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def start_conversation(self, question: str) -> Dict[str, Any]:

def send_message(self, conversation_id: str, message: str) -> Dict[str, Any]:
"""Send a follow-up message to an existing conversation"""
response = self.client.genie.send_message(
response = self.client.genie.create_message(
space_id=self.space_id,
conversation_id=conversation_id,
content=message
Expand Down Expand Up @@ -227,16 +227,22 @@ def process_genie_response(client, conversation_id, message_id, complete_message

return "No response available", None

def genie_query(question: str, token: str, space_id: str) -> Union[Tuple[str, Optional[str]], Tuple[pd.DataFrame, str]]:
def genie_query(question: str, token: str, space_id: str, conversation_id: str | None = None) -> Tuple[str | None, Union[str, pd.DataFrame], str | None]:
"""
Main entry point for querying Genie.
Returns: (conversation_id, result, query_text)
"""
try:
# Start a new conversation for each query
conversation_id, result, query_text = start_new_conversation(question, token, space_id)
return result, query_text
if conversation_id:
# Continue existing conversation
result, query_text = continue_conversation(conversation_id, question, token, space_id)
return conversation_id, result, query_text
else:
# Start a new conversation
conversation_id, result, query_text = start_new_conversation(question, token, space_id)
return conversation_id, result, query_text

except Exception as e:
logger.error(f"Error in conversation: {str(e)}. Please try again.")
return f"Sorry, an error occurred: {str(e)}. Please try again.", None
return None, f"Sorry, an error occurred: {str(e)}. Please try again.", None