Update decision_maker.py
Browse files- decision_maker.py +21 -10
decision_maker.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from typing import Dict, List, Any, Optional
|
2 |
-
from dataclasses import dataclass
|
3 |
from enum import Enum
|
4 |
import json
|
5 |
import time
|
@@ -19,6 +19,17 @@ class Tool:
|
|
19 |
optional_params: List[str]
|
20 |
confidence_threshold: float = 0.7
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
class DecisionMaker:
|
23 |
def __init__(self):
|
24 |
self.tools = self._initialize_tools()
|
@@ -66,15 +77,15 @@ class DecisionMaker:
|
|
66 |
|
67 |
# Determine required tools based on intent
|
68 |
if "search" in analysis["intent"]:
|
69 |
-
analysis["required_tools"].append(self.tools["simple_search"])
|
70 |
if "code" in analysis["intent"]:
|
71 |
-
analysis["required_tools"].append(self.tools["code_analysis"])
|
72 |
if "file" in analysis["intent"]:
|
73 |
-
analysis["required_tools"].append(self.tools["file_operation"])
|
74 |
|
75 |
# Calculate confidence based on tool requirements
|
76 |
if analysis["required_tools"]:
|
77 |
-
analysis["confidence"] = min(tool
|
78 |
|
79 |
# Generate suggested actions
|
80 |
analysis["suggested_actions"] = self._generate_actions(analysis)
|
@@ -105,11 +116,11 @@ class DecisionMaker:
|
|
105 |
|
106 |
for tool in analysis["required_tools"]:
|
107 |
action = {
|
108 |
-
"tool": tool
|
109 |
-
"type": tool
|
110 |
-
"confidence": tool
|
111 |
-
"required_params": tool
|
112 |
-
"optional_params": tool
|
113 |
}
|
114 |
actions.append(action)
|
115 |
|
|
|
1 |
from typing import Dict, List, Any, Optional
|
2 |
+
from dataclasses import dataclass, asdict
|
3 |
from enum import Enum
|
4 |
import json
|
5 |
import time
|
|
|
19 |
optional_params: List[str]
|
20 |
confidence_threshold: float = 0.7
|
21 |
|
22 |
+
def to_dict(self) -> Dict[str, Any]:
|
23 |
+
"""Convert Tool object to a dictionary for JSON serialization."""
|
24 |
+
return {
|
25 |
+
"name": self.name,
|
26 |
+
"type": self.type.value,
|
27 |
+
"description": self.description,
|
28 |
+
"required_params": self.required_params,
|
29 |
+
"optional_params": self.optional_params,
|
30 |
+
"confidence_threshold": self.confidence_threshold
|
31 |
+
}
|
32 |
+
|
33 |
class DecisionMaker:
|
34 |
def __init__(self):
|
35 |
self.tools = self._initialize_tools()
|
|
|
77 |
|
78 |
# Determine required tools based on intent
|
79 |
if "search" in analysis["intent"]:
|
80 |
+
analysis["required_tools"].append(self.tools["simple_search"].to_dict())
|
81 |
if "code" in analysis["intent"]:
|
82 |
+
analysis["required_tools"].append(self.tools["code_analysis"].to_dict())
|
83 |
if "file" in analysis["intent"]:
|
84 |
+
analysis["required_tools"].append(self.tools["file_operation"].to_dict())
|
85 |
|
86 |
# Calculate confidence based on tool requirements
|
87 |
if analysis["required_tools"]:
|
88 |
+
analysis["confidence"] = min(tool["confidence_threshold"] for tool in analysis["required_tools"])
|
89 |
|
90 |
# Generate suggested actions
|
91 |
analysis["suggested_actions"] = self._generate_actions(analysis)
|
|
|
116 |
|
117 |
for tool in analysis["required_tools"]:
|
118 |
action = {
|
119 |
+
"tool": tool["name"],
|
120 |
+
"type": tool["type"],
|
121 |
+
"confidence": tool["confidence_threshold"],
|
122 |
+
"required_params": tool["required_params"],
|
123 |
+
"optional_params": tool["optional_params"]
|
124 |
}
|
125 |
actions.append(action)
|
126 |
|