acecalisto3 commited on
Commit
9e6c847
·
verified ·
1 Parent(s): befa211

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -2
app.py CHANGED
@@ -6,9 +6,68 @@ from langchain.tools import Tool
6
  from langchain.chains import LLMChain
7
  from typing import List, Dict, Any, Optional
8
 
9
- # Base Tool and specific tools (CodeGenerationTool, DataRetrievalTool, TextGenerationTool) remain the same as in the previous version
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- # --- Specialized Agent Definitions ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  class SpecializedAgent(Agent):
13
  def __init__(self, name, role, tools, knowledge_base=None):
14
  super().__init__(name, role, tools, knowledge_base)
@@ -27,6 +86,9 @@ class SpecializedAgent(Agent):
27
  max_iterations=5
28
  )
29
 
 
 
 
30
  class RequirementsAgent(SpecializedAgent):
31
  def __init__(self):
32
  super().__init__("RequirementsAnalyst", "Analyzing and refining project requirements", [TextGenerationTool()])
 
6
  from langchain.chains import LLMChain
7
  from typing import List, Dict, Any, Optional
8
 
9
+ # Base Agent class
10
+ class Agent:
11
+ def __init__(self, name, role, tools, knowledge_base=None):
12
+ self.name = name
13
+ self.role = role
14
+ self.tools = tools
15
+ self.knowledge_base = knowledge_base
16
+ self.llm = HuggingFaceHub(repo_id="google/flan-t5-xl", model_kwargs={"temperature": 0.5})
17
+
18
+ def act(self, task, context):
19
+ # This method should be implemented in subclasses
20
+ raise NotImplementedError
21
+
22
+ # Base Tool class
23
+ class BaseTool(Tool):
24
+ def __init__(self, name, description):
25
+ super().__init__(name=name, description=description, func=self.run)
26
+ self.llm = HuggingFaceHub(repo_id="google/flan-t5-xl", model_kwargs={"temperature": 0.5})
27
+
28
+ def run(self, arguments: str) -> str:
29
+ raise NotImplementedError
30
+
31
+ # Specific tool implementations
32
+ class CodeGenerationTool(BaseTool):
33
+ def __init__(self):
34
+ super().__init__("Code Generation", "Generates code snippets in various languages.")
35
+ self.prompt_template = PromptTemplate(
36
+ input_variables=["language", "task"],
37
+ template="Generate {language} code for: {task}"
38
+ )
39
+ self.chain = LLMChain(llm=self.llm, prompt=self.prompt_template)
40
+
41
+ def run(self, arguments: str) -> str:
42
+ language, task = arguments.split(", ", 1)
43
+ return self.chain.run(language=language, task=task)
44
+
45
+ class DataRetrievalTool(BaseTool):
46
+ def __init__(self):
47
+ super().__init__("Data Retrieval", "Accesses data from APIs, databases, or files.")
48
+ self.prompt_template = PromptTemplate(
49
+ input_variables=["source", "query"],
50
+ template="Retrieve data from {source} based on: {query}"
51
+ )
52
+ self.chain = LLMChain(llm=self.llm, prompt=self.prompt_template)
53
 
54
+ def run(self, arguments: str) -> str:
55
+ source, query = arguments.split(", ", 1)
56
+ return self.chain.run(source=source, query=query)
57
+
58
+ class TextGenerationTool(BaseTool):
59
+ def __init__(self):
60
+ super().__init__("Text Generation", "Generates human-like text based on a given prompt.")
61
+ self.prompt_template = PromptTemplate(
62
+ input_variables=["prompt"],
63
+ template="Generate text based on: {prompt}"
64
+ )
65
+ self.chain = LLMChain(llm=self.llm, prompt=self.prompt_template)
66
+
67
+ def run(self, arguments: str) -> str:
68
+ return self.chain.run(prompt=arguments)
69
+
70
+ # Specialized Agent Definitions
71
  class SpecializedAgent(Agent):
72
  def __init__(self, name, role, tools, knowledge_base=None):
73
  super().__init__(name, role, tools, knowledge_base)
 
86
  max_iterations=5
87
  )
88
 
89
+ def act(self, task, context):
90
+ return self.agent_executor.run(input=task)
91
+
92
  class RequirementsAgent(SpecializedAgent):
93
  def __init__(self):
94
  super().__init__("RequirementsAnalyst", "Analyzing and refining project requirements", [TextGenerationTool()])