File size: 1,218 Bytes
1a74bcb
 
 
 
 
f3f99ec
c232c71
 
 
1a74bcb
 
c232c71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a74bcb
c232c71
f3f99ec
 
c232c71
 
 
 
 
 
 
 
 
 
 
 
f3f99ec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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,
)