crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

output

Open drewskidang opened this issue 2 years ago • 7 comments

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

drewskidang avatar Jan 24 '24 03:01 drewskidang

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

Biancamazzi avatar Jan 24 '24 16:01 Biancamazzi

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

sc00rpi0n avatar Jan 26 '24 12:01 sc00rpi0n

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

drewskidang avatar Feb 05 '24 23:02 drewskidang

Trying to get the output of both agents as a collum

drewskidang avatar Feb 05 '24 23:02 drewskidang

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

sc00rpi0n avatar Feb 06 '24 00:02 sc00rpi0n

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

drewskidang avatar Feb 06 '24 04:02 drewskidang

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

sc00rpi0n avatar Feb 06 '24 15:02 sc00rpi0n