shukdevdatta123 commited on
Commit
06c35fe
·
verified ·
1 Parent(s): 7e0d2c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -15
app.py CHANGED
@@ -65,6 +65,30 @@ class PersonalAIResearchAssistant:
65
  with open(self.knowledge_base_path, 'w') as f:
66
  json.dump(kb, f, indent=2)
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  def research_digest(self, topic: str,
69
  include_domains: List[str] = None,
70
  exclude_domains: List[str] = None,
@@ -113,10 +137,8 @@ class PersonalAIResearchAssistant:
113
  response = self.client.chat.completions.create(**params)
114
  content = response.choices[0].message.content
115
 
116
- # Extract tool usage information if available
117
- tool_info = None
118
- if hasattr(response.choices[0].message, 'executed_tools'):
119
- tool_info = response.choices[0].message.executed_tools
120
 
121
  # Create digest entry
122
  digest = {
@@ -190,10 +212,8 @@ class PersonalAIResearchAssistant:
190
 
191
  content = response.choices[0].message.content
192
 
193
- # Extract tool usage information if available
194
- tool_info = None
195
- if hasattr(response.choices[0].message, 'executed_tools'):
196
- tool_info = response.choices[0].message.executed_tools
197
 
198
  # Create code analysis entry
199
  analysis = {
@@ -249,10 +269,8 @@ class PersonalAIResearchAssistant:
249
 
250
  content = response.choices[0].message.content
251
 
252
- # Extract tool usage information if available
253
- tool_info = None
254
- if hasattr(response.choices[0].message, 'executed_tools'):
255
- tool_info = response.choices[0].message.executed_tools
256
 
257
  # Create connection entry
258
  connection = {
@@ -491,7 +509,7 @@ def research_topic(topic, include_domains, exclude_domains):
491
 
492
  # Add tool usage info if available
493
  if result.get("tool_usage"):
494
- response += f"\n\n*Tool Usage: {result['tool_usage']}*"
495
 
496
  return response
497
  except Exception as e:
@@ -520,7 +538,7 @@ def analyze_code(code_snippet, language, analysis_type):
520
 
521
  # Add tool usage info if available
522
  if result.get("tool_usage"):
523
- response += f"\n\n*Tool Usage: {result['tool_usage']}*"
524
 
525
  return response
526
  except Exception as e:
@@ -548,7 +566,7 @@ def connect_concepts_handler(concept_a, concept_b):
548
 
549
  # Add tool usage info if available
550
  if result.get("tool_usage"):
551
- response += f"\n\n*Tool Usage: {result['tool_usage']}*"
552
 
553
  return response
554
  except Exception as e:
 
65
  with open(self.knowledge_base_path, 'w') as f:
66
  json.dump(kb, f, indent=2)
67
 
68
+ def _extract_tool_info(self, response) -> Dict:
69
+ """
70
+ Extract tool usage information in a JSON serializable format
71
+ """
72
+ tool_info = None
73
+ if hasattr(response.choices[0].message, 'executed_tools'):
74
+ # Convert ExecutedTool objects to dictionaries
75
+ tools = response.choices[0].message.executed_tools
76
+ if tools:
77
+ tool_info = []
78
+ for tool in tools:
79
+ # Extract only serializable data
80
+ tool_dict = {
81
+ "tool_type": getattr(tool, "type", "unknown"),
82
+ "tool_name": getattr(tool, "name", "unknown"),
83
+ }
84
+ # Add any other relevant attributes in a serializable form
85
+ if hasattr(tool, "input"):
86
+ tool_dict["input"] = str(tool.input)
87
+ if hasattr(tool, "output"):
88
+ tool_dict["output"] = str(tool.output)
89
+ tool_info.append(tool_dict)
90
+ return tool_info
91
+
92
  def research_digest(self, topic: str,
93
  include_domains: List[str] = None,
94
  exclude_domains: List[str] = None,
 
137
  response = self.client.chat.completions.create(**params)
138
  content = response.choices[0].message.content
139
 
140
+ # Extract tool usage information in a serializable format
141
+ tool_info = self._extract_tool_info(response)
 
 
142
 
143
  # Create digest entry
144
  digest = {
 
212
 
213
  content = response.choices[0].message.content
214
 
215
+ # Extract tool usage information in a serializable format
216
+ tool_info = self._extract_tool_info(response)
 
 
217
 
218
  # Create code analysis entry
219
  analysis = {
 
269
 
270
  content = response.choices[0].message.content
271
 
272
+ # Extract tool usage information in a serializable format
273
+ tool_info = self._extract_tool_info(response)
 
 
274
 
275
  # Create connection entry
276
  connection = {
 
509
 
510
  # Add tool usage info if available
511
  if result.get("tool_usage"):
512
+ response += f"\n\n*Tool Usage Information Available*"
513
 
514
  return response
515
  except Exception as e:
 
538
 
539
  # Add tool usage info if available
540
  if result.get("tool_usage"):
541
+ response += f"\n\n*Tool Usage Information Available*"
542
 
543
  return response
544
  except Exception as e:
 
566
 
567
  # Add tool usage info if available
568
  if result.get("tool_usage"):
569
+ response += f"\n\n*Tool Usage Information Available*"
570
 
571
  return response
572
  except Exception as e: