Skip to content
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

fix(solver): add cacth except obj in main solver #306

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions kag/solver/execute/sub_query_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import logging

from tenacity import retry, stop_after_attempt

from kag.interface import KagBaseModule

from kag.solver.utils import init_prompt_with_fallback
Expand All @@ -25,6 +28,7 @@ def __init__(self, **kwargs):
"solve_question_without_spo", self.biz_scene
)

@retry(stop=stop_after_attempt(3))
def generate_sub_answer(
self, question: str, knowledge_graph: [], docs: [], history=[]
):
Expand Down
17 changes: 14 additions & 3 deletions kag/solver/main_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied.
import copy
import logging

from kag.solver.logic.solver_pipeline import SolverPipeline
from kag.solver.tools.info_processor import ReporterIntermediateProcessTool

from kag.common.conf import KAG_CONFIG, KAG_PROJECT_CONF

logger = logging.getLogger()

class SolverMain:
def invoke(
Expand Down Expand Up @@ -91,10 +93,19 @@ def invoke(
KAG_CONFIG.all_config.get("lf_solver_pipeline", default_pipeline_config)
)
resp = SolverPipeline.from_config(conf)
answer, trace_log = resp.run(query, report_tool=report_tool)
print(trace_log)
try:
answer, trace_log = resp.run(query, report_tool=report_tool)
state = ReporterIntermediateProcessTool.STATE.FINISH
logger.info(f"{query} answer={answer} tracelog={trace_log}")
except Exception as e:
if KAG_PROJECT_CONF.language == 'en':
answer = f"Sorry, An exception occurred while processing query: {query}. Error: {str(e)}, please retry."
else:
answer = f"抱歉,处理查询 {query} 时发生异常。错误:{str(e)}, 请重试。"
state = ReporterIntermediateProcessTool.STATE.ERROR
logger.warning(f"An exception occurred while processing query: {query}. Error: {str(e)}", exc_info=True)
report_tool.report_final_answer(
query, answer, ReporterIntermediateProcessTool.STATE.FINISH
query, answer, state
)
return answer

Expand Down
3 changes: 3 additions & 0 deletions kag/solver/plan/default_lf_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import logging
from typing import List

from tenacity import retry, stop_after_attempt

from kag.common.conf import KAG_PROJECT_CONF
from kag.interface import LLMClient, VectorizeModelABC
from kag.interface import PromptABC
Expand Down Expand Up @@ -100,6 +102,7 @@ def _parse_lf(self, question, sub_querys, logic_forms) -> List[LFPlan]:
)
return self._split_sub_query(parsed_logic_nodes)

@retry(stop=stop_after_attempt(3))
def generate_logic_form(self, question: str):
return self.llm_module.invoke(
{"question": question},
Expand Down
Loading