No project description provided
Project description
- Install via pip
pip install crewai-logging-patch
- Add import into your main crewai file - This needs to be above any other crewai imports
from logger_patch import apply_monkey_patch
- Add the patch method to your code - This needs to be above any other crewai imports
apply_monkey_patch()
- Add the following directly below your agent instances - You must use your agent names in place of <placeholder_name>
<placeholder_name>._logger = crewai.utilities.Logger(verbose_level=<placeholder_name>.verbose)
- And the same below your crew instance, again you must use your crew name in place of <placeholder_name>
<placeholder_name>._logger = crewai.utilities.Logger(verbose_level=<placeholder_name>.verbose)
- Ensure that verbose=True is set in your agent and crew instances
- Below is an example crewfile with all of this implemented
import os
from logger_patch import apply_monkey_patch
# Apply the monkey patch
apply_monkey_patch()
# Now use crewai and other imports as usual
from crewai import Agent, Crew, Task, Process
import crewai.utilities
# Setup LM Studio environment variables
os.environ['OPENAI_API_BASE'] = 'http://localhost:1234/v1'
os.environ['OPENAI_API_KEY'] = 'sk-111111111111111111111111111111111111111111111111'
os.environ['OPENAI_MODEL_NAME'] = 'Meta-Llama-3-8B-Instruct-imatrix'
# Create the agent
try:
researcher = Agent(
role='Researcher',
goal='Research the topic',
backstory='As an expert in the field of {topic}, you will research the topic and provide the necessary information',
max_iter=3,
max_rpm=100,
verbose=True,
allow_delegation=False,
)
# Manually set the logger to ensure it's the patched logger
researcher._logger = crewai.utilities.Logger(verbose_level=researcher.verbose)
# Create the task
research_task = Task(
description='Research the topic',
agent=researcher,
expected_output='5 paragraphs of information on the topic',
output_file='research_result.txt',
)
# Create the crew
crew = Crew(
agents=[researcher],
tasks=[research_task],
process=Process.sequential,
verbose=True,
memory=False,
cache=False,
max_rpm=100,
)
# Manually set the logger for crew to ensure it's the patched logger
crew._logger = crewai.utilities.Logger(verbose_level=crew.verbose)
# Start the crew
result = crew.kickoff(inputs={'topic': '70s, 80s and 90s Australian rock bands'})
except Exception as e:
print(f"An error occurred: {e}")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for crewai_logging_patch-0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85d9f625d6dd1c3e4a13ee75c5efd684e4b6e4a67144e23cd9997c9677614d78 |
|
MD5 | e4990f768e682f19aa90f391c00ab289 |
|
BLAKE2b-256 | c7562eaab6b896143357f113ca60fa5bf84777f4d0b45f0861ea75d54bb549fe |