Spaces:
Runtime error
Runtime error
Download tasks/new_article_suggestion.py from beautiful-code/ai_workflows: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/beautiful-code/ai_workflows/resolve/main/tasks/new_article_suggestion.py
- Command line
-
hf download hf://spaces/beautiful-code/ai_workflows/tasks/new_article_suggestion.py
-
curl -L -o new_article_suggestion.py https://huggingface.co/spaces/beautiful-code/ai_workflows/resolve/main/tasks/new_article_suggestion.py
1.22 kB
| import json | |
| import streamlit as st | |
| import utils.settings as settings | |
| from crewai import Task | |
| from crewai.tasks.task_output import TaskOutput | |
| from pydantic import BaseModel | |
| from typing import List | |
| from agents.learning_curator import learning_curator | |
| class SuggestedArticle(BaseModel): | |
| title: str | |
| url: str | |
| reason_for_recommendation: str | |
| class SuggestedArticles(BaseModel): | |
| articles: List[SuggestedArticle] | |
| def callback_function(output: TaskOutput): | |
| suggested_articles = json.loads(output.exported_output)['articles'] | |
| for article in suggested_articles: | |
| settings.articles[article['url']] = article | |
| st.markdown("### New Article Suggestion task is executed successfully!") | |
| article_suggestion_task = Task( | |
| description=( | |
| "Find 5 articles from the past 10 days that align with the user's learning interests. " | |
| "The articles should provide incremental learning to the user based on their insights." | |
| ), | |
| expected_output=( | |
| "List of article titles along with their links. " | |
| ), | |
| output_json=SuggestedArticles, | |
| output_file="article_suggestions.json", | |
| agent=learning_curator, | |
| async_execution=False, | |
| callback=callback_function, | |
| ) | |