Skip to content

style: format code with Ruff Formatter #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions app/crew/crew.py
Original file line number Diff line number Diff line change
@@ -45,31 +45,23 @@ def get_research_crew(query: ResearchQuery) -> Crew:

# Initialize agents with appropriate tools
relevancy_agent = get_relevancy_agent(AgentInput(query=query))
research_agent = get_research_agent(
AgentInput(query=query, tools=[tavily_extractor_tool, tavily_search_tool])
)
research_agent = get_research_agent(AgentInput(query=query, tools=[tavily_extractor_tool, tavily_search_tool]))
query_agent = get_query_agent(AgentInput(query=query))
retrieval_agent = get_retrieval_agent(
AgentInput(
query=query, tools=[tavily_extractor_tool, tavily_search_tool, qdrant_tool]
)
AgentInput(query=query, tools=[tavily_extractor_tool, tavily_search_tool, qdrant_tool])
)
synthesizer_agent = get_synthesizer_agent(AgentInput(query=query))

# Initialize tasks with assigned agents
question_relevancy_task = get_question_relevancy_task(
TaskInput(agent=relevancy_agent, query=query)
)
question_relevancy_task = get_question_relevancy_task(TaskInput(agent=relevancy_agent, query=query))
research_approach_task = get_research_approach_creation_task(
TaskInput(
agent=research_agent,
query=query,
tools=[tavily_extractor_tool, tavily_search_tool],
)
)
search_query_task = get_search_query_generation_task(
TaskInput(agent=query_agent, query=query)
)
search_query_task = get_search_query_generation_task(TaskInput(agent=query_agent, query=query))
rag_retrieval_task = get_rag_retrieval_results_task(
TaskInput(
agent=retrieval_agent,
42 changes: 7 additions & 35 deletions app/crew/tasks.py
Original file line number Diff line number Diff line change
@@ -9,11 +9,7 @@

@traceable(run_type="task")
def get_question_relevancy_task(task_input: TaskInput) -> Task:
output_file = (
task_input.output_file
if task_input.output_file
else Path("out") / "question_relevancy.txt"
)
output_file = task_input.output_file if task_input.output_file else Path("out") / "question_relevancy.txt"
return Task(
agent=task_input.agent,
description=f"Evaluate if the question '{task_input.query.query}' is relevant for research. Consider factors such as clarity, specificity, research potential, and whether it is answerable through research. Flag questions that are too vague, nonsensical, or impossible to research effectively.{task_input.query.context_info}",
@@ -32,11 +28,7 @@ def get_question_relevancy_task(task_input: TaskInput) -> Task:

@traceable(run_type="task")
def get_research_approach_creation_task(task_input: TaskInput) -> Task:
output_file = (
task_input.output_file
if task_input.output_file
else Path("out") / "research_approach.txt"
)
output_file = task_input.output_file if task_input.output_file else Path("out") / "research_approach.txt"
return Task(
agent=task_input.agent,
description=f"Create a comprehensive research approach for the question: '{task_input.query.query}'. Outline the key areas to investigate, potential sources of information, and methodologies to employ. Consider different angles and perspectives that might provide valuable insights.{task_input.query.context_info}",
@@ -53,11 +45,7 @@ def get_research_approach_creation_task(task_input: TaskInput) -> Task:

@traceable(run_type="task")
def get_search_query_generation_task(task_input: TaskInput) -> Task:
output_file = (
task_input.output_file
if task_input.output_file
else Path("out") / "search_queries.txt"
)
output_file = task_input.output_file if task_input.output_file else Path("out") / "search_queries.txt"
return Task(
agent=task_input.agent,
description=f"Generate a diverse set of search queries related to the research question: '{task_input.query.query}'. Create at least 5 distinct search queries that will help gather comprehensive information. Queries should target different aspects of the question and use varying keywords to maximize relevant results.{task_input.query.context_info}",
@@ -74,11 +62,7 @@ def get_search_query_generation_task(task_input: TaskInput) -> Task:

@traceable(run_type="task")
def get_rag_retrieval_results_task(task_input: TaskInput) -> Task:
output_file = (
task_input.output_file
if task_input.output_file
else Path("out") / "rag_retrieval_results.txt"
)
output_file = task_input.output_file if task_input.output_file else Path("out") / "rag_retrieval_results.txt"
return Task(
agent=task_input.agent,
description=f"Using Retrieval Augmented Generation (RAG), retrieve relevant information from the knowledge base to answer the research question: '{task_input.query.query}'. Focus on finding high-quality, accurate information that directly addresses the question and provides context.{task_input.query.context_info}",
@@ -95,11 +79,7 @@ def get_rag_retrieval_results_task(task_input: TaskInput) -> Task:

@traceable(run_type="task")
def get_web_search_results_task(task_input: TaskInput) -> Task:
output_file = (
task_input.output_file
if task_input.output_file
else Path("out") / "web_search_results.txt"
)
output_file = task_input.output_file if task_input.output_file else Path("out") / "web_search_results.txt"
return Task(
agent=task_input.agent,
description=f"Conduct comprehensive web searches using the generated queries to find the most relevant and up-to-date information related to the research question: '{task_input.query.query.query}'. Focus on authoritative sources, recent publications, and diverse perspectives.{task_input.query.context_info}",
@@ -116,11 +96,7 @@ def get_web_search_results_task(task_input: TaskInput) -> Task:

@traceable(run_type="task")
def get_keep_relevant_data_task(task_input: TaskInput) -> Task:
output_file = (
task_input.output_file
if task_input.output_file
else Path("out") / "relevant_data.txt"
)
output_file = task_input.output_file if task_input.output_file else Path("out") / "relevant_data.txt"
return Task(
agent=task_input.agent,
description=f"Critically evaluate all gathered information (from RAG and web searches) based on its direct relevance to the research question: '{task_input.query.query.query}'. Apply a strict filter, discarding any information that is tangential, low-quality, or lacks credible sourcing. Retain only the most pertinent and verifiable data points.{task_input.query.context_info}",
@@ -137,11 +113,7 @@ def get_keep_relevant_data_task(task_input: TaskInput) -> Task:

@traceable(run_type="task")
def get_summarizing_task(task_input: TaskInput) -> Task:
output_file = (
task_input.output_file
if task_input.output_file
else Path("out") / "research_synthesis.txt"
)
output_file = task_input.output_file if task_input.output_file else Path("out") / "research_synthesis.txt"
return Task(
agent=task_input.agent,
description=f"Synthesize the curated, relevant information into a final, comprehensive, and coherent report answering the research question: '{task_input.query.query}'. Integrate the verified data points, ensuring a logical flow and addressing the core aspects of the query. *Crucially, every statement or piece of information presented must be accurately attributed to its source* based on the curated data provided in the context.{task_input.query.context_info}",
8 changes: 2 additions & 6 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -10,9 +10,7 @@ class AgentInput(BaseModel):
...,
description="The research query to be processed by the agent.",
)
tools: list[BaseTool] | None = Field(
None, description="List of tools available to the agent."
)
tools: list[BaseTool] | None = Field(None, description="List of tools available to the agent.")


class TaskInput(BaseModel):
@@ -24,9 +22,7 @@ class TaskInput(BaseModel):
...,
description="The research query to be processed by the task.",
)
tools: list[BaseTool] | None = Field(
None, description="List of tools available to the task."
)
tools: list[BaseTool] | None = Field(None, description="List of tools available to the task.")
context: list[Task] | None = Field(
None,
description="List of tasks that are contextually relevant to this task.",
36 changes: 8 additions & 28 deletions app/temp/qdrant_search_tool.py
Original file line number Diff line number Diff line change
@@ -54,17 +54,13 @@ class QdrantVectorSearchTool(BaseTool):
qdrant_api_key: Authentication key for Qdrant
"""

model_config: ClassVar[dict[str, bool]] = {
"arbitrary_types_allowed": True
} # Add ClassVar annotation
model_config: ClassVar[dict[str, bool]] = {"arbitrary_types_allowed": True} # Add ClassVar annotation
client: QdrantClient = None
async_client: AsyncQdrantClient = None
openai_client: Any = None # Added for lazy initialization
openai_async_client: Any = None # Added for lazy initialization
name: str = "QdrantVectorSearchTool"
description: str = (
"A tool to search the Qdrant database for relevant information on internal documents."
)
description: str = "A tool to search the Qdrant database for relevant information on internal documents."
args_schema: type[BaseModel] = QdrantToolSchema
query: str | None = None
filter_by: str | None = None
@@ -146,11 +142,7 @@ def _run(
# Create filter if filter parameters are provided
search_filter = None
if filter_by and filter_value:
search_filter = Filter(
must=[
FieldCondition(key=filter_by, match=MatchValue(value=filter_value))
]
)
search_filter = Filter(must=[FieldCondition(key=filter_by, match=MatchValue(value=filter_value))])

# Search in Qdrant using the built-in query method
query_vector = (
@@ -192,9 +184,7 @@ def _vectorize_query_sync(self, query: str, embedding_model: str) -> list[float]
from openai import Client

# Define error messages as constants
openai_api_key_not_set_error_msg = (
"OPENAI_API_KEY environment variable is not set."
)
openai_api_key_not_set_error_msg = "OPENAI_API_KEY environment variable is not set."
# Lazy initialization of the sync client
if not self.openai_client:
api_key = os.getenv("OPENAI_API_KEY")
@@ -240,17 +230,11 @@ async def _arun(
# Create filter if filter parameters are provided
search_filter = None
if filter_by and filter_value:
search_filter = Filter(
must=[
FieldCondition(key=filter_by, match=MatchValue(value=filter_value))
]
)
search_filter = Filter(must=[FieldCondition(key=filter_by, match=MatchValue(value=filter_value))])

# Search in Qdrant using the built-in query method
query_vector = (
await self._vectorize_query_async(
query, embedding_model="text-embedding-3-large"
)
await self._vectorize_query_async(query, embedding_model="text-embedding-3-large")
if not self.custom_embedding_fn
else self.custom_embedding_fn(query)
)
@@ -275,9 +259,7 @@ async def _arun(

return json.dumps(results, indent=2)

async def _vectorize_query_async(
self, query: str, embedding_model: str
) -> list[float]:
async def _vectorize_query_async(self, query: str, embedding_model: str) -> list[float]:
"""Default async vectorization function with openai.

Args:
@@ -290,9 +272,7 @@ async def _vectorize_query_async(
from openai import AsyncClient

# Define error messages as constants
openai_api_key_not_set_error_msg = (
"OPENAI_API_KEY environment variable is not set."
)
openai_api_key_not_set_error_msg = "OPENAI_API_KEY environment variable is not set."
# Lazy initialization of the async client
if not self.openai_async_client:
api_key = os.getenv("OPENAI_API_KEY")