Skip to content

Commit

Permalink
Removed supervisor crew, added simple LLM supervisor
Browse files Browse the repository at this point in the history
  • Loading branch information
Luisotee committed Nov 19, 2024
1 parent 9f7ff4a commit be16eb7
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 4,413 deletions.
44 changes: 31 additions & 13 deletions apps/ai_api/eda_ai_api/api/routes/supervisor.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
import os
from fastapi import APIRouter
from langchain.prompts import PromptTemplate
from langchain_groq import ChatGroq
from langchain.chains import LLMChain
from eda_ai_api.models.supervisor import SupervisorRequest, SupervisorResponse
from supervisor.crew import SupervisorCrew
from opportunity_finder.crew import OpportunityFinderCrew
from proposal_writer.crew import ProposalWriterCrew

router = APIRouter()

print("API KEY:", os.environ.get("GROQ_API_KEY"))
# Setup LLM and prompt
llm = ChatGroq(
model_name="llama3-groq-70b-8192-tool-use-preview",
api_key=os.environ.get("GROQ_API_KEY"),
temperature=0.5,
)


ROUTER_TEMPLATE = """Given a user message, determine the appropriate service to handle the request.
Choose between:
- discovery: For finding grant opportunities
- proposal: For writing grant proposals
- heartbeat: For checking system health
User message: {message}
Return only one word (discovery/proposal/heartbeat):"""

router_prompt = PromptTemplate(input_variables=["message"], template=ROUTER_TEMPLATE)

router_chain = LLMChain(llm=llm, prompt=router_prompt)


@router.post("/supervisor", response_model=SupervisorResponse)
async def supervisor_route(request: SupervisorRequest) -> SupervisorResponse:
# Get crew decision
crew_response = (
SupervisorCrew().create_crew().kickoff(inputs={"message": request.message})
)

# Extract decision from crew response
decision = str(crew_response).lower()
# Get routing decision from LLM
decision = router_chain.run(message=request.message).strip().lower()

# Print input message and decision for debugging
print("\n==================================================")
Expand All @@ -26,16 +47,13 @@ async def supervisor_route(request: SupervisorRequest) -> SupervisorResponse:

# Handle different decision paths
if decision == "discovery":
# TODO: Extract topics from the actual message
topics = ["AI", "Technology"]
result = (
OpportunityFinderCrew().crew().kickoff(inputs={"topics": ", ".join(topics)})
)
elif decision == "proposal":
# Initialize ProposalWriterCrew with context from the message
# TODO: Extract project and grant details from message
community_project = "sample_project" # This should come from message parsing
grant_call = "sample_grant" # This should come from message parsing
community_project = "sample_project"
grant_call = "sample_grant"
result = (
ProposalWriterCrew(
community_project=community_project, grant_call=grant_call
Expand Down
2 changes: 0 additions & 2 deletions plugins/supervisor/.gitignore

This file was deleted.

54 changes: 0 additions & 54 deletions plugins/supervisor/README.md

This file was deleted.

20 changes: 0 additions & 20 deletions plugins/supervisor/pyproject.toml

This file was deleted.

Empty file.
4 changes: 0 additions & 4 deletions plugins/supervisor/src/supervisor/config/agents.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions plugins/supervisor/src/supervisor/config/tasks.yaml

This file was deleted.

45 changes: 0 additions & 45 deletions plugins/supervisor/src/supervisor/crew.py

This file was deleted.

29 changes: 0 additions & 29 deletions plugins/supervisor/src/supervisor/main.py

This file was deleted.

Empty file.
19 changes: 0 additions & 19 deletions plugins/supervisor/src/supervisor/tools/custom_tool.py

This file was deleted.

Loading

0 comments on commit be16eb7

Please sign in to comment.