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
20.79k stars 2.87k forks source link

output #177

Closed drewskidang closed 3 months ago

drewskidang commented 9 months ago

can we append the model output into a json/jsonl??

Biancamazzi commented 9 months ago

don't forget we have https://chat.openai.com/g/g-qqTuUWsBY-crewai-assistant to help and also the discord community https://discord.com/invite/X4JWnZnxPb

C-1pher commented 9 months ago

it is possible , just store the output , then extract the part you want to append and use the json library to append the extracted part

drewskidang commented 9 months ago

@sc00rpi0n can you show me code example. Trying to save the output as a conversation

drewskidang commented 9 months ago

Trying to get the output of both agents as a collum

C-1pher commented 9 months ago

at the latest crewai update now the output have each agent name next to its output , assume the results is saved in "output" variable then here's an example code

# Extract agent answers and create a JSON conversation
conversation = []

# Split the output into blocks based on the working agent
blocks = output.split('[DEBUG]: Working Agent: ')

for block in blocks[1:]:
    agent_name, task_output = block.split('[DEBUG]: [', 1)
    agent_name = agent_name.strip()
    task_output = task_output.split('] Task output: ')[1].strip()

    conversation.append({
        "agent_name": agent_name,
        "answer": task_output
    })

# Create a JSON conversation
json_conversation = json.dumps(conversation, indent=2)

# Print the JSON conversation
print(json_conversation)

that's is just an example you can edit it to match your needs

drewskidang commented 9 months ago

@sc00rpi0n would outputs be the result if i did result = crew.kickoff()

C-1pher commented 9 months ago

yes , but make sure to change the name f the variable in the script as i used output = crew.kickoff()