beautiful-code/ai_workflows
0
1import json2import streamlit as st3 4from crewai import Task5from crewai.tasks.task_output import TaskOutput6from pydantic import BaseModel7from typing import List8 9from agents.learning_profiler import learning_profiler10 11 12class Topic(BaseModel):13 name: str14 insights: List[str]15 16 17class LearningProfile(BaseModel):18 topics_of_interests: List[str]19 learnings: List[Topic]20 21def callback_function(output: TaskOutput):22 st.markdown("### Learning profile of the user:")23 data=json.loads(output.exported_output)24 st.markdown(f"**topics_of_interests:** {data['topics_of_interests'][0]}")25 st.markdown(f"**learnings:**")26 for topic in data['learnings']:27 st.markdown(f"*{topic['name']}*:{topic['insights'][0]}")28 29learning_profile_task = Task(30 description=(31 "Create a Learning profile of the user based on "32 "the following articles and insights he has read in the past: \n"33 "{previous_article_insights}"34 ),35 expected_output=(36 "A structured learning profile of the user with his interests, topics he has read about "37 "and insights he has captured on the topics."38 ),39 agent=learning_profiler,40 output_json=LearningProfile,41 output_file="learning_profile.json",42 async_execution=False,43 callback=callback_function44)45 