From e5fa411092dde1a0a39eda6c16298682bf5b11fa Mon Sep 17 00:00:00 2001 From: joachim-danswer Date: Thu, 23 Jan 2025 15:18:43 -0800 Subject: [PATCH] EL comments addressed --- .../main/nodes/answer_comparison.py | 7 +- .../main/nodes/generate_initial_answer.py | 1 - .../agent_search/deep_search_a/main/states.py | 75 +++++-------------- .../shared_graph_utils/prompts.py | 6 +- 4 files changed, 25 insertions(+), 64 deletions(-) diff --git a/backend/onyx/agents/agent_search/deep_search_a/main/nodes/answer_comparison.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/answer_comparison.py index b899f759b..bf5f0d429 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main/nodes/answer_comparison.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/answer_comparison.py @@ -35,10 +35,9 @@ def answer_comparison(state: MainState, config: RunnableConfig) -> AnswerCompari # no need to stream this resp = model.invoke(msg) - if isinstance(resp.content, str) and "yes" in resp.content.lower(): - refined_answer_improvement = True - else: - refined_answer_improvement = False + refined_answer_improvement = ( + isinstance(resp.content, str) and "yes" in resp.content.lower() + ) dispatch_custom_event( "refined_answer_improvement", diff --git a/backend/onyx/agents/agent_search/deep_search_a/main/nodes/generate_initial_answer.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/generate_initial_answer.py index 06ed14029..0eb033240 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main/nodes/generate_initial_answer.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/generate_initial_answer.py @@ -66,7 +66,6 @@ def generate_initial_answer( history = build_history_prompt(agent_a_config.prompt_builder) date_str = get_today_prompt() - # sub_question_docs = state.documents sub_question_docs = state.context_documents all_original_question_documents = state.all_original_question_documents diff --git a/backend/onyx/agents/agent_search/deep_search_a/main/states.py b/backend/onyx/agents/agent_search/deep_search_a/main/states.py index 0dfc8773c..c44ad4224 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main/states.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/states.py @@ -48,43 +48,25 @@ class RefinedAgentEndStats(BaseModel): agent_refined_metrics: AgentRefinedMetrics = AgentRefinedMetrics() -class BaseDecompUpdateBase(BaseModel): +class BaseDecompUpdate(RefinedAgentStartStats, RefinedAgentEndStats): agent_start_time: datetime = datetime.now() initial_decomp_questions: list[str] = [] -class AnswerComparisonBase(BaseModel): +class AnswerComparison(LoggerUpdate): refined_answer_improvement: bool = False -class AnswerComparison(AnswerComparisonBase, LoggerUpdate): - pass - - -class RoutingDecisionBase(BaseModel): +class RoutingDecision(LoggerUpdate): routing: str = "" sample_doc_str: str = "" -class RoutingDecision(RoutingDecisionBase, LoggerUpdate): - pass - - -class LoggingUpdate(BaseModel): - log_messages: list[str] = [] - - -class BaseDecompUpdate( - RefinedAgentStartStats, RefinedAgentEndStats, BaseDecompUpdateBase -): - pass - - class InitialAnswerBASEUpdate(BaseModel): initial_base_answer: str = "" -class InitialAnswerUpdateBase(BaseModel): +class InitialAnswerUpdate(LoggerUpdate): initial_answer: str = "" initial_agent_stats: InitialAgentResultStats | None = None generated_sub_questions: list[str] = [] @@ -92,29 +74,21 @@ class InitialAnswerUpdateBase(BaseModel): agent_base_metrics: AgentBaseMetrics | None = None -class InitialAnswerUpdate(InitialAnswerUpdateBase, LoggerUpdate): - pass - - -class RefinedAnswerUpdateBase(BaseModel): +class RefinedAnswerUpdate(RefinedAgentEndStats): refined_answer: str = "" refined_agent_stats: RefinedAgentStats | None = None refined_answer_quality: bool = False -class RefinedAnswerUpdate(RefinedAgentEndStats, RefinedAnswerUpdateBase): - pass - - -class InitialAnswerQualityUpdate(LoggingUpdate): +class InitialAnswerQualityUpdate(LoggerUpdate): initial_answer_quality: bool = False -class RequireRefinedAnswerUpdate(LoggingUpdate): +class RequireRefinedAnswerUpdate(LoggerUpdate): require_refined_answer: bool = True -class DecompAnswersUpdate(LoggingUpdate): +class DecompAnswersUpdate(LoggerUpdate): documents: Annotated[list[InferenceSection], dedup_inference_sections] = [] context_documents: Annotated[list[InferenceSection], dedup_inference_sections] = [] decomp_answer_results: Annotated[ @@ -122,12 +96,12 @@ class DecompAnswersUpdate(LoggingUpdate): ] = [] -class FollowUpDecompAnswersUpdate(LoggingUpdate): +class FollowUpDecompAnswersUpdate(LoggerUpdate): refined_documents: Annotated[list[InferenceSection], dedup_inference_sections] = [] refined_decomp_answer_results: Annotated[list[QuestionAnswerResults], add] = [] -class ExpandedRetrievalUpdate(LoggingUpdate): +class ExpandedRetrievalUpdate(LoggerUpdate): all_original_question_documents: Annotated[ list[InferenceSection], dedup_inference_sections ] @@ -135,26 +109,16 @@ class ExpandedRetrievalUpdate(LoggingUpdate): original_question_retrieval_stats: AgentChunkStats = AgentChunkStats() -class EntityTermExtractionUpdateBase(LoggingUpdate): +class EntityTermExtractionUpdate(LoggerUpdate): entity_retlation_term_extractions: EntityRelationshipTermExtraction = ( EntityRelationshipTermExtraction() ) -class EntityTermExtractionUpdate(EntityTermExtractionUpdateBase, LoggerUpdate): - pass - - -class FollowUpSubQuestionsUpdateBase(BaseModel): +class FollowUpSubQuestionsUpdate(RefinedAgentStartStats): refined_sub_questions: dict[int, FollowUpSubQuestion] = {} -class FollowUpSubQuestionsUpdate( - RefinedAgentStartStats, FollowUpSubQuestionsUpdateBase -): - pass - - ## Graph Input State ## Graph Input State @@ -169,22 +133,21 @@ class MainInput(CoreState): class MainState( # This includes the core state MainInput, - LoggerUpdate, - BaseDecompUpdateBase, - InitialAnswerUpdateBase, + BaseDecompUpdate, + InitialAnswerUpdate, InitialAnswerBASEUpdate, DecompAnswersUpdate, ExpandedRetrievalUpdate, - EntityTermExtractionUpdateBase, + EntityTermExtractionUpdate, InitialAnswerQualityUpdate, RequireRefinedAnswerUpdate, - FollowUpSubQuestionsUpdateBase, + FollowUpSubQuestionsUpdate, FollowUpDecompAnswersUpdate, - RefinedAnswerUpdateBase, + RefinedAnswerUpdate, RefinedAgentStartStats, RefinedAgentEndStats, - RoutingDecisionBase, - AnswerComparisonBase, + RoutingDecision, + AnswerComparison, ): # expanded_retrieval_result: Annotated[list[ExpandedRetrievalResult], add] base_raw_search_result: Annotated[list[ExpandedRetrievalResult], add] diff --git a/backend/onyx/agents/agent_search/shared_graph_utils/prompts.py b/backend/onyx/agents/agent_search/shared_graph_utils/prompts.py index c57f9569e..159cf92e5 100644 --- a/backend/onyx/agents/agent_search/shared_graph_utils/prompts.py +++ b/backend/onyx/agents/agent_search/shared_graph_utils/prompts.py @@ -724,7 +724,7 @@ is close to the information it supports. If you have multiple citations that sup as [[D1]]()[[D3]](), or [[D2]]()[[D4]](), etc. Feel free to also cite sub-questions in addition to documents, but make sure that you have documents cited with the sub-question citation. If you want to cite both a document and a sub-question, please use [[D1]]()[[Q3]](), or [[D2]]()[[D7]]()[[Q4]](), etc. -Again, please do NEVER cite sub-questions without a document citation! +Again, please NEVER cite sub-questions without a document citation! Proper citations are very important for the user! IMPORTANT RULES: @@ -818,7 +818,7 @@ Please provide inline citations to documents in the format [[D1]](), [[D2]](), [ citations, please cite for example as [[D1]]()[[D3]](), or [[D2]]()[[D4]](), etc. Feel free to also cite sub-questions in addition to documents, but make sure that you have documents cited with the sub-question citation. If you want to cite both a document and a sub-question, please use [[D1]]()[[Q3]](), or [[D2]]()[[D7]]()[[Q4]](), etc. -Again, please do NEVER cite sub-questions without a document citation! +Again, please NEVER cite sub-questions without a document citation! Proper citations are very important for the user!\n\n {history} @@ -969,7 +969,7 @@ the refined answer is substantially better than the initial answer. Better could Here is the refined answer: {refined_answer} - With these criteriain mind, is the refined answer substantially better than the initial answer? + With these criteria in mind, is the refined answer substantially better than the initial answer? Please answer with a simple 'yes' or 'no'. """