DrishtiSharma's picture
Update agents/base_agent.py
5293772 verified
raw
history blame
905 Bytes
import os
from abc import ABC, abstractmethod
from typing import Any, Dict
from groq import Groq
client = Groq()
class BaseAgent(ABC):
def __init__(self, model_name: str = "llama3.2:3b"):
self.model_name = model_name
async def get_completion(self, prompt: str) -> str:
try:
response = client.chat.completions.create(groq_api_key=os.getenv("GROQ_API_KEY"), messages=[{'role': 'user', 'content': prompt}], model=self.model_name)
return response.choices[0].message.content
except Exception as e:
raise Exception(f"Error getting completion: {str(e)}")
class MainAgent(BaseAgent):
@abstractmethod
async def process(self, input_data: Any) -> Dict[str, Any]:
pass
class ValidatorAgent(BaseAgent):
@abstractmethod
async def validate(self, input_data: Any, output_data: Any) -> Dict[str, bool]:
pass