Jayashree Sridhar
commited on
Commit
·
c5514db
1
Parent(s):
3019028
included privateaatr in all tools
Browse files
agents/tools/knowledge_tools.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
#from .base_tool import BaseTool
|
| 2 |
from utils.knowledge_base import KnowledgeBase
|
| 3 |
-
|
| 4 |
from crewai.tools import BaseTool
|
| 5 |
|
| 6 |
|
|
@@ -9,10 +9,10 @@ class SearchKnowledgeTool(BaseTool):
|
|
| 9 |
name: str = "search_knowledge"
|
| 10 |
description: str = "Search self-help or spiritual wisdom."
|
| 11 |
model_config = {"arbitrary_types_allowed": True}
|
| 12 |
-
|
| 13 |
def __init__(self, config=None):
|
| 14 |
super().__init__()
|
| 15 |
-
self.
|
| 16 |
def _run(self, query: str, k: int = 5):
|
| 17 |
return self.kb.search(query, k=k) if self.kb.is_initialized() else \
|
| 18 |
[{"text": "General wisdom", "score": 1.0}]
|
|
|
|
| 1 |
#from .base_tool import BaseTool
|
| 2 |
from utils.knowledge_base import KnowledgeBase
|
| 3 |
+
from pydantic import PrivateAttr
|
| 4 |
from crewai.tools import BaseTool
|
| 5 |
|
| 6 |
|
|
|
|
| 9 |
name: str = "search_knowledge"
|
| 10 |
description: str = "Search self-help or spiritual wisdom."
|
| 11 |
model_config = {"arbitrary_types_allowed": True}
|
| 12 |
+
_kp: KnowledgeBase = PrivateAttr()
|
| 13 |
def __init__(self, config=None):
|
| 14 |
super().__init__()
|
| 15 |
+
self._kb = KnowledgeBase(config)
|
| 16 |
def _run(self, query: str, k: int = 5):
|
| 17 |
return self.kb.search(query, k=k) if self.kb.is_initialized() else \
|
| 18 |
[{"text": "General wisdom", "score": 1.0}]
|
agents/tools/llm_tools.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
#from .base_tool import BaseTool
|
| 2 |
from models.tinygpt2_model import TinyGPT2Model
|
| 3 |
-
|
| 4 |
from crewai.tools import BaseTool
|
| 5 |
|
| 6 |
|
|
@@ -9,10 +9,10 @@ class MistralChatTool(BaseTool):
|
|
| 9 |
name: str = "mistral_chat"
|
| 10 |
description: str = "Generate an empathetic AI chat response."
|
| 11 |
model_config = {"arbitrary_types_allowed": True}
|
| 12 |
-
|
| 13 |
def __init__(self, config=None):
|
| 14 |
super().__init__()
|
| 15 |
-
self.
|
| 16 |
def _run(self, prompt: str, context: dict = None):
|
| 17 |
msg = f"Context: {context}\nUser: {prompt}" if context else prompt
|
| 18 |
return self.model.generate(msg)
|
|
@@ -21,10 +21,10 @@ class GenerateAdviceTool(BaseTool):
|
|
| 21 |
name: str = "generate_advice"
|
| 22 |
description: str = "Generate personalized advice."
|
| 23 |
model_config = {"arbitrary_types_allowed": True}
|
| 24 |
-
|
| 25 |
def __init__(self, config=None):
|
| 26 |
super().__init__()
|
| 27 |
-
self.
|
| 28 |
def _run(self, user_analysis: dict, wisdom_quotes: list):
|
| 29 |
prompt = f"Advice for: {user_analysis}, with wisdom: {wisdom_quotes}"
|
| 30 |
return self.model.generate(prompt, max_length=300)
|
|
@@ -33,10 +33,10 @@ class SummarizeConversationTool(BaseTool):
|
|
| 33 |
name: str = "summarize_conversation"
|
| 34 |
description: str = "Summarize chat with insights and next steps."
|
| 35 |
model_config = {"arbitrary_types_allowed": True}
|
| 36 |
-
|
| 37 |
def __init__(self, config=None):
|
| 38 |
super().__init__()
|
| 39 |
-
self.
|
| 40 |
def _run(self, conversation: list):
|
| 41 |
prompt = f"Summarize: {conversation}"
|
| 42 |
return self.model.generate(prompt, max_length=200)
|
|
|
|
| 1 |
#from .base_tool import BaseTool
|
| 2 |
from models.tinygpt2_model import TinyGPT2Model
|
| 3 |
+
from pydantic import PrivateAttr
|
| 4 |
from crewai.tools import BaseTool
|
| 5 |
|
| 6 |
|
|
|
|
| 9 |
name: str = "mistral_chat"
|
| 10 |
description: str = "Generate an empathetic AI chat response."
|
| 11 |
model_config = {"arbitrary_types_allowed": True}
|
| 12 |
+
_model: TinyGPT2Model = PrivateAttr()
|
| 13 |
def __init__(self, config=None):
|
| 14 |
super().__init__()
|
| 15 |
+
self._model = TinyGPT2Model()
|
| 16 |
def _run(self, prompt: str, context: dict = None):
|
| 17 |
msg = f"Context: {context}\nUser: {prompt}" if context else prompt
|
| 18 |
return self.model.generate(msg)
|
|
|
|
| 21 |
name: str = "generate_advice"
|
| 22 |
description: str = "Generate personalized advice."
|
| 23 |
model_config = {"arbitrary_types_allowed": True}
|
| 24 |
+
_model: TinyGPT2Model = PrivateAttr()
|
| 25 |
def __init__(self, config=None):
|
| 26 |
super().__init__()
|
| 27 |
+
self._model = TinyGPT2Model()
|
| 28 |
def _run(self, user_analysis: dict, wisdom_quotes: list):
|
| 29 |
prompt = f"Advice for: {user_analysis}, with wisdom: {wisdom_quotes}"
|
| 30 |
return self.model.generate(prompt, max_length=300)
|
|
|
|
| 33 |
name: str = "summarize_conversation"
|
| 34 |
description: str = "Summarize chat with insights and next steps."
|
| 35 |
model_config = {"arbitrary_types_allowed": True}
|
| 36 |
+
_model: TinyGPT2Model = PrivateAttr()
|
| 37 |
def __init__(self, config=None):
|
| 38 |
super().__init__()
|
| 39 |
+
self._model = TinyGPT2Model()
|
| 40 |
def _run(self, conversation: list):
|
| 41 |
prompt = f"Summarize: {conversation}"
|
| 42 |
return self.model.generate(prompt, max_length=200)
|
agents/tools/validation_tools.py
CHANGED
|
@@ -8,7 +8,7 @@ from dataclasses import dataclass
|
|
| 8 |
import json
|
| 9 |
from transformers import pipeline
|
| 10 |
import torch
|
| 11 |
-
|
| 12 |
from crewai.tools import BaseTool
|
| 13 |
#from .base_tool import BaseTool
|
| 14 |
|
|
@@ -408,10 +408,10 @@ class ValidateResponseTool(BaseTool):
|
|
| 408 |
name: str = "validate_response"
|
| 409 |
description: str = "Validates safety and helpfulness."
|
| 410 |
model_config = {"arbitrary_types_allowed": True}
|
| 411 |
-
|
| 412 |
def __init__(self, config=None, **data):
|
| 413 |
super().__init__(**data)
|
| 414 |
-
self.
|
| 415 |
# ... any required initialization ...
|
| 416 |
def _run(self, response: str, context: dict = None):
|
| 417 |
# Place your actual validation logic here, include dummy for illustration
|
|
|
|
| 8 |
import json
|
| 9 |
from transformers import pipeline
|
| 10 |
import torch
|
| 11 |
+
from pydantic import PrivateAttr
|
| 12 |
from crewai.tools import BaseTool
|
| 13 |
#from .base_tool import BaseTool
|
| 14 |
|
|
|
|
| 408 |
name: str = "validate_response"
|
| 409 |
description: str = "Validates safety and helpfulness."
|
| 410 |
model_config = {"arbitrary_types_allowed": True}
|
| 411 |
+
_config: object = PrivateAttr()
|
| 412 |
def __init__(self, config=None, **data):
|
| 413 |
super().__init__(**data)
|
| 414 |
+
self._config = config
|
| 415 |
# ... any required initialization ...
|
| 416 |
def _run(self, response: str, context: dict = None):
|
| 417 |
# Place your actual validation logic here, include dummy for illustration
|