Spaces:
Runtime error
Runtime error
Merge pull request #3 from beautiful-code/feature/add-streamlit-ui
Browse files- agents/article_evaluator.py +3 -1
- agents/curiosity_catalyst.py +3 -1
- agents/learning_curator.py +4 -2
- agents/learning_profiler.py +5 -2
- app.py +81 -21
- crew/article_suggestion.py +2 -1
- llms/gemini.py +8 -0
- tasks/create_article_pitch.py +13 -8
- tasks/create_learning_profile.py +11 -3
- tasks/evaluate_articles.py +15 -10
- tasks/new_article_suggestion.py +8 -3
- tools/helpers.py +45 -0
agents/article_evaluator.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from crewai import Agent
|
| 2 |
from llms.gpt import llm
|
|
|
|
| 3 |
|
| 4 |
article_evaluator = Agent(
|
| 5 |
role="Recommended Article Evaluator",
|
|
@@ -14,5 +15,6 @@ article_evaluator = Agent(
|
|
| 14 |
"incremental learning once the user completes reading the articles."
|
| 15 |
),
|
| 16 |
allow_delegation=False,
|
| 17 |
-
llm=llm
|
|
|
|
| 18 |
)
|
|
|
|
| 1 |
from crewai import Agent
|
| 2 |
from llms.gpt import llm
|
| 3 |
+
from tools.helpers import streamlit_callback
|
| 4 |
|
| 5 |
article_evaluator = Agent(
|
| 6 |
role="Recommended Article Evaluator",
|
|
|
|
| 15 |
"incremental learning once the user completes reading the articles."
|
| 16 |
),
|
| 17 |
allow_delegation=False,
|
| 18 |
+
llm=llm,
|
| 19 |
+
step_callback=streamlit_callback
|
| 20 |
)
|
agents/curiosity_catalyst.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from crewai import Agent
|
| 2 |
from llms.gpt import llm
|
|
|
|
| 3 |
from tools.scrape_website import scrape_tool
|
| 4 |
|
| 5 |
curiosity_catalyst = Agent(
|
|
@@ -12,5 +13,6 @@ curiosity_catalyst = Agent(
|
|
| 12 |
"for reading the articles."
|
| 13 |
),
|
| 14 |
allow_delegation=False,
|
| 15 |
-
llm=llm
|
|
|
|
| 16 |
)
|
|
|
|
| 1 |
from crewai import Agent
|
| 2 |
from llms.gpt import llm
|
| 3 |
+
from tools.helpers import streamlit_callback
|
| 4 |
from tools.scrape_website import scrape_tool
|
| 5 |
|
| 6 |
curiosity_catalyst = Agent(
|
|
|
|
| 13 |
"for reading the articles."
|
| 14 |
),
|
| 15 |
allow_delegation=False,
|
| 16 |
+
llm=llm,
|
| 17 |
+
step_callback=streamlit_callback
|
| 18 |
)
|
agents/learning_curator.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
from crewai import Agent
|
|
|
|
|
|
|
| 2 |
from tools.scrape_website import scrape_tool
|
| 3 |
from tools.search_web import search_tool
|
| 4 |
-
from llms.gpt import llm
|
| 5 |
|
| 6 |
learning_curator = Agent(
|
| 7 |
role="Personal Learning Curator",
|
|
@@ -14,5 +15,6 @@ learning_curator = Agent(
|
|
| 14 |
),
|
| 15 |
allow_delegation=False,
|
| 16 |
tools=[scrape_tool, search_tool],
|
| 17 |
-
llm=llm
|
|
|
|
| 18 |
)
|
|
|
|
| 1 |
from crewai import Agent
|
| 2 |
+
from llms.gpt import llm
|
| 3 |
+
from tools.helpers import streamlit_callback
|
| 4 |
from tools.scrape_website import scrape_tool
|
| 5 |
from tools.search_web import search_tool
|
|
|
|
| 6 |
|
| 7 |
learning_curator = Agent(
|
| 8 |
role="Personal Learning Curator",
|
|
|
|
| 15 |
),
|
| 16 |
allow_delegation=False,
|
| 17 |
tools=[scrape_tool, search_tool],
|
| 18 |
+
llm=llm,
|
| 19 |
+
step_callback=streamlit_callback
|
| 20 |
)
|
agents/learning_profiler.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from crewai import Agent
|
| 2 |
-
from tools.scrape_website import scrape_tool
|
| 3 |
from llms.gpt import llm
|
|
|
|
|
|
|
| 4 |
|
| 5 |
learning_profiler = Agent(
|
| 6 |
role="Personal Learning Profiler",
|
|
@@ -11,5 +12,7 @@ learning_profiler = Agent(
|
|
| 11 |
"The profile you build gives a high level overview of what interests that the user has. "
|
| 12 |
),
|
| 13 |
allow_delegation=False,
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
)
|
|
|
|
| 1 |
from crewai import Agent
|
|
|
|
| 2 |
from llms.gpt import llm
|
| 3 |
+
from tools.helpers import streamlit_callback
|
| 4 |
+
from tools.scrape_website import scrape_tool
|
| 5 |
|
| 6 |
learning_profiler = Agent(
|
| 7 |
role="Personal Learning Profiler",
|
|
|
|
| 12 |
"The profile you build gives a high level overview of what interests that the user has. "
|
| 13 |
),
|
| 14 |
allow_delegation=False,
|
| 15 |
+
OPENAI_API_KEY="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",
|
| 16 |
+
llm=llm,
|
| 17 |
+
step_callback=streamlit_callback
|
| 18 |
)
|
app.py
CHANGED
|
@@ -1,31 +1,91 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
|
| 4 |
-
from crew.article_suggestion import article_recommendation_crew
|
| 5 |
import utils.settings as settings
|
|
|
|
|
|
|
|
|
|
| 6 |
from utils.write_to_json import write_dict_to_json as write_dict_to_json
|
| 7 |
|
| 8 |
settings.init()
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
"Tool Use: The LLM is given tools such as web search, code execution, or any other function to help it gather information, take action, or process data. "
|
| 17 |
-
"Planning: The LLM comes up with, and executes, a multistep plan to achieve a goal "
|
| 18 |
-
"Multi-agent collaboration: More than one AI agent work together, splitting up tasks and discussing and debating ideas, to come up with better solutions than a single agent would.\n\n"
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
})
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
print(result)
|
| 29 |
-
print("Usage Metrics:\n", article_recommendation_crew.usage_metrics)
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import streamlit as st
|
| 3 |
|
|
|
|
| 4 |
import utils.settings as settings
|
| 5 |
+
|
| 6 |
+
from crew.article_suggestion import article_recommendation_crew
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
from utils.write_to_json import write_dict_to_json as write_dict_to_json
|
| 9 |
|
| 10 |
settings.init()
|
| 11 |
|
| 12 |
+
load_dotenv(
|
| 13 |
+
"/home/quizra/Documents/Learning_practise/python/streamlit/growthi-app/growthy_agents/.env"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def icon(emoji: str):
|
| 18 |
+
"""Shows an emoji as a Notion-style page icon."""
|
| 19 |
+
st.write(
|
| 20 |
+
f'<span style="font-size: 78px; line-height: 1">{emoji}</span>',
|
| 21 |
+
unsafe_allow_html=True,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
st.set_page_config(layout="wide")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def main():
|
| 29 |
+
icon("📖 Articles RecommendAIgent")
|
| 30 |
+
st.subheader("Let AI agents recommend articles based on your interest!")
|
| 31 |
+
|
| 32 |
+
with st.sidebar:
|
| 33 |
+
st.header("👇 Provide Your Interests Below!")
|
| 34 |
+
with st.form("user_input_form", border=True):
|
| 35 |
+
interests = st.text_input(
|
| 36 |
+
"Enter your interests (comma-separated):",
|
| 37 |
+
"GenAI, Architecture, Agentic Programming",
|
| 38 |
+
)
|
| 39 |
+
previous_article_insights = st.text_area(
|
| 40 |
+
"Enter previous article insights:",
|
| 41 |
+
"Agentic Design Patterns (https://www.deeplearning.ai/the-batch/how-agents-can-improve-llm-performance/)\n"
|
| 42 |
+
"Reflection: The LLM examines its own work to come up with ways to improve it. "
|
| 43 |
+
"Tool Use: The LLM is given tools such as web search, code execution, or any other function to help it gather information, take action, or process data. "
|
| 44 |
+
"Planning: The LLM comes up with, and executes, a multistep plan to achieve a goal "
|
| 45 |
+
"Multi-agent collaboration: More than one AI agent work together, splitting up tasks and discussing and debating ideas, to come up with better solutions than a single agent would.\n\n"
|
| 46 |
+
# "GenAI Multi-Agent Systems (https://thenewstack.io/genai-multi-agent-systems-a-secret-weapon-for-tech-teams/)\n"
|
| 47 |
+
"Multi-agent systems go beyond the task-oriented roles to truly super-charge development and strategy teams. "
|
| 48 |
+
"Successful multi-agent systems act as a “digital twin” for your development team. "
|
| 49 |
+
"Different Approaches: 1. Centralized, with one agent in the center that collects and assimilates all the other outputs. "
|
| 50 |
+
"2. Distributed, where there is no central controller and the agents coordinate directly with one another in an “agent swarm. "
|
| 51 |
+
"3. Hierarchical, where agents are organized in teams or hierarchical layers.\n",
|
| 52 |
+
height=400,
|
| 53 |
+
)
|
| 54 |
+
st.markdown("") # Adding a blank space here
|
| 55 |
+
submitted = st.form_submit_button("Submit")
|
| 56 |
+
|
| 57 |
+
if submitted:
|
| 58 |
+
with st.status(
|
| 59 |
+
"🤖 **Agents at work...**", state="running", expanded=True
|
| 60 |
+
) as status:
|
| 61 |
+
with st.container(height=500, border=False):
|
| 62 |
+
result = article_recommendation_crew.kickoff(
|
| 63 |
+
inputs={
|
| 64 |
+
"interests": interests,
|
| 65 |
+
"previous_article_insights": previous_article_insights,
|
| 66 |
+
}
|
| 67 |
+
)
|
| 68 |
+
status.update(
|
| 69 |
+
label="✅ Articles are Ready for Reading!",
|
| 70 |
+
state="complete",
|
| 71 |
+
expanded=False,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
st.subheader("", anchor=False, divider="rainbow")
|
| 75 |
|
| 76 |
+
json_data = json.loads(result)
|
| 77 |
+
articles_list = json_data.get("articles", None)
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
if articles_list is None:
|
| 80 |
+
st.markdown("No articles found.")
|
| 81 |
+
return
|
| 82 |
+
else:
|
| 83 |
+
for article in articles_list:
|
| 84 |
+
st.markdown(f"# {article['title']}")
|
| 85 |
+
st.markdown(f"**URL:** [{article['url']}]({article['url']})")
|
| 86 |
+
st.markdown(f"**Pitch:** {article['pitch']}")
|
| 87 |
+
st.markdown("---")
|
| 88 |
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
main()
|
crew/article_suggestion.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from crewai import Crew
|
|
|
|
| 2 |
from agents.learning_profiler import learning_profiler
|
| 3 |
from agents.learning_curator import learning_curator
|
| 4 |
from agents.article_evaluator import article_evaluator
|
|
@@ -7,7 +8,6 @@ from tasks.create_learning_profile import learning_profile_task
|
|
| 7 |
from tasks.new_article_suggestion import article_suggestion_task
|
| 8 |
from tasks.evaluate_articles import evaluation_task
|
| 9 |
from tasks.create_article_pitch import article_pitch_task
|
| 10 |
-
from llms.gpt import llm
|
| 11 |
|
| 12 |
article_recommendation_crew = Crew(
|
| 13 |
agents=[learning_profiler, learning_curator,
|
|
@@ -23,4 +23,5 @@ article_recommendation_crew = Crew(
|
|
| 23 |
"model": 'text-embedding-3-small'
|
| 24 |
}
|
| 25 |
}
|
|
|
|
| 26 |
)
|
|
|
|
| 1 |
from crewai import Crew
|
| 2 |
+
from llms.gpt import llm
|
| 3 |
from agents.learning_profiler import learning_profiler
|
| 4 |
from agents.learning_curator import learning_curator
|
| 5 |
from agents.article_evaluator import article_evaluator
|
|
|
|
| 8 |
from tasks.new_article_suggestion import article_suggestion_task
|
| 9 |
from tasks.evaluate_articles import evaluation_task
|
| 10 |
from tasks.create_article_pitch import article_pitch_task
|
|
|
|
| 11 |
|
| 12 |
article_recommendation_crew = Crew(
|
| 13 |
agents=[learning_profiler, learning_curator,
|
|
|
|
| 23 |
"model": 'text-embedding-3-small'
|
| 24 |
}
|
| 25 |
}
|
| 26 |
+
# manager_llm=gemini_client
|
| 27 |
)
|
llms/gemini.py
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
|
|
| 1 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
llm=ChatGoogleGenerativeAI(model="gemini-1.5-flash",verbose=True)
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
|
| 4 |
+
try:
|
| 5 |
+
# Check if there's already a running event loop
|
| 6 |
+
asyncio.get_event_loop()
|
| 7 |
+
except RuntimeError:
|
| 8 |
+
# If not, create a new event loop
|
| 9 |
+
asyncio.set_event_loop(asyncio.new_event_loop())
|
| 10 |
+
|
| 11 |
llm=ChatGoogleGenerativeAI(model="gemini-1.5-flash",verbose=True)
|
tasks/create_article_pitch.py
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from crewai import Task
|
| 2 |
-
from agents.curiosity_catalyst import curiosity_catalyst
|
| 3 |
-
from tools.scrape_website import scrape_tool
|
| 4 |
from crewai.tasks.task_output import TaskOutput
|
| 5 |
-
import utils.settings as settings
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from typing import List
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
class PitchedArticle(BaseModel):
|
|
@@ -19,10 +23,11 @@ class PitchedArticles(BaseModel):
|
|
| 19 |
|
| 20 |
|
| 21 |
def callback_function(output: TaskOutput):
|
| 22 |
-
evaluated_articles = json.loads(output.exported_output)['articles']
|
| 23 |
-
|
| 24 |
-
for article in evaluated_articles:
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
article_pitch_task = Task(
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
import utils.settings as settings
|
| 5 |
+
|
| 6 |
from crewai import Task
|
|
|
|
|
|
|
| 7 |
from crewai.tasks.task_output import TaskOutput
|
|
|
|
| 8 |
from pydantic import BaseModel
|
| 9 |
from typing import List
|
| 10 |
+
|
| 11 |
+
from agents.curiosity_catalyst import curiosity_catalyst
|
| 12 |
+
from tools.scrape_website import scrape_tool
|
| 13 |
|
| 14 |
|
| 15 |
class PitchedArticle(BaseModel):
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def callback_function(output: TaskOutput):
|
| 26 |
+
# evaluated_articles = json.loads(output.exported_output)['articles']
|
| 27 |
+
# st.markdown(evaluated_articles)
|
| 28 |
+
# for article in evaluated_articles:
|
| 29 |
+
# settings.articles[article['url']]['pitch'] = article['pitch']
|
| 30 |
+
st.markdown("### Create Article Pitch is executed successfully!")
|
| 31 |
|
| 32 |
|
| 33 |
article_pitch_task = Task(
|
tasks/create_learning_profile.py
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from crewai import Task
|
| 2 |
-
from
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from typing import List
|
| 5 |
|
|
|
|
|
|
|
| 6 |
|
| 7 |
class Topic(BaseModel):
|
| 8 |
name: str
|
|
@@ -12,7 +17,9 @@ class Topic(BaseModel):
|
|
| 12 |
class LearningProfile(BaseModel):
|
| 13 |
topics_of_interests: List[str]
|
| 14 |
learnings: List[Topic]
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
learning_profile_task = Task(
|
| 18 |
description=(
|
|
@@ -27,5 +34,6 @@ learning_profile_task = Task(
|
|
| 27 |
agent=learning_profiler,
|
| 28 |
output_json=LearningProfile,
|
| 29 |
output_file="learning_profile.json",
|
| 30 |
-
async_execution=False
|
|
|
|
| 31 |
)
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
from crewai import Task
|
| 5 |
+
from crewai.tasks.task_output import TaskOutput
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from typing import List
|
| 8 |
|
| 9 |
+
from agents.learning_profiler import learning_profiler
|
| 10 |
+
|
| 11 |
|
| 12 |
class Topic(BaseModel):
|
| 13 |
name: str
|
|
|
|
| 17 |
class LearningProfile(BaseModel):
|
| 18 |
topics_of_interests: List[str]
|
| 19 |
learnings: List[Topic]
|
| 20 |
+
|
| 21 |
+
def callback_function(output: TaskOutput):
|
| 22 |
+
st.markdown("### Create Learning Profile task is executed successfully!")
|
| 23 |
|
| 24 |
learning_profile_task = Task(
|
| 25 |
description=(
|
|
|
|
| 34 |
agent=learning_profiler,
|
| 35 |
output_json=LearningProfile,
|
| 36 |
output_file="learning_profile.json",
|
| 37 |
+
async_execution=False,
|
| 38 |
+
callback=callback_function
|
| 39 |
)
|
tasks/evaluate_articles.py
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from crewai import Task
|
| 2 |
-
from agents.article_evaluator import article_evaluator
|
| 3 |
from crewai.tasks.task_output import TaskOutput
|
| 4 |
-
import utils.settings as settings
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from typing import List
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
class EvaluatedArticle(BaseModel):
|
|
@@ -19,13 +23,14 @@ class EvaluatedArticles(BaseModel):
|
|
| 19 |
|
| 20 |
|
| 21 |
def callback_function(output: TaskOutput):
|
| 22 |
-
evaluated_articles = json.loads(output.exported_output)['articles']
|
| 23 |
-
|
| 24 |
-
for article in evaluated_articles:
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
evaluation_task = Task(
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
import utils.settings as settings
|
| 5 |
+
|
| 6 |
from crewai import Task
|
|
|
|
| 7 |
from crewai.tasks.task_output import TaskOutput
|
|
|
|
| 8 |
from pydantic import BaseModel
|
| 9 |
from typing import List
|
| 10 |
+
|
| 11 |
+
from agents.article_evaluator import article_evaluator
|
| 12 |
|
| 13 |
|
| 14 |
class EvaluatedArticle(BaseModel):
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def callback_function(output: TaskOutput):
|
| 26 |
+
# evaluated_articles = json.loads(output.exported_output)['articles']
|
| 27 |
+
|
| 28 |
+
# for article in evaluated_articles:
|
| 29 |
+
# settings.articles[article['url']
|
| 30 |
+
# ]['evaluation_score'] = article['evaluation_score']
|
| 31 |
+
# settings.articles[article['url']
|
| 32 |
+
# ]['evaluation_reason'] = article['evaluation_reason']
|
| 33 |
+
st.markdown("### Evaluate Articles task is executed successfully!")
|
| 34 |
|
| 35 |
|
| 36 |
evaluation_task = Task(
|
tasks/new_article_suggestion.py
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from crewai import Task
|
| 2 |
-
from agents.learning_curator import learning_curator
|
| 3 |
from crewai.tasks.task_output import TaskOutput
|
| 4 |
-
import utils.settings as settings
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from typing import List
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
class SuggestedArticle(BaseModel):
|
|
@@ -22,6 +26,7 @@ def callback_function(output: TaskOutput):
|
|
| 22 |
|
| 23 |
for article in suggested_articles:
|
| 24 |
settings.articles[article['url']] = article
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
article_suggestion_task = Task(
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
import utils.settings as settings
|
| 5 |
+
|
| 6 |
from crewai import Task
|
|
|
|
| 7 |
from crewai.tasks.task_output import TaskOutput
|
|
|
|
| 8 |
from pydantic import BaseModel
|
| 9 |
from typing import List
|
| 10 |
+
|
| 11 |
+
from agents.learning_curator import learning_curator
|
| 12 |
|
| 13 |
|
| 14 |
class SuggestedArticle(BaseModel):
|
|
|
|
| 26 |
|
| 27 |
for article in suggested_articles:
|
| 28 |
settings.articles[article['url']] = article
|
| 29 |
+
st.markdown("### New Article Suggestion task is executed successfully!")
|
| 30 |
|
| 31 |
|
| 32 |
article_suggestion_task = Task(
|
tools/helpers.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from crewai.tasks.task_output import TaskOutput
|
| 3 |
+
|
| 4 |
+
def streamlit_callback(step_output:TaskOutput):
|
| 5 |
+
st.markdown("---")
|
| 6 |
+
for step in step_output:
|
| 7 |
+
if isinstance(step, tuple) and len(step) == 2:
|
| 8 |
+
action, observation = step
|
| 9 |
+
|
| 10 |
+
# Display action information
|
| 11 |
+
if isinstance(action, dict) and all(key in action for key in ["tool", "tool_input", "log"]):
|
| 12 |
+
st.markdown(f"**Tool:** {action['tool']}")
|
| 13 |
+
st.markdown(f"**Tool Input:** {action['tool_input']}")
|
| 14 |
+
st.markdown(f"**Log:** {action['log']}")
|
| 15 |
+
if "Action" in action:
|
| 16 |
+
st.markdown(f"# 📝 Processing Action...")
|
| 17 |
+
st.markdown(f"**Action:** {action['Action']}")
|
| 18 |
+
st.markdown(f"**Action Input:** ```json\n{action['tool_input']}\n```")
|
| 19 |
+
elif isinstance(action, str):
|
| 20 |
+
if action != 'log':
|
| 21 |
+
continue
|
| 22 |
+
st.markdown(f"# Action Result...")
|
| 23 |
+
st.markdown(f"**Action:** {action}")
|
| 24 |
+
else:
|
| 25 |
+
st.markdown(f"**Action:** {str(action)}")
|
| 26 |
+
|
| 27 |
+
# Display observation information
|
| 28 |
+
st.markdown(f"**Thought**")
|
| 29 |
+
if isinstance(observation, str):
|
| 30 |
+
observation_lines = observation.split('\n')
|
| 31 |
+
for line in observation_lines:
|
| 32 |
+
if line.startswith('Title: '):
|
| 33 |
+
st.markdown(f"**Title:** {line[7:]}")
|
| 34 |
+
elif line.startswith('Link: '):
|
| 35 |
+
st.markdown(f"**Link:** {line[6:]}")
|
| 36 |
+
elif line.startswith('Snippet: '):
|
| 37 |
+
st.markdown(f"**Snippet:** {line[9:]}")
|
| 38 |
+
elif line.startswith('-'):
|
| 39 |
+
st.markdown(line)
|
| 40 |
+
else:
|
| 41 |
+
st.markdown(line)
|
| 42 |
+
else:
|
| 43 |
+
st.markdown(str(observation))
|
| 44 |
+
else:
|
| 45 |
+
st.markdown(step)
|