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
18.45k stars 2.54k forks source link

converting training_data to trained_agents_data error #884

Open WellyngtonF opened 1 month ago

WellyngtonF commented 1 month 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 1 month ago

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

WellyngtonF commented 1 month 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 1 month 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 1 month 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 2 weeks ago

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

CarstenHoyer commented 5 days 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 {}.