Skip to content

Commit

Permalink
chore: use different LLMs for different purposes and have custom mana…
Browse files Browse the repository at this point in the history
luandro committed Dec 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c540a59 commit 48c0945
Showing 4 changed files with 1,757 additions and 1,177 deletions.
3 changes: 2 additions & 1 deletion plugins/grant_plugin/opportunity_finder/pyproject.toml
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ authors = [{ name = "Your Name", email = "[email protected]" }]
requires-python = ">=3.10,<=3.13"
dependencies = [
"crewai[agentops,tools]>=0.76.2,<1.0.0",
"langtrace-python-sdk>=3.3.13",
]

[project.scripts]
@@ -20,4 +21,4 @@ requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.setuptools]
package-dir = {"" = "src"}
package-dir = {"" = "src"}
Original file line number Diff line number Diff line change
@@ -6,16 +6,59 @@

search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()
llm = LLM(
model="groq/llama3-groq-70b-8192-tool-use-preview", # Replace with your chosen Cerebras model name, e.g., "cerebras/llama3.1-8b"
api_key=os.environ.get("GROQ_API_KEY"), # Your Cerebras API key
model_name = "groq/llama-3.3-70b-versatile"
print(f"Using LLM model: {model_name}")

high_resource_model = "groq/llama-3.3-70b-versatile"
medium_resource_model = "groq/mixtral-8x7b-32768"
low_resource_model = "groq/llama-3.1-8b-instant"
high_resource_llm = LLM(
model=high_resource_model,
api_key=os.environ.get("GROQ_API_KEY"),
temperature=0.5,
)

medium_resource_llm = LLM(
model=medium_resource_model,
api_key=os.environ.get("GROQ_API_KEY"),
temperature=0.5,
)

low_resource_llm = LLM(
model=low_resource_model,
api_key=os.environ.get("GROQ_API_KEY"),
temperature=0.5,
)
@CrewBase
class OpportunityFinderCrew:
"""OpportunityFinder crew"""
def manager_agent(self) -> Agent:
return Agent(
role="Crew Manager",
goal="""
Manage the team to complete the task in the best way possible.
""",
backstory="""
You are a seasoned manager with a knack for getting the best out of your team.\nYou are also known for your ability to delegate work to the right people, and to ask the right questions to get the best out of your team.\nEven though you don't perform tasks by yourself, you have a lot of experience in the field, which allows you to properly evaluate the work of your team members.
Additional rules for Tools:
-----------------
1. Regarding the Action Input (the input to the action, just a simple python dictionary, enclosed
in curly braces, using \" to wrap keys and values.)
For example for the following schema:
```
class ExampleToolInput(BaseModel):
task: str = Field(..., description="The task to delegate")
context: str = Field(..., description="The context for the task")
coworker: str = Field(..., description="The role/name of the coworker to delegate to")
```
Then the input should be a JSON object with the user ID:
- task: The task to delegate
- context: The context for the task
- coworker: The role/name of the coworker to delegate to
""",
)

@agent
def search_specialist(self) -> Agent:
@@ -24,7 +67,7 @@ def search_specialist(self) -> Agent:
verbose=True,
allow_delegation=True,
tools=[search_tool, scrape_tool],
llm=llm,
llm=low_resource_llm,
)

@agent
@@ -34,7 +77,7 @@ def researcher(self) -> Agent:
tools=[search_tool, scrape_tool],
verbose=True,
allow_delegation=True,
llm=llm,
llm=medium_resource_llm,
)

@agent
@@ -43,7 +86,7 @@ def reporting_analyst(self) -> Agent:
config=self.agents_config["reporting_analyst"],
tools=[search_tool, scrape_tool],
verbose=True,
llm=llm,
llm=low_resource_llm,
)

@task
@@ -73,7 +116,9 @@ def crew(self) -> Crew:
agents=self.agents,
tasks=self.tasks,
process=Process.hierarchical,
manager_llm=llm,
# manager_llm=llm,
manager_agent=self.manager_agent(),
max_rpm=30,
verbose=True,
output_log_file=f'OpportunityFinderCrew_{datetime.datetime.now().strftime("%Y%m%d_%H%M%S")}.log',
)
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ def run():
def main(topics: str):
"""
Run the crew with specified topics.
Args:
topics: Comma-separated string of topics to search for opportunities
"""
@@ -37,6 +37,12 @@ def main(topics: str):
}
return OpportunityFinderCrew().crew().kickoff(inputs=inputs)

if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: uv run src/opportunity_finder/main.py 'topic1, topic2, topic3'")
sys.exit(1)
main(sys.argv[1])

def train():
"""
Train the crew for a given number of iterations.
2,864 changes: 1,696 additions & 1,168 deletions plugins/grant_plugin/opportunity_finder/uv.lock

Large diffs are not rendered by default.

0 comments on commit 48c0945

Please sign in to comment.