Ankit93 commited on
Commit
ec40a8b
·
verified ·
1 Parent(s): de0fbc2

Update src/agent/agenttools.py

Browse files
Files changed (1) hide show
  1. src/agent/agenttools.py +2 -144
src/agent/agenttools.py CHANGED
@@ -56,8 +56,8 @@ class ChatBotFunctionTools:
56
  "You are a Python Expert.\n"
57
  "Give the python source code as asked like copilot or help to debug a particular code block:\n"
58
  f"{query}\n"
59
- "Keep it compact and dont give much theory. Explain code blocks only."
60
- )
61
  return self.generator.complete(prompt)
62
 
63
  @retry(max_retries=5, delay=1)
@@ -79,145 +79,3 @@ class ChatBotFunctionTools:
79
  }
80
 
81
 
82
-
83
- # class LearningAgent:
84
- # """Core agent that orchestrates tool usage for learning system"""
85
- #
86
- # def __init__(self, llm_value):
87
- # self.llm = LLMCall(llm_type=llm_value).get_llm()
88
- # self.tools = self._setup_tools()
89
- # self.chat_history: List[Dict[str, str]] = [] # Stores properly formatted messages
90
- # self.max_history = 20
91
- #
92
- # def _setup_tools(self) -> Dict[str, FunctionTool]:
93
- # """Initialize all learning tools"""
94
- # return {
95
- # **self._setup_ml_tools(),
96
- # **self._setup_dl_tools(),
97
- # **self._setup_graph_tools(),
98
- # **self._setup_utility_tools()
99
- # }
100
- #
101
- # def _setup_ml_tools(self) -> Dict[str, FunctionTool]:
102
- # """Machine Learning tools"""
103
- #
104
- # def ml_concept_explainer(query: str) -> str:
105
- # prompt = f"Explain this ML concept in simple terms with examples: {query}"
106
- # return self.llm.complete(prompt).text
107
- #
108
- # return {
109
- # "ml_concept": FunctionTool.from_defaults(fn=ml_concept_explainer)
110
- # }
111
- #
112
- # def _setup_dl_tools(self) -> Dict[str, FunctionTool]:
113
- # """Deep Learning tools"""
114
- #
115
- # def dl_architecture(arch: str) -> str:
116
- # prompt = f"Explain the {arch} neural network architecture with diagram description"
117
- # return self.llm.complete(prompt).text
118
- #
119
- # return {
120
- # "dl_architecture": FunctionTool.from_defaults(fn=dl_architecture)
121
- # }
122
- #
123
- # def _setup_graph_tools(self) -> Dict[str, FunctionTool]:
124
- # """Graph/Visualization tools"""
125
- #
126
- # def visualize_algorithm(algo: str) -> str:
127
- # prompt = f"Create visualization code that demonstrates how {algo} works"
128
- # return self.llm.complete(prompt).text
129
- #
130
- # return {
131
- # "algo_visualizer": FunctionTool.from_defaults(fn=visualize_algorithm)
132
- # }
133
- #
134
- # def _setup_utility_tools(self) -> Dict[str, FunctionTool]:
135
- # """Utility tools"""
136
- #
137
- # def concept_combiner(concepts: List[str]) -> str:
138
- # prompt = f"Explain the relationship between these concepts: {', '.join(concepts)}"
139
- # return self.llm.complete(prompt).text
140
- #
141
- # return {
142
- # "concept_combiner": FunctionTool.from_defaults(fn=concept_combiner)
143
- # }
144
- #
145
- # def extract_json_from_markdown(self, markdown_text):
146
- # """
147
- # Extract and parse JSON content from a markdown-style code block.
148
- # Handles formats like ```json ... ```
149
- # """
150
- # try:
151
- # # Extract JSON block using regex
152
- # match = re.search(r"```json\s*(\{.*?\})\s*```", markdown_text, re.DOTALL)
153
- # if not match:
154
- # raise ValueError("No JSON block found in markdown")
155
- #
156
- # json_str = match.group(1)
157
- # return json.loads(json_str)
158
- # except Exception as e:
159
- # print(f"[ERROR] Could not parse JSON: {e}")
160
- # return None
161
- #
162
- # def determine_tools(self, query: str):
163
- # """Decide which tools to use based on query"""
164
- # previous_questions = ""
165
- # if self.chat_history:
166
- # previous_questions = "\n".join([msg["content"] for msg in self.chat_history if msg["role"] == "user"][:-1]) \
167
- # if self.chat_history else "No previous questions"
168
- # prompt = f"""Analyze this learning query and select appropriate tools also form the condensed query based on
169
- # previous_questions and Query:
170
- # Query: {query}
171
- # Previous Query: {previous_questions}
172
- # Available Tools: {list(self.tools.keys())}
173
- # Return dictionary of tool names and condensed query as dictionary in the below format:
174
- # ```json
175
- # {{
176
- # "condensed_query": condensed query considering chat history and user query as string,
177
- # "tool_names": tool names as comma-separated list
178
- # }}
179
- # ```
180
- # Do Not add additional text"""
181
- #
182
- # response = self.llm.complete(prompt).text
183
- # response = self.extract_json_from_markdown(response)
184
- # return [t.strip() for t in response['tool_names'].split(",") if t.strip() in self.tools], response["condensed_query"]
185
- #
186
- # def execute_tools(self, tools: List[str], query: str) -> tuple[str, str]:
187
- # """Execute multiple tools and combine results"""
188
- # tool_results = []
189
- # content_results = []
190
- #
191
- # for tool in tools:
192
- # try:
193
- # tool_output = self.tools[tool](query)
194
- # content = tool_output.content if isinstance(tool_output, ToolOutput) else str(tool_output)
195
- # tool_results.append(tool)
196
- # content_results.append(content)
197
- # except Exception as e:
198
- # logging.error(f"Tool {tool} failed: {str(e)}")
199
- # tool_results.append(tool)
200
- # content_results.append(f"Error: {str(e)}")
201
- #
202
- # if len(tool_results) > 1:
203
- # combined = "\n\n".join(f"**{t}**:\n{c}" for t, c in zip(tool_results, content_results))
204
- # explanation = self.tools["concept_combiner"](content_results)
205
- # return "multiple", f"{combined}\n\n**Combined Analysis**:\n{explanation}"
206
- # return tool_results[0], content_results[0]
207
- #
208
- # def process_query(self, query: str) -> tuple[List[Dict[str, str]], str, str]:
209
- # """Process query and return properly formatted messages"""
210
- # tools, condensed_query = self.determine_tools(query)
211
- # logging.info(f"Selected tools: {tools}")
212
- #
213
- # tool_used, response = self.execute_tools(tools, condensed_query)
214
- #
215
- # # Format messages for Gradio Chatbot
216
- # user_msg = {"role": "user", "content": query.title()}
217
- # assistant_msg = {"role": "assistant", "content": response}
218
- #
219
- # self.chat_history.extend([user_msg, assistant_msg])
220
- # if len(self.chat_history) > self.max_history * 2: # *2 for user+assistant pairs
221
- # self.chat_history = self.chat_history[-(self.max_history * 2):]
222
- #
223
- # return self.chat_history, tool_used, response
 
56
  "You are a Python Expert.\n"
57
  "Give the python source code as asked like copilot or help to debug a particular code block:\n"
58
  f"{query}\n"
59
+ "Keep it compact and dont give theory until you are asked. Explain code blocks only."
60
+ "Strictly folllow the instructions")
61
  return self.generator.complete(prompt)
62
 
63
  @retry(max_retries=5, delay=1)
 
79
  }
80
 
81