Spaces:
Runtime error
Runtime error
File size: 1,913 Bytes
1a74bcb f3f99ec c232c71 1a74bcb 60ce749 c232c71 f8558a4 1a74bcb f8558a4 1a74bcb c232c71 f3f99ec c232c71 60ce749 c232c71 60ce749 c232c71 60ce749 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 46 47 48 49 50 51 52 53 54 55 56 57 58 | 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.article_evaluator import article_evaluator
from tasks.create_learning_profile import learning_profile_task
from tasks.new_article_suggestion import article_suggestion_task
class EvaluatedArticle(BaseModel):
title: str
url: str
evaluation_score: int
evaluation_reason: str
class EvaluatedArticles(BaseModel):
articles: List[EvaluatedArticle]
def callback_function(output: TaskOutput):
evaluated_articles = json.loads(output.exported_output)['articles']
for article in evaluated_articles:
settings.articles[article['url']
]['evaluation_score'] = article['evaluation_score']
settings.articles[article['url']
]['evaluation_reason'] = article['evaluation_reason']
st.markdown("### Evaluate Articles task is executed successfully!")
evaluation_task = Task(
description=(
"Evaluate artilces based on the metric does the articles provide incremenrtal "
"learning w.r.t the insights captured by the user. "
"Score the articles on the scale of 1 to 10, "
"1 being doesn't provide incremental learning and "
"10 being provides incremental learning to the user."
"Evaluate only articles that have been suggested to the user and no other articles."
),
expected_output=(
"List of article titles with their URLs, evaluation scores, "
"and evaluation reasons w.r.t insights captured by the user."
),
output_json=EvaluatedArticles,
output_file="evaluated_articles.json",
agent=article_evaluator,
async_execution=False,
callback=callback_function,
context=[learning_profile_task, article_suggestion_task]
)
|