SnehaLeela commited on
Commit
629a280
·
verified ·
1 Parent(s): 63fc079

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -47
app.py CHANGED
@@ -38,38 +38,10 @@ def record_unknown_question(question):
38
  writer.writerow([question])
39
  return {"recorded": "ok"}
40
 
41
- # JSON definitions for tools
42
- record_user_details_json = {
43
- "name": "record_user_details",
44
- "description": "Record user info when they provide email",
45
- "parameters": {
46
- "type": "object",
47
- "properties": {
48
- "email": {"type": "string", "description": "The user's email"},
49
- "name": {"type": "string", "description": "User's name"},
50
- "notes": {"type": "string", "description": "Extra info"}
51
- },
52
- "required": ["email"],
53
- "additionalProperties": False
54
- }
55
- }
56
-
57
- record_unknown_question_json = {
58
- "name": "record_unknown_question",
59
- "description": "Record any unanswered question",
60
- "parameters": {
61
- "type": "object",
62
- "properties": {
63
- "question": {"type": "string", "description": "The question not answered"},
64
- },
65
- "required": ["question"],
66
- "additionalProperties": False
67
- }
68
- }
69
-
70
  tools = [
71
- {"type": "function", "function": record_user_details_json},
72
- {"type": "function", "function": record_unknown_question_json}
73
  ]
74
 
75
  class Me:
@@ -91,12 +63,13 @@ class Me:
91
  # Handle tool calls
92
  def handle_tool_call(self, tool_calls):
93
  results = []
94
- for tool_call in tool_calls:
95
- tool_name = tool_call.function.name
96
- arguments = json.loads(tool_call.function.arguments)
97
- tool = globals().get(tool_name)
98
- result = tool(**arguments) if tool else {}
99
- results.append({"role": "tool", "content": json.dumps(result), "tool_call_id": tool_call.id})
 
100
  return results
101
 
102
  # System prompt for LLM
@@ -116,25 +89,24 @@ class Me:
116
  expertise_text = ", ".join(self.expertise)
117
 
118
  education_text = ""
119
- if hasattr(self, 'education') and self.education:
120
  highest = self.education[0].get("highest_degree", {})
121
  education_text = f"{highest.get('degree','')} in {highest.get('field_of_study','')} from {highest.get('university','')} ({highest.get('start_year','')}–{highest.get('end_year','')})"
122
-
123
- # Optional: prepare friends text for fun
124
  friends_text = ""
125
- if hasattr(self, 'friends') and self.friends:
126
  friends_list = []
127
  for f in self.friends:
128
  friends_list.append(f"{f.get('Name','')} ({f.get('Company','')}): {f.get('Description','')}")
129
  friends_text = "\n".join(friends_list)
130
-
131
  system_prompt = (
132
- f"You are acting as {self.personal_info['name']} (aka {self.personal_info.get('nickname','')}). "
133
- f"Answer questions about {self.personal_info['name']}'s career, background, skills, and experience. "
134
- f"Represent {self.personal_info['name']} faithfully. "
135
  f"If you don't know an answer, use record_unknown_question tool. "
136
  f"If the user engages in discussion, try to steer them towards providing their email using record_user_details tool.\n\n"
137
- f"## Summary:\n{self.personal_info['summary']}\n\n"
138
  f"## Interests:\n{', '.join(self.personal_info.get('personal_interests', []))}\n\n"
139
  f"## Travel History:\n{', '.join(self.personal_info.get('travel_history', []))}\n\n"
140
  f"## Education:\n{education_text}\n\n"
@@ -142,7 +114,7 @@ class Me:
142
  f"## Experience:\n{experience_text}\n\n"
143
  f"## Friends (for fun):\n{friends_text}\n\n"
144
  f"## LinkedIn Profile:\nhttps://www.linkedin.com/in/sneha-leela-0a450349/\n\n"
145
- f"Chat with the user staying in character as {self.personal_info['name']}."
146
  )
147
  return system_prompt
148
 
 
38
  writer.writerow([question])
39
  return {"recorded": "ok"}
40
 
41
+ # Define tools for the LLM
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  tools = [
43
+ {"name": "record_user_details", "description": "Record user info when they provide email", "func": record_user_details},
44
+ {"name": "record_unknown_question", "description": "Record any unanswered question", "func": record_unknown_question},
45
  ]
46
 
47
  class Me:
 
63
  # Handle tool calls
64
  def handle_tool_call(self, tool_calls):
65
  results = []
66
+ for call in tool_calls:
67
+ # Find the corresponding Python function
68
+ func = next((t["func"] for t in tools if t["name"] == call.function.name), None)
69
+ if func:
70
+ args = json.loads(call.function.arguments)
71
+ result = func(**args)
72
+ results.append({"role": "tool", "content": json.dumps(result), "tool_call_id": call.id})
73
  return results
74
 
75
  # System prompt for LLM
 
89
  expertise_text = ", ".join(self.expertise)
90
 
91
  education_text = ""
92
+ if self.education:
93
  highest = self.education[0].get("highest_degree", {})
94
  education_text = f"{highest.get('degree','')} in {highest.get('field_of_study','')} from {highest.get('university','')} ({highest.get('start_year','')}–{highest.get('end_year','')})"
95
+
 
96
  friends_text = ""
97
+ if self.friends:
98
  friends_list = []
99
  for f in self.friends:
100
  friends_list.append(f"{f.get('Name','')} ({f.get('Company','')}): {f.get('Description','')}")
101
  friends_text = "\n".join(friends_list)
102
+
103
  system_prompt = (
104
+ f"You are acting as {self.personal_info.get('name','')} (aka {self.personal_info.get('nickname','')}). "
105
+ f"Answer questions about {self.personal_info.get('name','')}'s career, background, skills, and experience. "
106
+ f"Represent {self.personal_info.get('name','')} faithfully. "
107
  f"If you don't know an answer, use record_unknown_question tool. "
108
  f"If the user engages in discussion, try to steer them towards providing their email using record_user_details tool.\n\n"
109
+ f"## Summary:\n{self.personal_info.get('summary','')}\n\n"
110
  f"## Interests:\n{', '.join(self.personal_info.get('personal_interests', []))}\n\n"
111
  f"## Travel History:\n{', '.join(self.personal_info.get('travel_history', []))}\n\n"
112
  f"## Education:\n{education_text}\n\n"
 
114
  f"## Experience:\n{experience_text}\n\n"
115
  f"## Friends (for fun):\n{friends_text}\n\n"
116
  f"## LinkedIn Profile:\nhttps://www.linkedin.com/in/sneha-leela-0a450349/\n\n"
117
+ f"Chat with the user staying in character as {self.personal_info.get('name','')}."
118
  )
119
  return system_prompt
120