Team Ai
Apppublic

beautiful-code/ai_workflows

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
create_article_pitch.py54 linesDownload Raw Back to tasks
1import json2import streamlit as st3 4import utils.settings as settings5 6from crewai import Task7from crewai.tasks.task_output import TaskOutput8from pydantic import BaseModel9from typing import List10 11from agents.curiosity_catalyst import curiosity_catalyst12from workflows.tools.scrape_website import scrape_tool13from tasks.create_learning_profile import learning_profile_task14from tasks.evaluate_articles import evaluation_task15 16 17class PitchedArticle(BaseModel):18    title: str19    url: str20    pitch: str21 22 23class PitchedArticles(BaseModel):24    articles: List[PitchedArticle]25 26 27def callback_function(output: TaskOutput):28    evaluated_articles = json.loads(output.exported_output)29    st.markdown(evaluated_articles)30    for article in evaluated_articles['articles']:31        settings.articles[article['url']]['pitch'] = article['pitch']32    st.markdown("### Create Article Pitch is executed successfully!")33 34 35article_pitch_task = Task(36    description=(37        "Create a pitch only for the articles that have been evaluated and no other links. "38        "Craft the pitch so to that it teases the article's most intriguing aspects, "39        "by posing questions that the article might answer or "40        "highlighting surprising facts to pique the user's curiosity "41        " to read the article for incremental learning."42    ),43    expected_output=(44        "List of all the artilces that have been evaluated phase along with their url and pitch statement and no other new urls."45    ),46    output_json=PitchedArticles,47    output_file="pitched_articles.json",48    tools=[scrape_tool],49    agent=curiosity_catalyst,50    async_execution=False,51    callback=callback_function,52    context=[learning_profile_task, evaluation_task]53)54