|
""" |
|
Test script for LLM interface with conversation history. |
|
""" |
|
|
|
from utils import SocialGraphManager |
|
from llm_interface import LLMInterface |
|
|
|
|
|
graph_manager = SocialGraphManager("social_graph.json") |
|
|
|
|
|
person_id = "emma" |
|
person_context = graph_manager.get_person_context(person_id) |
|
|
|
|
|
llm_interface = LLMInterface() |
|
|
|
|
|
original_method = llm_interface.generate_suggestion |
|
|
|
|
|
def mock_generate_suggestion(*args, **kwargs): |
|
"""Mock method to print the prompt instead of sending it to the LLM.""" |
|
|
|
person_context = args[0] |
|
user_input = args[1] if len(args) > 1 else kwargs.get("user_input") |
|
|
|
|
|
|
|
name = person_context.get("name", "") |
|
role = person_context.get("role", "") |
|
topics = person_context.get("topics", []) |
|
context = person_context.get("context", "") |
|
selected_topic = person_context.get("selected_topic", "") |
|
frequency = person_context.get("frequency", "") |
|
mood = person_context.get("mood", 3) |
|
|
|
|
|
mood_descriptions = { |
|
1: "I'm feeling quite down and sad today. My responses might be more subdued.", |
|
2: "I'm feeling a bit low today. I might be less enthusiastic than usual.", |
|
3: "I'm feeling okay today - neither particularly happy nor sad.", |
|
4: "I'm feeling pretty good today. I'm in a positive mood.", |
|
5: "I'm feeling really happy and upbeat today! I'm in a great mood.", |
|
} |
|
mood_description = mood_descriptions.get(mood, mood_descriptions[3]) |
|
|
|
|
|
import datetime |
|
current_datetime = datetime.datetime.now() |
|
current_time = current_datetime.strftime("%I:%M %p") |
|
current_day = current_datetime.strftime("%A") |
|
current_date = current_datetime.strftime("%B %d, %Y") |
|
|
|
|
|
prompt = f"""I am Will, a 38-year-old with MND (Motor Neuron Disease) from Manchester. |
|
I am talking to {name}, who is my {role}. |
|
About {name}: {context} |
|
We typically talk about: {', '.join(topics)} |
|
We communicate {frequency}. |
|
|
|
Current time: {current_time} |
|
Current day: {current_day} |
|
Current date: {current_date} |
|
|
|
My current mood: {mood_description} |
|
""" |
|
|
|
|
|
if role in ["wife", "son", "daughter", "mother", "father"]: |
|
prompt += "I communicate with my family in a warm, loving way, sometimes using inside jokes.\n" |
|
elif role in ["doctor", "therapist", "nurse"]: |
|
prompt += "I communicate with healthcare providers in a direct, informative way.\n" |
|
elif role in ["best mate", "friend"]: |
|
prompt += "I communicate with friends casually, often with humor and sometimes swearing.\n" |
|
elif role in ["work colleague", "boss"]: |
|
prompt += "I communicate with colleagues professionally but still friendly.\n" |
|
|
|
|
|
if selected_topic: |
|
prompt += f"\nWe are currently discussing {selected_topic}.\n" |
|
|
|
|
|
conversation_history = person_context.get("conversation_history", []) |
|
if conversation_history: |
|
|
|
recent_conversations = sorted( |
|
conversation_history, |
|
key=lambda x: x.get("timestamp", ""), |
|
reverse=True |
|
)[:2] |
|
|
|
if recent_conversations: |
|
prompt += "\nOur recent conversations:\n" |
|
|
|
for conversation in recent_conversations: |
|
|
|
timestamp = conversation.get("timestamp", "") |
|
try: |
|
dt = datetime.datetime.fromisoformat(timestamp) |
|
formatted_date = dt.strftime("%B %d at %I:%M %p") |
|
except (ValueError, TypeError): |
|
formatted_date = timestamp |
|
|
|
prompt += f"\nConversation on {formatted_date}:\n" |
|
|
|
|
|
messages = conversation.get("messages", []) |
|
for message in messages: |
|
speaker = message.get("speaker", "Unknown") |
|
text = message.get("text", "") |
|
prompt += f'{speaker}: "{text}"\n' |
|
|
|
|
|
if user_input: |
|
|
|
prompt += f'\n{name} just said to me: "{user_input}"\n' |
|
prompt += f"I want to respond directly to what {name} just said.\n" |
|
else: |
|
|
|
if selected_topic: |
|
|
|
prompt += f"\nI'm about to start a conversation with {name} about {selected_topic}.\n" |
|
prompt += f"I want to initiate a conversation about {selected_topic} in a natural way.\n" |
|
else: |
|
|
|
prompt += f"\nI'm about to start a conversation with {name}.\n" |
|
prompt += "I want to initiate a conversation in a natural way based on our relationship.\n" |
|
|
|
|
|
print("\n=== PROMPT WITH CONVERSATION HISTORY ===") |
|
print(prompt) |
|
print("=======================================\n") |
|
|
|
|
|
return "This is a mock response to test conversation history inclusion in the prompt." |
|
|
|
|
|
llm_interface.generate_suggestion = mock_generate_suggestion |
|
|
|
|
|
user_input = "Do you think you'll be up for dinner with the kids tonight?" |
|
llm_interface.generate_suggestion(person_context, user_input=user_input) |
|
|
|
|
|
llm_interface.generate_suggestion = original_method |
|
|