Jayashree Sridhar
commited on
Commit
·
4b2ca0c
1
Parent(s):
f130374
modified llm & knowledge tools
Browse files
agents/tools/knowledge_tools.py
CHANGED
|
@@ -1,12 +1,14 @@
|
|
| 1 |
from .base_tool import BaseTool
|
| 2 |
from utils.knowledge_base import KnowledgeBase
|
|
|
|
| 3 |
|
| 4 |
class SearchKnowledgeTool(BaseTool):
|
| 5 |
name: str = "search_knowledge"
|
| 6 |
description: str = "Search self-help or spiritual wisdom."
|
|
|
|
| 7 |
def __init__(self, config=None):
|
| 8 |
super().__init__()
|
| 9 |
-
self.
|
| 10 |
def __call__(self, query: str, k: int = 5):
|
| 11 |
return self.kb.search(query, k=k) if self.kb.is_initialized() else \
|
| 12 |
[{"text": "General wisdom", "score": 1.0}]
|
|
|
|
| 1 |
from .base_tool import BaseTool
|
| 2 |
from utils.knowledge_base import KnowledgeBase
|
| 3 |
+
from pydantic import BaseModel, PrivateAttr
|
| 4 |
|
| 5 |
class SearchKnowledgeTool(BaseTool):
|
| 6 |
name: str = "search_knowledge"
|
| 7 |
description: str = "Search self-help or spiritual wisdom."
|
| 8 |
+
_kp: KnowledgeBase = PrivateAttr()
|
| 9 |
def __init__(self, config=None):
|
| 10 |
super().__init__()
|
| 11 |
+
self._kb = KnowledgeBase(config)
|
| 12 |
def __call__(self, query: str, k: int = 5):
|
| 13 |
return self.kb.search(query, k=k) if self.kb.is_initialized() else \
|
| 14 |
[{"text": "General wisdom", "score": 1.0}]
|
agents/tools/llm_tools.py
CHANGED
|
@@ -1,12 +1,14 @@
|
|
| 1 |
from .base_tool import BaseTool
|
| 2 |
from models.tinygpt2_model import TinyGPT2Model
|
|
|
|
| 3 |
|
| 4 |
class MistralChatTool(BaseTool):
|
| 5 |
name: str = "mistral_chat"
|
| 6 |
description: str = "Generate an empathetic AI chat response."
|
|
|
|
| 7 |
def __init__(self, config=None):
|
| 8 |
super().__init__()
|
| 9 |
-
self.
|
| 10 |
def __call__(self, prompt: str, context: dict = None):
|
| 11 |
msg = f"Context: {context}\nUser: {prompt}" if context else prompt
|
| 12 |
return self.model.generate(msg)
|
|
@@ -14,9 +16,10 @@ class MistralChatTool(BaseTool):
|
|
| 14 |
class GenerateAdviceTool(BaseTool):
|
| 15 |
name: str = "generate_advice"
|
| 16 |
description: str = "Generate personalized advice."
|
|
|
|
| 17 |
def __init__(self, config=None):
|
| 18 |
super().__init__()
|
| 19 |
-
self.
|
| 20 |
def __call__(self, user_analysis: dict, wisdom_quotes: list):
|
| 21 |
prompt = f"Advice for: {user_analysis}, with wisdom: {wisdom_quotes}"
|
| 22 |
return self.model.generate(prompt, max_length=300)
|
|
@@ -24,9 +27,10 @@ class GenerateAdviceTool(BaseTool):
|
|
| 24 |
class SummarizeConversationTool(BaseTool):
|
| 25 |
name: str = "summarize_conversation"
|
| 26 |
description: str = "Summarize chat with insights and next steps."
|
|
|
|
| 27 |
def __init__(self, config=None):
|
| 28 |
super().__init__()
|
| 29 |
-
self.
|
| 30 |
def __call__(self, conversation: list):
|
| 31 |
prompt = f"Summarize: {conversation}"
|
| 32 |
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 BaseModel, PrivateAttr
|
| 4 |
|
| 5 |
class MistralChatTool(BaseTool):
|
| 6 |
name: str = "mistral_chat"
|
| 7 |
description: str = "Generate an empathetic AI chat response."
|
| 8 |
+
_model: TinyGPT2Model = PrivateAttr()
|
| 9 |
def __init__(self, config=None):
|
| 10 |
super().__init__()
|
| 11 |
+
self._model = TinyGPT2Model()
|
| 12 |
def __call__(self, prompt: str, context: dict = None):
|
| 13 |
msg = f"Context: {context}\nUser: {prompt}" if context else prompt
|
| 14 |
return self.model.generate(msg)
|
|
|
|
| 16 |
class GenerateAdviceTool(BaseTool):
|
| 17 |
name: str = "generate_advice"
|
| 18 |
description: str = "Generate personalized advice."
|
| 19 |
+
_model: TinyGPT2Model = PrivateAttr()
|
| 20 |
def __init__(self, config=None):
|
| 21 |
super().__init__()
|
| 22 |
+
self._model = TinyGPT2Model()
|
| 23 |
def __call__(self, user_analysis: dict, wisdom_quotes: list):
|
| 24 |
prompt = f"Advice for: {user_analysis}, with wisdom: {wisdom_quotes}"
|
| 25 |
return self.model.generate(prompt, max_length=300)
|
|
|
|
| 27 |
class SummarizeConversationTool(BaseTool):
|
| 28 |
name: str = "summarize_conversation"
|
| 29 |
description: str = "Summarize chat with insights and next steps."
|
| 30 |
+
_model: TinyGPT2Model = PrivateAttr()
|
| 31 |
def __init__(self, config=None):
|
| 32 |
super().__init__()
|
| 33 |
+
self._model = TinyGPT2Model()
|
| 34 |
def __call__(self, conversation: list):
|
| 35 |
prompt = f"Summarize: {conversation}"
|
| 36 |
return self.model.generate(prompt, max_length=200)
|