crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
21.21k stars 2.94k forks source link

converting training_data to trained_agents_data error #884

Open WellyngtonF opened 4 months ago

WellyngtonF commented 4 months ago

Hi, Im studying CrewAI, i tried to create a crew to make docs about some code, when i try to use the new feature for train i got this error :

Traceback (most recent call last): File "/home/wellyngton/Documentos/CrewDoc/main.py", line 35, in documentation_crew.train(n_iterations = 1, inputs = inputs[0]) File "/home/wellyngton/Documentos/CrewDoc/.venv/lib/python3.12/site-packages/crewai/crew.py", line 312, in train agent_id=str(agent.role), trained_data=result.model_dump() ^^^^^^^^^^^^^^^^^ AttributeError: 'ConverterError' object has no attribute 'model_dump'

I think this has something with the content of the training_data.pkl, because i pass/home/wellyngton/Documentos/CrewDoc/training_data.json a bunch of code in input, and this have quotes and brackets, so maybe the converter isnt working properly, someone can help me to fix this or point possibles fixes to the crewAI package ?

This is the training_data converted to json using picke.load: training_data.json

I tested with a agent reading my own main.py file

theCyberTech commented 4 months ago

Hi @WellyngtonF Can you share what your inputs are please?

WellyngtonF commented 4 months ago

Hi @theCyberTech, This is my Agent config:

code_interpreter:
  role: >
    Code Interpreter
  backstory: >
    You are a Code Interpreter specialist that likes to interpret code and explain it in a way that everyone can understand your solution
  goal: >
    Interpret the code and create a documentation following the industry standards.

My task config:

code_interpret_task:
  description: >
    Interpret the code below and explain following the documentation standards.

    "{file_content}"

    You can use code snippets from the file content in your explanation.
  expected_output: >
    The explanation of the code

This is the task input when training:

Interpret the code below and explain following the documentation standards.
"import warnings
warnings.filterwarnings("ignore")

import os
from crew import DocumentationCrew
from crewai_tools import FileReadTool
# make a list of all the content files with .py extension in a file path (can access all the folders and subfolders), exclude __pycache__ and .venv folder
# then read the content of the files and store them in a list
def read_files(dir):
    r = []
    for root, dirs, files in os.walk(dir):
        for name in files:
            if name.endswith('.py') and '__pycache__' not in root and '.venv' not in root:
                r.append(os.path.join(root, name))

    list_content = []
    for file in r:
        with open(file, 'r') as f:
            content = f.read()
            list_content.append(content)

    return list_content    

files = read_files('/home/wellyngton/Documentos/CrewDoc')

inputs = [{'file_content': file} for file in files]
inputs = inputs[:1]

documentation_crew = DocumentationCrew().crew()

# documentation_crew.kickoff(inputs[0])
documentation_crew.train(n_iterations = 1, inputs = inputs[0])"
You can use code snippets from the file content in your explanation.
theCyberTech commented 4 months ago

Hi @WellyngtonF

Looking at your inputs section, you might need to re-evaluate what you are trying to do here as the one issue I think I can see is below

Both crew.kickoff & crew.train expecting dict to be pass but you have specified a list inputs = inputs[0]

WellyngtonF commented 4 months ago

Hi @WellyngtonF

Looking at your inputs section, you might need to re-evaluate what you are trying to do here as the one issue I think I can see is below

Both crew.kickoff & crew.train expecting dict to be pass but you have specified a list inputs = inputs[0]

My inputs its a list of dict, so passing inputs[0] will give a dict to the train, this works fine in kickoff, i only have problems when i run the train function and needs to write data to the trained_agent_data.pkl file, i think this has something to do with my llm, with ollama using llama3 or mistral i got this problem, but using openAi api works fine.

meetzuber commented 3 months ago

I am also facing same issue. also did not find proper documentation about crewai train agent feature.

CarstenHoyer commented 3 months ago

I see the same with Ollama LLama3:8b

Could be here: https://github.com/crewAIInc/crewAI/blob/main/src/crewai/utilities/evaluators/task_evaluator.py#L128

Seems to be related to special chars in the result set; " or {}.

strikeoncmputrz commented 1 month ago

I hit the same error running Crewai version 0.65.2

Traceback (most recent call last):                                                   
  File "/home/x0xxin/crew/horizon/src/horizon/main.py", line 30, in train                                                                                                 
    HorizonCrew().crew().train(n_iterations=int(sys.argv[1]), filename=sys.argv[2])                                                                                       
  File "/home/x0xxin/crew2/lib/python3.12/site-packages/crewai/crew.py", line 449, in train                                                                               
    agent_id=str(agent.role), trained_data=result.model_dump()                                                                                                            
                                           ^^^^^^^^^^^^^^^^^                                                                                                              
AttributeError: 'ConverterError' object has no attribute 'model_dump'                                                                                                     

During handling of the above exception, another exception occurred:                                                                                                       

Traceback (most recent call last):                                                   
  File "<string>", line 1, in <module>                                               
  File "/home/x0xxin/crew/horizon/src/horizon/main.py", line 33, in train                                                                                                 
    raise Exception(f"An error occurred while training the crew: {e}")                                                                                                    
Exception: An error occurred while training the crew: 'ConverterError' object has no attribute 'model_dump'
An error occurred while training the crew: Command '['poetry', 'run', 'train', '2', 'trained_agents_data.pkl']' returned non-zero exit status 1.