Create base_agent.py
Browse files- agents/base_agent.py +26 -0
agents/base_agent.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from abc import ABC, abstractmethod
|
| 2 |
+
from typing import Any, Dict
|
| 3 |
+
import ollama
|
| 4 |
+
|
| 5 |
+
class BaseAgent(ABC):
|
| 6 |
+
def __init__(self, model_name: str = "llama3.2:3b"):
|
| 7 |
+
self.model_name = model_name
|
| 8 |
+
|
| 9 |
+
async def get_completion(self, prompt: str) -> str:
|
| 10 |
+
try:
|
| 11 |
+
response = ollama.chat(model=self.model_name, messages=[
|
| 12 |
+
{'role': 'user', 'content': prompt}
|
| 13 |
+
])
|
| 14 |
+
return response['message']['content']
|
| 15 |
+
except Exception as e:
|
| 16 |
+
raise Exception(f"Error getting completion: {str(e)}")
|
| 17 |
+
|
| 18 |
+
class MainAgent(BaseAgent):
|
| 19 |
+
@abstractmethod
|
| 20 |
+
async def process(self, input_data: Any) -> Dict[str, Any]:
|
| 21 |
+
pass
|
| 22 |
+
|
| 23 |
+
class ValidatorAgent(BaseAgent):
|
| 24 |
+
@abstractmethod
|
| 25 |
+
async def validate(self, input_data: Any, output_data: Any) -> Dict[str, bool]:
|
| 26 |
+
pass
|