Spaces:
Sleeping
Sleeping
Commit
·
8496edd
1
Parent(s):
55cba78
upload
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- Dockerfile +25 -0
- core/.DS_Store +0 -0
- core/agent/__init__.py +0 -0
- core/agent/base_agent.py +7 -0
- core/agent/coordinator.py +74 -0
- core/agent/create_charts.py +19 -0
- core/agent/data_description.py +11 -0
- core/agent/method_ranking.py +125 -0
- core/agent/model_selection.py +16 -0
- core/agent/parse_problem.py +0 -0
- core/agent/problem_analysis.py +28 -0
- core/agent/problem_modeling.py +29 -0
- core/agent/task copy.py +64 -0
- core/agent/task.py +251 -0
- core/agent/task_decompse.py +47 -0
- core/input/__init__.py +0 -0
- core/input/problem.py +31 -0
- core/input/test_middle_result.py +212 -0
- core/llm/__init__.py +0 -0
- core/llm/llm.py +122 -0
- core/prompt/.DS_Store +0 -0
- core/prompt/__init__.py +0 -0
- core/prompt/constants.py +271 -0
- core/prompt/template.py +1106 -0
- core/run_batch.py +221 -0
- core/run_batch_wo_coo.py +176 -0
- core/run_batch_wo_rag.py +225 -0
- core/test.py +56 -0
- core/test2.py +59 -0
- core/utils/convert_format.py +104 -0
- core/utils/decompose_analysis.py +93 -0
- core/utils/embedding.py +77 -0
- core/utils/generate_paper.py +736 -0
- core/utils/generate_problem.py +45 -0
- core/utils/problem2.py +23 -0
- core/utils/utils.py +161 -0
- core/workflow/__init__.py +0 -0
- core/workflow/solution.py +14 -0
- data/.DS_Store +3 -0
- data/actor_data/.DS_Store +3 -0
- data/actor_data/docs/.DS_Store +3 -0
- data/actor_data/input/.DS_Store +3 -0
- data/actor_data/input/code_template/main.py +3 -0
- data/actor_data/input/code_template/main1.py +3 -0
- data/actor_data/input/code_template/main10.py +3 -0
- data/actor_data/input/code_template/main2.py +3 -0
- data/actor_data/input/code_template/main3.py +3 -0
- data/actor_data/input/code_template/main4.py +3 -0
- data/actor_data/input/code_template/main5.py +3 -0
.gitattributes
CHANGED
|
@@ -33,4 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 36 |
data/** filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
data/ filter=lfs diff=lfs merge=lfs -text
|
| 37 |
data/** filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM ubuntu:24.04
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY . /app
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
|
| 8 |
+
|
| 9 |
+
# Set up a new user named "user" with user ID 1000
|
| 10 |
+
RUN useradd -m -u 1000 user
|
| 11 |
+
|
| 12 |
+
# Switch to the "user" user
|
| 13 |
+
USER user
|
| 14 |
+
|
| 15 |
+
# Set home to the user's home directory
|
| 16 |
+
ENV HOME=/home/user \
|
| 17 |
+
PATH=/home/user/.local/bin:$PATH
|
| 18 |
+
|
| 19 |
+
# Set the working directory to the user's home directory
|
| 20 |
+
WORKDIR $HOME/app
|
| 21 |
+
|
| 22 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
| 23 |
+
COPY --chown=user . $HOME/app
|
| 24 |
+
|
| 25 |
+
CMD ["streamlit", "run", "app.py", "--server.port", "8200"]
|
core/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
core/agent/__init__.py
ADDED
|
File without changes
|
core/agent/base_agent.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from abc import ABC, abstractmethod
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class BaseAgent(ABC):
|
| 5 |
+
|
| 6 |
+
def __init__(self, llm):
|
| 7 |
+
self.llm = llm
|
core/agent/coordinator.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections import defaultdict, deque
|
| 2 |
+
from prompt.template import TASK_DEPENDENCY_ANALYSIS_WITH_CODE_PROMPT, TASK_DEPENDENCY_ANALYSIS_PROMPT, DAG_CONSTRUCTION_PROMPT, CODE_STRUCTURE_PROMPT
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
class Coordinator:
|
| 8 |
+
def __init__(self, llm):
|
| 9 |
+
self.llm = llm
|
| 10 |
+
self.memory = {}
|
| 11 |
+
self.code_memory = {}
|
| 12 |
+
|
| 13 |
+
def compute_dag_order(self, graph):
|
| 14 |
+
"""
|
| 15 |
+
计算DAG的拓扑排序(计算顺序)。
|
| 16 |
+
:param graph: 以邻接表形式表示的DAG,格式为 {节点: [该节点依赖的其他节点]}。
|
| 17 |
+
:return: 一个表示计算顺序的列表。
|
| 18 |
+
"""
|
| 19 |
+
# 计算入度
|
| 20 |
+
in_degree = {node: 0 for node in graph}
|
| 21 |
+
for node in graph:
|
| 22 |
+
in_degree[node] += len(graph[node])
|
| 23 |
+
|
| 24 |
+
# 找到所有入度为0的节点(可以作为计算的起点)
|
| 25 |
+
queue = deque([node for node in in_degree if in_degree[node] == 0])
|
| 26 |
+
order = []
|
| 27 |
+
|
| 28 |
+
while queue:
|
| 29 |
+
node = queue.popleft()
|
| 30 |
+
order.append(node)
|
| 31 |
+
|
| 32 |
+
# 遍历所有节点,找到依赖当前节点的节点,减少其入度
|
| 33 |
+
for neighbor in graph:
|
| 34 |
+
if node in graph[neighbor]:
|
| 35 |
+
in_degree[neighbor] -= 1
|
| 36 |
+
if in_degree[neighbor] == 0:
|
| 37 |
+
queue.append(neighbor)
|
| 38 |
+
|
| 39 |
+
# 检查是否存在环(如果排序的节点数小于总节点数,则说明存在环)
|
| 40 |
+
if len(order) != len(graph):
|
| 41 |
+
raise ValueError("Graph contains a cycle!")
|
| 42 |
+
|
| 43 |
+
return order
|
| 44 |
+
|
| 45 |
+
def analyze(self, tasknum: int, modeling_problem: str, problem_analysis: str, modeling_solution: str, task_descriptions: str, with_code: bool):
|
| 46 |
+
if with_code:
|
| 47 |
+
prompt = TASK_DEPENDENCY_ANALYSIS_WITH_CODE_PROMPT.format(tasknum=tasknum, modeling_problem=modeling_problem, problem_analysis=problem_analysis, modeling_solution=modeling_solution, task_descriptions=task_descriptions).strip()
|
| 48 |
+
else:
|
| 49 |
+
prompt = TASK_DEPENDENCY_ANALYSIS_PROMPT.format(tasknum=tasknum, modeling_problem=modeling_problem, problem_analysis=problem_analysis, modeling_solution=modeling_solution, task_descriptions=task_descriptions).strip()
|
| 50 |
+
return self.llm.generate(prompt)
|
| 51 |
+
|
| 52 |
+
def dag_construction(self, tasknum: int, modeling_problem: str, problem_analysis: str, modeling_solution: str, task_descriptions: str, task_dependency_analysis: str):
|
| 53 |
+
prompt = DAG_CONSTRUCTION_PROMPT.format(tasknum=tasknum, modeling_problem=modeling_problem, problem_analysis=problem_analysis, modeling_solution=modeling_solution, task_descriptions=task_descriptions, task_dependency_analysis=task_dependency_analysis).strip()
|
| 54 |
+
return self.llm.generate(prompt)
|
| 55 |
+
|
| 56 |
+
def analyze_dependencies(self, modeling_problem: str, problem_analysis: str, modeling_solution: str, task_descriptions: str, with_code: bool):
|
| 57 |
+
task_dependency_analysis = self.analyze(len(task_descriptions), modeling_problem, problem_analysis, modeling_solution, task_descriptions, with_code)
|
| 58 |
+
self.task_dependency_analysis = task_dependency_analysis.split('\n\n')
|
| 59 |
+
count = 0
|
| 60 |
+
for i in range(5):
|
| 61 |
+
try:
|
| 62 |
+
dependency_DAG = self.dag_construction(len(task_descriptions), modeling_problem, problem_analysis, modeling_solution, task_descriptions, task_dependency_analysis)
|
| 63 |
+
dependency_DAG_string = dependency_DAG.strip('```json\n').strip('```')
|
| 64 |
+
self.DAG = json.loads(dependency_DAG_string)
|
| 65 |
+
break
|
| 66 |
+
except:
|
| 67 |
+
continue
|
| 68 |
+
if count == 5:
|
| 69 |
+
sys.exit("Fail at analyze_dependencies")
|
| 70 |
+
order = self.compute_dag_order(self.DAG)
|
| 71 |
+
|
| 72 |
+
return order
|
| 73 |
+
|
| 74 |
+
|
core/agent/create_charts.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .base_agent import BaseAgent
|
| 2 |
+
from prompt.template import CREATE_CHART_PROMPT
|
| 3 |
+
|
| 4 |
+
class Chart(BaseAgent):
|
| 5 |
+
def __init__(self, llm):
|
| 6 |
+
super().__init__(llm)
|
| 7 |
+
|
| 8 |
+
def create_single_chart(self, paper_content: str, existing_charts: str, user_prompt: str=''):
|
| 9 |
+
prompt = CREATE_CHART_PROMPT.format(paper_content=paper_content, existing_charts=existing_charts, user_prompt=user_prompt)
|
| 10 |
+
return self.llm.generate(prompt)
|
| 11 |
+
|
| 12 |
+
def create_charts(self, paper_content: str, chart_num: int, user_prompt: str=''):
|
| 13 |
+
existing_charts = ''
|
| 14 |
+
charts = []
|
| 15 |
+
for i in range(chart_num):
|
| 16 |
+
chart = self.create_single_chart(paper_content, existing_charts, user_prompt)
|
| 17 |
+
charts.append(chart)
|
| 18 |
+
existing_charts = '\n---\n'.join(charts)
|
| 19 |
+
return charts
|
core/agent/data_description.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .base_agent import BaseAgent
|
| 2 |
+
from prompt.template import DATA_DESCRIPTION_PROMPT
|
| 3 |
+
|
| 4 |
+
class DataDescription(BaseAgent):
|
| 5 |
+
def __init__(self, llm):
|
| 6 |
+
super().__init__(llm)
|
| 7 |
+
|
| 8 |
+
def summary(self, data_description: str):
|
| 9 |
+
prompt = DATA_DESCRIPTION_PROMPT.format(data_description=data_description)
|
| 10 |
+
return self.llm.generate(prompt)
|
| 11 |
+
|
core/agent/method_ranking.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import List
|
| 4 |
+
from functools import partial
|
| 5 |
+
from .base_agent import BaseAgent
|
| 6 |
+
from prompt.template import METHOD_CRITIQUE_PROMPT
|
| 7 |
+
from utils.convert_format import markdown_to_json_method
|
| 8 |
+
from utils.utils import parse_llm_output_to_json
|
| 9 |
+
from utils.embedding import EmbeddingScorer
|
| 10 |
+
|
| 11 |
+
import json
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class MethodScorer:
|
| 16 |
+
|
| 17 |
+
def __init__(self, score_func, parent_weight=0.5, child_weight=0.5):
|
| 18 |
+
self.parent_weight = parent_weight
|
| 19 |
+
self.child_weight = child_weight
|
| 20 |
+
self.score_func = score_func
|
| 21 |
+
self.leaves = []
|
| 22 |
+
|
| 23 |
+
def process(self, data):
|
| 24 |
+
self.leaves = []
|
| 25 |
+
for root_node in data:
|
| 26 |
+
self._process_node(root_node, parent_scores=[])
|
| 27 |
+
for root_node in data:
|
| 28 |
+
self._collect_leaves(root_node)
|
| 29 |
+
return self.leaves
|
| 30 |
+
|
| 31 |
+
def _process_node(self, node, parent_scores):
|
| 32 |
+
if 'children' in node:
|
| 33 |
+
children = node.get('children', [])
|
| 34 |
+
if children:
|
| 35 |
+
first_child = children[0]
|
| 36 |
+
if 'method_class' in first_child:
|
| 37 |
+
input_for_llm = [{"method": child["method_class"], "description": child.get("description", "")} for child in children]
|
| 38 |
+
llm_result = self.score_func(input_for_llm)
|
| 39 |
+
for idx, child in enumerate(children):
|
| 40 |
+
if idx < len(llm_result):
|
| 41 |
+
child['score'] = llm_result[idx]['score']
|
| 42 |
+
else:
|
| 43 |
+
child['score'] = 0
|
| 44 |
+
current_score = node.get('score')
|
| 45 |
+
new_parent = parent_scores.copy()
|
| 46 |
+
if current_score is not None:
|
| 47 |
+
new_parent.append(current_score)
|
| 48 |
+
for child in children:
|
| 49 |
+
self._process_node(child, new_parent)
|
| 50 |
+
else:
|
| 51 |
+
input_for_llm = [{"method": child["method"], "description": child.get("description", "")} for child in children]
|
| 52 |
+
llm_result = self.score_func(input_for_llm)
|
| 53 |
+
for idx, child in enumerate(children):
|
| 54 |
+
if idx < len(llm_result):
|
| 55 |
+
child_score = llm_result[idx]['score']
|
| 56 |
+
else:
|
| 57 |
+
child_score = 0
|
| 58 |
+
child['score'] = child_score
|
| 59 |
+
parent_avg = sum(parent_scores) / len(parent_scores) if parent_scores else 0
|
| 60 |
+
final_score = parent_avg * self.parent_weight + child_score * self.child_weight
|
| 61 |
+
child['final_score'] = final_score
|
| 62 |
+
|
| 63 |
+
def _collect_leaves(self, node):
|
| 64 |
+
if 'children' in node:
|
| 65 |
+
for child in node['children']:
|
| 66 |
+
self._collect_leaves(child)
|
| 67 |
+
else:
|
| 68 |
+
if 'final_score' in node:
|
| 69 |
+
self.leaves.append({
|
| 70 |
+
"method": node["method"],
|
| 71 |
+
"description": node.get("description", ""),
|
| 72 |
+
"score": node['final_score']
|
| 73 |
+
})
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class MethodRanking(BaseAgent):
|
| 78 |
+
def __init__(self, llm, rag=True):
|
| 79 |
+
super().__init__(llm)
|
| 80 |
+
self.rag = rag
|
| 81 |
+
self.embedding_scorer = EmbeddingScorer()
|
| 82 |
+
current_file = Path(__file__).resolve()
|
| 83 |
+
json_path = current_file.parent.parent.parent / 'data/actor_data/docs/method_en_v1.json'
|
| 84 |
+
md_path = current_file.parent.parent.parent / 'data/actor_data/docs/method_en_v1.md'
|
| 85 |
+
|
| 86 |
+
with open(str(md_path), "r", encoding="utf-8") as f:
|
| 87 |
+
self.markdown_text = f.read()
|
| 88 |
+
self.method_tree = markdown_to_json_method(self.markdown_text)
|
| 89 |
+
with open(json_path, "w+", encoding="utf-8") as f:
|
| 90 |
+
json.dump(self.method_tree, f, ensure_ascii=False, indent=4)
|
| 91 |
+
|
| 92 |
+
def llm_score_method(self, problem_description: str, methods: List[dict]):
|
| 93 |
+
methods_str = '\n'.join([f"{i+1}. {method['method']} {method.get('description', '')}" for i, method in enumerate(methods)])
|
| 94 |
+
prompt = METHOD_CRITIQUE_PROMPT.format(problem_description=problem_description, methods=methods_str)
|
| 95 |
+
answer = self.llm.generate(prompt)
|
| 96 |
+
method_scores = parse_llm_output_to_json(answer).get('methods', [])
|
| 97 |
+
method_scores = sorted(method_scores, key=lambda x: x['method_index'])
|
| 98 |
+
for method in method_scores:
|
| 99 |
+
method['score'] = sum(method['scores'].values()) / len(method['scores'])
|
| 100 |
+
# print(method_scores)
|
| 101 |
+
return method_scores
|
| 102 |
+
|
| 103 |
+
def format_methods(self, methods: List[str]):
|
| 104 |
+
return '\n'.join([f"**{method['method']}:** {method['description']}" for method in methods])
|
| 105 |
+
|
| 106 |
+
def top_methods(self, problem_description: str, top_k: int=6, method: str='embedding'):
|
| 107 |
+
if self.rag:
|
| 108 |
+
if method == 'embedding':
|
| 109 |
+
score_func = partial(self.embedding_scorer.score_method, problem_description)
|
| 110 |
+
else:
|
| 111 |
+
score_func = partial(self.llm_score_method, problem_description)
|
| 112 |
+
method_scores = MethodScorer(score_func).process(self.method_tree)
|
| 113 |
+
method_scores.sort(key=lambda x: x['score'], reverse=True)
|
| 114 |
+
return self.format_methods(method_scores[:top_k])
|
| 115 |
+
else:
|
| 116 |
+
return self.markdown_text
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
if __name__ == "__main__":
|
| 120 |
+
from input.test_middle_result import problem_str
|
| 121 |
+
from llm.llm import LLM
|
| 122 |
+
llm = LLM('deepseek-chat')
|
| 123 |
+
# print(llm.generate('Hello, how are you?'))
|
| 124 |
+
mr = MethodRanking(llm)
|
| 125 |
+
# print(mr.top_methods(problem_str, top_k=6))
|
core/agent/model_selection.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .base_agent import BaseAgent
|
| 2 |
+
from prompt.template import MODEL_SELECTION_PROMPT
|
| 3 |
+
from prompt.constants import modeling_methods
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class ModelSelection(BaseAgent):
|
| 7 |
+
def __init__(self, llm):
|
| 8 |
+
super().__init__(llm)
|
| 9 |
+
|
| 10 |
+
def select_models(self, modeling_problem: str):
|
| 11 |
+
prompt = MODEL_SELECTION_PROMPT.format(modeling_methods=modeling_methods, modeling_problem=modeling_problem)
|
| 12 |
+
answer = self.llm.generate(prompt)
|
| 13 |
+
selected_models = answer.split('Conclusion:')[-1]
|
| 14 |
+
return selected_models
|
| 15 |
+
|
| 16 |
+
|
core/agent/parse_problem.py
ADDED
|
File without changes
|
core/agent/problem_analysis.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .base_agent import BaseAgent
|
| 2 |
+
from prompt.template import PROBLEM_ANALYSIS_PROMPT, PROBLEM_ANALYSIS_CRITIQUE_PROMPT, PROBLEM_ANALYSIS_IMPROVEMENT_PROMPT
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class ProblemAnalysis(BaseAgent):
|
| 6 |
+
def __init__(self, llm):
|
| 7 |
+
super().__init__(llm)
|
| 8 |
+
|
| 9 |
+
def analysis_actor(self, modeling_problem: str, user_prompt: str=''):
|
| 10 |
+
prompt = PROBLEM_ANALYSIS_PROMPT.format(modeling_problem=modeling_problem, user_prompt=user_prompt).strip()
|
| 11 |
+
return self.llm.generate(prompt)
|
| 12 |
+
|
| 13 |
+
def analysis_critic(self, modeling_problem: str, problem_analysis: str):
|
| 14 |
+
prompt = PROBLEM_ANALYSIS_CRITIQUE_PROMPT.format(modeling_problem=modeling_problem, problem_analysis=problem_analysis).strip()
|
| 15 |
+
return self.llm.generate(prompt)
|
| 16 |
+
|
| 17 |
+
def analysis_improvement(self, modeling_problem: str, problem_analysis: str, problem_analysis_critique: str, user_prompt: str=''):
|
| 18 |
+
prompt = PROBLEM_ANALYSIS_IMPROVEMENT_PROMPT.format(modeling_problem=modeling_problem, problem_analysis=problem_analysis, problem_analysis_critique=problem_analysis_critique, user_prompt=user_prompt).strip()
|
| 19 |
+
return self.llm.generate(prompt)
|
| 20 |
+
|
| 21 |
+
def analysis(self, modeling_problem: str, round: int = 3, user_prompt: str = ''):
|
| 22 |
+
problem_analysis = self.analysis_actor(modeling_problem, user_prompt)
|
| 23 |
+
for i in range(round):
|
| 24 |
+
print(f'Problem Analysis Round {i+1}')
|
| 25 |
+
problem_analysis_critique = self.analysis_critic(modeling_problem, problem_analysis)
|
| 26 |
+
problem_analysis_improvement = self.analysis_improvement(modeling_problem, problem_analysis, problem_analysis_critique, user_prompt)
|
| 27 |
+
problem_analysis = problem_analysis_improvement
|
| 28 |
+
return problem_analysis
|
core/agent/problem_modeling.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .base_agent import BaseAgent
|
| 2 |
+
from prompt.template import PROBLEM_MODELING_PROMPT, PROBLEM_MODELING_CRITIQUE_PROMPT, PROBLEM_MODELING_IMPROVEMENT_PROMPT
|
| 3 |
+
# from prompt.constants import modeling_methods
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class ProblemModeling(BaseAgent):
|
| 7 |
+
def __init__(self, llm):
|
| 8 |
+
super().__init__(llm)
|
| 9 |
+
|
| 10 |
+
def modeling_actor(self, modeling_problem: str, problem_analysis: str, modeling_methods: str, user_prompt: str=''):
|
| 11 |
+
prompt = PROBLEM_MODELING_PROMPT.format(modeling_methods=modeling_methods, modeling_problem=modeling_problem, problem_analysis=problem_analysis, user_prompt=user_prompt).strip()
|
| 12 |
+
return self.llm.generate(prompt)
|
| 13 |
+
|
| 14 |
+
def modeling_critic(self, modeling_problem: str, problem_analysis: str, modeling_solution: str):
|
| 15 |
+
prompt = PROBLEM_MODELING_CRITIQUE_PROMPT.format(modeling_problem=modeling_problem, problem_analysis=problem_analysis, modeling_solution=modeling_solution).strip()
|
| 16 |
+
return self.llm.generate(prompt)
|
| 17 |
+
|
| 18 |
+
def modeling_improvement(self, modeling_problem: str, problem_analysis: str, modeling_solution: str, modeling_solution_critique: str, user_prompt: str=''):
|
| 19 |
+
prompt = PROBLEM_MODELING_IMPROVEMENT_PROMPT.format(modeling_problem=modeling_problem, problem_analysis=problem_analysis, modeling_solution=modeling_solution, modeling_solution_critique=modeling_solution_critique, user_prompt=user_prompt).strip()
|
| 20 |
+
return self.llm.generate(prompt)
|
| 21 |
+
|
| 22 |
+
def modeling(self, modeling_problem: str, problem_analysis: str, modeling_methods: str, round: int = 3, user_prompt: str = ''):
|
| 23 |
+
modeling_solution = self.modeling_actor(modeling_problem, problem_analysis, modeling_methods, user_prompt)
|
| 24 |
+
for i in range(round):
|
| 25 |
+
print(f'Problem Modeling Round {i+1}')
|
| 26 |
+
modeling_solution_critique = self.modeling_critic(modeling_problem, problem_analysis, modeling_solution)
|
| 27 |
+
modeling_solution_improvement = self.modeling_improvement(modeling_problem, problem_analysis, modeling_solution, modeling_solution_critique, user_prompt)
|
| 28 |
+
modeling_solution = modeling_solution_improvement
|
| 29 |
+
return modeling_solution
|
core/agent/task copy.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .base_agent import BaseAgent
|
| 2 |
+
from prompt.constants import modeling_methods
|
| 3 |
+
from prompt.template import (TASK_ANALYSIS_PROMPT, TASK_RESULT_PROMPT, TASK_ANSWER_PROMPT,
|
| 4 |
+
TASK_FORMULAS_PROMPT, TASK_FORMULAS_CRITIQUE_PROMPT, TASK_FORMULAS_IMPROVEMENT_PROMPT,
|
| 5 |
+
TASK_MODELING_PROMPT, TASK_MODELING_CRITIQUE_PROMPT, TASK_MODELING_IMPROVEMENT_PROMPT)
|
| 6 |
+
|
| 7 |
+
class Task(BaseAgent):
|
| 8 |
+
def __init__(self, llm):
|
| 9 |
+
super().__init__(llm)
|
| 10 |
+
|
| 11 |
+
def analysis(self, task_description: str, user_prompt: str = ''):
|
| 12 |
+
prompt = TASK_ANALYSIS_PROMPT.format(task_description=task_description, user_prompt=user_prompt).strip()
|
| 13 |
+
return self.llm.generate(prompt)
|
| 14 |
+
|
| 15 |
+
def formulas_actor(self, data_summary: str, task_description: str, task_analysis: str, user_prompt: str = ''):
|
| 16 |
+
prompt = TASK_FORMULAS_PROMPT.format(data_summary=data_summary, task_description=task_description, task_analysis=task_analysis, modeling_methods=modeling_methods, user_prompt=user_prompt).strip()
|
| 17 |
+
return self.llm.generate(prompt)
|
| 18 |
+
|
| 19 |
+
def formulas_critic(self, data_summary: str, task_description: str, task_analysis: str, modeling_formulas: str):
|
| 20 |
+
prompt = TASK_FORMULAS_CRITIQUE_PROMPT.format(data_summary=data_summary, task_description=task_description, task_analysis=task_analysis, modeling_formulas=modeling_formulas).strip()
|
| 21 |
+
return self.llm.generate(prompt)
|
| 22 |
+
|
| 23 |
+
def formulas_improvement(self, data_summary: str, task_description: str, task_analysis: str, modeling_formulas: str, modeling_formulas_critique: str, user_prompt: str = ''):
|
| 24 |
+
prompt = TASK_FORMULAS_IMPROVEMENT_PROMPT.format(data_summary=data_summary, task_description=task_description, task_analysis=task_analysis, modeling_formulas=modeling_formulas, modeling_formulas_critique=modeling_formulas_critique, user_prompt=user_prompt).strip()
|
| 25 |
+
return self.llm.generate(prompt)
|
| 26 |
+
|
| 27 |
+
def formulas(self, data_summary: str, task_description: str, task_analysis: str, round: int = 1, user_prompt: str = ''):
|
| 28 |
+
formulas = self.formulas_actor(data_summary, task_description, task_analysis, user_prompt)
|
| 29 |
+
for i in range(round):
|
| 30 |
+
print(f'FORMULAS Round {i+1}')
|
| 31 |
+
formulas_critique = self.formulas_critic(data_summary, task_description, task_analysis, formulas)
|
| 32 |
+
formulas = self.formulas_improvement(data_summary, task_description, task_analysis, formulas, formulas_critique, user_prompt)
|
| 33 |
+
return formulas
|
| 34 |
+
|
| 35 |
+
def modeling_actor(self, data_summary: str, task_description: str, task_analysis: str, formulas: str, user_prompt: str = ''):
|
| 36 |
+
prompt = TASK_MODELING_PROMPT.format(data_summary=data_summary, task_description=task_description, task_analysis=task_analysis, modeling_formulas=formulas, user_prompt=user_prompt).strip()
|
| 37 |
+
return self.llm.generate(prompt)
|
| 38 |
+
|
| 39 |
+
# def modeling_critic(self, task_description: str, task_analysis: str, data_summary: str, formulas: str, modeling_process: str):
|
| 40 |
+
# prompt = TASK_MODELING_CRITIQUE_PROMPT.format(task_description=task_description, task_analysis=task_analysis, data_summary=data_summary, modeling_formulas=formulas, modeling_process=modeling_process).strip()
|
| 41 |
+
# return self.llm.generate(prompt)
|
| 42 |
+
|
| 43 |
+
# def modeling_improvement(self, task_description: str, task_analysis: str, data_summary: str, formulas: str, modeling_process: str, modeling_process_critique: str):
|
| 44 |
+
# prompt = TASK_MODELING_IMPROVEMENT_PROMPT.format(task_description=task_description, task_analysis=task_analysis, data_summary=data_summary, modeling_formulas=formulas, modeling_process=modeling_process, modeling_process_critique=modeling_process_critique).strip()
|
| 45 |
+
# return self.llm.generate(prompt)
|
| 46 |
+
|
| 47 |
+
# def modeling(self, task_description: str, task_analysis: str, data_summary: str, formulas: str, round: int = 1):
|
| 48 |
+
# process = self.modeling_actor(task_description, task_analysis, data_summary, formulas)
|
| 49 |
+
# for i in range(round):
|
| 50 |
+
# print(f'MODELING Round {i+1}')
|
| 51 |
+
# process_critique = self.modeling_critic(task_description, task_analysis, data_summary, formulas, process)
|
| 52 |
+
# process = self.modeling_improvement(task_description, task_analysis, data_summary, formulas, process, process_critique)
|
| 53 |
+
# return process
|
| 54 |
+
|
| 55 |
+
def modeling(self, data_summary: str, task_description: str, task_analysis: str, formulas: str, round: int = 1, user_prompt: str = ''):
|
| 56 |
+
return self.modeling_actor(data_summary, task_description, task_analysis, formulas, user_prompt)
|
| 57 |
+
|
| 58 |
+
def result(self, task_description: str, task_analysis: str, task_formulas: str, task_modeling: str, user_prompt: str = ''):
|
| 59 |
+
prompt = TASK_RESULT_PROMPT.format(task_description=task_description, task_analysis=task_analysis, task_formulas=task_formulas, task_modeling=task_modeling, user_prompt=user_prompt).strip()
|
| 60 |
+
return self.llm.generate(prompt)
|
| 61 |
+
|
| 62 |
+
def answer(self, task_description: str, task_analysis: str, task_formulas: str, task_modeling: str, task_result: str, user_prompt: str = ''):
|
| 63 |
+
prompt = TASK_ANSWER_PROMPT.format(task_description=task_description, task_analysis=task_analysis, task_formulas=task_formulas, task_modeling=task_modeling, task_result=task_result, user_prompt=user_prompt).strip()
|
| 64 |
+
return self.llm.generate(prompt)
|
core/agent/task.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .base_agent import BaseAgent
|
| 2 |
+
from prompt.constants import modeling_methods
|
| 3 |
+
from prompt.template import (TASK_ANALYSIS_PROMPT, TASK_RESULT_PROMPT, TASK_ANSWER_PROMPT,
|
| 4 |
+
TASK_FORMULAS_PROMPT, TASK_FORMULAS_CRITIQUE_PROMPT, TASK_FORMULAS_IMPROVEMENT_PROMPT,
|
| 5 |
+
TASK_MODELING_PROMPT, TASK_MODELING_CRITIQUE_PROMPT, TASK_MODELING_IMPROVEMENT_PROMPT,
|
| 6 |
+
TASK_CODING_PROMPT, TASK_CODING_DEBUG_PROMPT, CODE_STRUCTURE_PROMPT,
|
| 7 |
+
TASK_RESULT_WITH_CODE_PROMPT, COO_PROMPT, TASK_CODING_WO_COO_PROMPT)
|
| 8 |
+
import sys
|
| 9 |
+
import os
|
| 10 |
+
import subprocess
|
| 11 |
+
import selectors
|
| 12 |
+
import tiktoken
|
| 13 |
+
import json
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class EnvException(Exception):
|
| 17 |
+
def __init__(self, message):
|
| 18 |
+
self.message = message
|
| 19 |
+
def __str__(self):
|
| 20 |
+
return self.message
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def execute_script(script_path, work_dir):
|
| 24 |
+
try:
|
| 25 |
+
device = 0
|
| 26 |
+
python = "python"
|
| 27 |
+
cmd = f"CUDA_VISIBLE_DEVICES={device} {python} -u {script_path}"
|
| 28 |
+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True, cwd=work_dir)
|
| 29 |
+
|
| 30 |
+
stdout_lines = []
|
| 31 |
+
stderr_lines = []
|
| 32 |
+
|
| 33 |
+
selector = selectors.DefaultSelector()
|
| 34 |
+
selector.register(process.stdout, selectors.EVENT_READ)
|
| 35 |
+
selector.register(process.stderr, selectors.EVENT_READ)
|
| 36 |
+
|
| 37 |
+
while process.poll() is None and selector.get_map():
|
| 38 |
+
events = selector.select(timeout=1)
|
| 39 |
+
|
| 40 |
+
for key, _ in events:
|
| 41 |
+
line = key.fileobj.readline()
|
| 42 |
+
if key.fileobj == process.stdout:
|
| 43 |
+
print("STDOUT:", line, end =" ")
|
| 44 |
+
stdout_lines.append(line)
|
| 45 |
+
else:
|
| 46 |
+
print("STDERR:", line, end =" ")
|
| 47 |
+
stderr_lines.append(line)
|
| 48 |
+
|
| 49 |
+
for line in process.stdout:
|
| 50 |
+
line = line
|
| 51 |
+
print("STDOUT:", line, end =" ")
|
| 52 |
+
stdout_lines.append(line)
|
| 53 |
+
for line in process.stderr:
|
| 54 |
+
line = line
|
| 55 |
+
print("STDERR:", line, end =" ")
|
| 56 |
+
stderr_lines.append(line)
|
| 57 |
+
|
| 58 |
+
return_code = process.returncode
|
| 59 |
+
|
| 60 |
+
if return_code != 0:
|
| 61 |
+
observation = "".join(stderr_lines)
|
| 62 |
+
else:
|
| 63 |
+
observation = "".join(stdout_lines)
|
| 64 |
+
if observation == "" and return_code == 0:
|
| 65 |
+
# printed to stderr only
|
| 66 |
+
observation = "".join(stderr_lines)
|
| 67 |
+
return "The script has been executed. Here is the output:\n" + observation
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print("++++", "Wrong!")
|
| 70 |
+
raise EnvException(f"Something went wrong in executing {script_path}: {e}. Please check if it is ready to be executed.")
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class Task(BaseAgent):
|
| 74 |
+
def __init__(self, llm, coo=True, rag=True):
|
| 75 |
+
super().__init__(llm)
|
| 76 |
+
self.coo = coo
|
| 77 |
+
self.rag = rag
|
| 78 |
+
if coo:
|
| 79 |
+
self.coo_prompt = COO_PROMPT
|
| 80 |
+
else:
|
| 81 |
+
self.coo_prompt = ""
|
| 82 |
+
|
| 83 |
+
def analysis(self, prompt: str, task_description: str, user_prompt: str = ''):
|
| 84 |
+
prompt = TASK_ANALYSIS_PROMPT.format(prompt=prompt, coo_prompt=self.coo_prompt, task_description=task_description, user_prompt=user_prompt).strip()
|
| 85 |
+
return self.llm.generate(prompt)
|
| 86 |
+
|
| 87 |
+
def formulas_actor(self, prompt: str, data_summary: str, task_description: str, task_analysis: str, modeling_methods: str, user_prompt: str = ''):
|
| 88 |
+
prompt = TASK_FORMULAS_PROMPT.format(prompt=prompt, coo_prompt=self.coo_prompt, data_summary=data_summary, task_description=task_description, task_analysis=task_analysis, modeling_methods=modeling_methods, user_prompt=user_prompt).strip()
|
| 89 |
+
return self.llm.generate(prompt)
|
| 90 |
+
|
| 91 |
+
def formulas_critic(self, data_summary: str, task_description: str, task_analysis: str, modeling_formulas: str):
|
| 92 |
+
prompt = TASK_FORMULAS_CRITIQUE_PROMPT.format(data_summary=data_summary, task_description=task_description, task_analysis=task_analysis, modeling_formulas=modeling_formulas).strip()
|
| 93 |
+
return self.llm.generate(prompt)
|
| 94 |
+
|
| 95 |
+
def formulas_improvement(self, data_summary: str, task_description: str, task_analysis: str, modeling_formulas: str, modeling_formulas_critique: str, user_prompt: str = ''):
|
| 96 |
+
prompt = TASK_FORMULAS_IMPROVEMENT_PROMPT.format(data_summary=data_summary, task_description=task_description, task_analysis=task_analysis, modeling_formulas=modeling_formulas, modeling_formulas_critique=modeling_formulas_critique, user_prompt=user_prompt).strip()
|
| 97 |
+
return self.llm.generate(prompt)
|
| 98 |
+
|
| 99 |
+
def formulas(self, prompt: str, data_summary: str, task_description: str, task_analysis: str, modeling_methods: str, round: int = 1, user_prompt: str = ''):
|
| 100 |
+
formulas = self.formulas_actor(prompt, data_summary, task_description, task_analysis, modeling_methods, user_prompt)
|
| 101 |
+
if self.rag:
|
| 102 |
+
for i in range(round):
|
| 103 |
+
print(f'FORMULAS Round {i+1}')
|
| 104 |
+
formulas_critique = self.formulas_critic(data_summary, task_description, task_analysis, formulas)
|
| 105 |
+
formulas = self.formulas_improvement(data_summary, task_description, task_analysis, formulas, formulas_critique, user_prompt)
|
| 106 |
+
|
| 107 |
+
return formulas
|
| 108 |
+
|
| 109 |
+
def modeling_actor(self, prompt: str, data_summary: str, task_description: str, task_analysis: str, formulas: str, user_prompt: str = ''):
|
| 110 |
+
prompt = TASK_MODELING_PROMPT.format(prompt=prompt, coo_prompt=self.coo_prompt, data_summary=data_summary, task_description=task_description, task_analysis=task_analysis, modeling_formulas=formulas, user_prompt=user_prompt).strip()
|
| 111 |
+
return self.llm.generate(prompt)
|
| 112 |
+
|
| 113 |
+
# def modeling_critic(self, task_description: str, task_analysis: str, data_summary: str, formulas: str, modeling_process: str):
|
| 114 |
+
# prompt = TASK_MODELING_CRITIQUE_PROMPT.format(task_description=task_description, task_analysis=task_analysis, data_summary=data_summary, modeling_formulas=formulas, modeling_process=modeling_process).strip()
|
| 115 |
+
# return self.llm.generate(prompt)
|
| 116 |
+
|
| 117 |
+
# def modeling_improvement(self, task_description: str, task_analysis: str, data_summary: str, formulas: str, modeling_process: str, modeling_process_critique: str):
|
| 118 |
+
# prompt = TASK_MODELING_IMPROVEMENT_PROMPT.format(task_description=task_description, task_analysis=task_analysis, data_summary=data_summary, modeling_formulas=formulas, modeling_process=modeling_process, modeling_process_critique=modeling_process_critique).strip()
|
| 119 |
+
# return self.llm.generate(prompt)
|
| 120 |
+
|
| 121 |
+
# def modeling(self, task_description: str, task_analysis: str, data_summary: str, formulas: str, round: int = 1):
|
| 122 |
+
# process = self.modeling_actor(task_description, task_analysis, data_summary, formulas)
|
| 123 |
+
# for i in range(round):
|
| 124 |
+
# print(f'MODELING Round {i+1}')
|
| 125 |
+
# process_critique = self.modeling_critic(task_description, task_analysis, data_summary, formulas, process)
|
| 126 |
+
# process = self.modeling_improvement(task_description, task_analysis, data_summary, formulas, process, process_critique)
|
| 127 |
+
# return process
|
| 128 |
+
|
| 129 |
+
def modeling(self, prompt: str, data_summary: str, task_description: str, task_analysis: str, formulas: str, round: int = 1, user_prompt: str = ''):
|
| 130 |
+
return self.modeling_actor(prompt, data_summary, task_description, task_analysis, formulas, user_prompt)
|
| 131 |
+
|
| 132 |
+
def modeling_actor(self, prompt: str, data_summary: str, task_description: str, task_analysis: str, formulas: str, modeling: str, user_prompt: str = ''):
|
| 133 |
+
prompt = TASK_MODELING_PROMPT.format(prompt=prompt, coo_prompt=self.coo_prompt, data_summary=data_summary, task_description=task_description, task_analysis=task_analysis, modeling_formulas=formulas, modeling_methods=modeling, user_prompt=user_prompt).strip()
|
| 134 |
+
return self.llm.generate(prompt)
|
| 135 |
+
|
| 136 |
+
def coding_actor(self, data_file, data_summary, variable_description, task_description: str, task_analysis: str, formulas: str, modeling: str, dependent_file_prompt: str, code_template: str, script_name: str, work_dir: str, user_prompt: str = ''):
|
| 137 |
+
if self.coo:
|
| 138 |
+
prompt = TASK_CODING_PROMPT.format(data_file=data_file, data_summary=data_summary, variable_description=variable_description, task_description=task_description, task_analysis=task_analysis, modeling_formulas=formulas, modeling_process=modeling, dependent_file_prompt=dependent_file_prompt, code_template=code_template, user_prompt=user_prompt).strip()
|
| 139 |
+
else:
|
| 140 |
+
prompt = TASK_CODING_WO_COO_PROMPT.format(data_file=data_file, data_summary=data_summary, variable_description=variable_description, task_description=task_description, task_analysis=task_analysis, modeling_formulas=formulas, modeling_process=modeling, code_template=code_template, user_prompt=user_prompt).strip()
|
| 141 |
+
max_retry = 0
|
| 142 |
+
while max_retry < 5:
|
| 143 |
+
max_retry += 1
|
| 144 |
+
try:
|
| 145 |
+
completion = self.llm.generate(prompt)
|
| 146 |
+
new_content = completion.split("```python")[1].split("```")[0].strip()
|
| 147 |
+
break
|
| 148 |
+
except Exception as e:
|
| 149 |
+
# Format control.
|
| 150 |
+
print(f"Retry! The code does not start with ```python")
|
| 151 |
+
continue
|
| 152 |
+
|
| 153 |
+
with open(os.path.join(work_dir, script_name), "w") as f:
|
| 154 |
+
f.write(new_content)
|
| 155 |
+
|
| 156 |
+
# Execute the script.
|
| 157 |
+
try:
|
| 158 |
+
observation = execute_script(script_name, work_dir)
|
| 159 |
+
## If observation is too long, we only keep the last ~2k tokens.
|
| 160 |
+
enc = tiktoken.get_encoding("cl100k_base")
|
| 161 |
+
tokens = len(enc.encode(observation))
|
| 162 |
+
if tokens >= 2000:
|
| 163 |
+
observation = observation[:2000]
|
| 164 |
+
tokens = len(enc.encode(observation))
|
| 165 |
+
except Exception as e:
|
| 166 |
+
print(e)
|
| 167 |
+
input("Ah oh, Got stuck! Press any key to continue.")
|
| 168 |
+
|
| 169 |
+
return new_content, observation
|
| 170 |
+
|
| 171 |
+
def coding_debugger(self, code_template: str, modeling: str, code: str, observation: str, script_name: str, work_dir: str, user_prompt: str = ''):
|
| 172 |
+
|
| 173 |
+
prompt = TASK_CODING_DEBUG_PROMPT.format(code_template=code_template, modeling_process=modeling, code=code, observation=observation, user_prompt=user_prompt).strip()
|
| 174 |
+
|
| 175 |
+
max_retry = 0
|
| 176 |
+
while max_retry < 5:
|
| 177 |
+
max_retry += 1
|
| 178 |
+
try:
|
| 179 |
+
completion = self.llm.generate(prompt)
|
| 180 |
+
new_content = completion.split("```python")[1].split("```")[0].strip()
|
| 181 |
+
break
|
| 182 |
+
except Exception as e:
|
| 183 |
+
# Format control.
|
| 184 |
+
print(f"Retry! The code does not start with ```python")
|
| 185 |
+
continue
|
| 186 |
+
|
| 187 |
+
with open(os.path.join(work_dir, script_name), "w") as f:
|
| 188 |
+
f.write(new_content)
|
| 189 |
+
|
| 190 |
+
# Execute the script.
|
| 191 |
+
try:
|
| 192 |
+
observation = execute_script(script_name, work_dir)
|
| 193 |
+
## If observation is too long, we only keep the last ~2k tokens.
|
| 194 |
+
enc = tiktoken.get_encoding("cl100k_base")
|
| 195 |
+
tokens = len(enc.encode(observation))
|
| 196 |
+
if tokens >= 2000:
|
| 197 |
+
observation = observation[:2000]
|
| 198 |
+
tokens = len(enc.encode(observation))
|
| 199 |
+
except Exception as e:
|
| 200 |
+
print(e)
|
| 201 |
+
input("Ah oh, Got stuck! Press any key to continue.")
|
| 202 |
+
|
| 203 |
+
return new_content, observation
|
| 204 |
+
|
| 205 |
+
def coding(self, data_file, data_summary, variable_description, task_description: str, task_analysis: str, formulas: str, modeling: str, dependent_file_prompt: str, code_template: str, script_name: str, work_dir: str, try_num: int = 5, round: int = 1, user_prompt: str = ''):
|
| 206 |
+
for i in range(try_num):
|
| 207 |
+
print("="*10 + f" Try: {i + 1} " + "="*10)
|
| 208 |
+
iteration = 0
|
| 209 |
+
max_iteration = 3
|
| 210 |
+
while iteration < max_iteration:
|
| 211 |
+
print("="*10 + f" Iteration: {iteration + 1} " + "="*10)
|
| 212 |
+
if iteration == 0:
|
| 213 |
+
code, observation = self.coding_actor(data_file, data_summary, variable_description, task_description, task_analysis, formulas, modeling, dependent_file_prompt, code_template, script_name, work_dir, user_prompt)
|
| 214 |
+
# If the script has been successfully executed: Exit.
|
| 215 |
+
if "Traceback (most recent call last):" not in observation and "SyntaxError: invalid syntax" not in observation and "IndentationError" not in observation:
|
| 216 |
+
return code, True, observation.split("The script has been executed. Here is the output:\n")[1]
|
| 217 |
+
else:
|
| 218 |
+
code, observation = self.coding_debugger(code_template, modeling, code, observation, script_name, work_dir, user_prompt)
|
| 219 |
+
# If the script has been successfully executed: Exit.
|
| 220 |
+
if "Traceback (most recent call last):" not in observation and "SyntaxError: invalid syntax" not in observation and "IndentationError" not in observation:
|
| 221 |
+
return code, True, observation.split("The script has been executed. Here is the output:\n")[1]
|
| 222 |
+
iteration += 1
|
| 223 |
+
|
| 224 |
+
return code, False, None
|
| 225 |
+
|
| 226 |
+
def result(self, task_description: str, task_analysis: str, task_formulas: str, task_modeling: str, user_prompt: str = '', execution_result: str = ''):
|
| 227 |
+
if execution_result == '':
|
| 228 |
+
prompt = TASK_RESULT_PROMPT.format(task_description=task_description, task_analysis=task_analysis, task_formulas=task_formulas, task_modeling=task_modeling, user_prompt=user_prompt).strip()
|
| 229 |
+
else:
|
| 230 |
+
prompt = TASK_RESULT_WITH_CODE_PROMPT.format(task_description=task_description, task_analysis=task_analysis, task_formulas=task_formulas, task_modeling=task_modeling, user_prompt=user_prompt, execution_result=execution_result).strip()
|
| 231 |
+
return self.llm.generate(prompt)
|
| 232 |
+
|
| 233 |
+
def answer(self, task_description: str, task_analysis: str, task_formulas: str, task_modeling: str, task_result: str, user_prompt: str = ''):
|
| 234 |
+
prompt = TASK_ANSWER_PROMPT.format(task_description=task_description, task_analysis=task_analysis, task_formulas=task_formulas, task_modeling=task_modeling, task_result=task_result, user_prompt=user_prompt).strip()
|
| 235 |
+
return self.llm.generate(prompt)
|
| 236 |
+
|
| 237 |
+
def extract_code_structure(self, task_id, code: str, save_path: str):
|
| 238 |
+
prompt = CODE_STRUCTURE_PROMPT.format(code=code, save_path=save_path)
|
| 239 |
+
count = 0
|
| 240 |
+
for i in range(5):
|
| 241 |
+
try:
|
| 242 |
+
strucutre = self.llm.generate(prompt)
|
| 243 |
+
structure_string = strucutre.strip('```json\n').strip('```')
|
| 244 |
+
structure_json = json.loads(structure_string)
|
| 245 |
+
for i in range(len(structure_json['file_outputs'])):
|
| 246 |
+
structure_json['file_outputs'][i]['file_description'] = 'This file is generated by code for Task {}. '.format(task_id) + structure_json['file_outputs'][i]['file_description']
|
| 247 |
+
return structure_json
|
| 248 |
+
except:
|
| 249 |
+
continue
|
| 250 |
+
if count == 5:
|
| 251 |
+
sys.exit("Fail at extract_code_structure")
|
core/agent/task_decompse.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from .base_agent import BaseAgent
|
| 4 |
+
from prompt.template import TASK_DECOMPOSE_PROMPT, TASK_DESCRIPTION_PROMPT, TASK_DECOMPOSE_WO_COO_PROMPT
|
| 5 |
+
from utils.utils import read_json_file
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TaskDecompose(BaseAgent):
|
| 9 |
+
def __init__(self, llm, coo=True):
|
| 10 |
+
super().__init__(llm)
|
| 11 |
+
self.coo = coo
|
| 12 |
+
current_file = Path(__file__).resolve()
|
| 13 |
+
path = current_file.parent.parent.parent / 'data/actor_data/input/decompose_prompt.json'
|
| 14 |
+
self.decomposed_principles = read_json_file(str(path))
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def decompose(self, modeling_problem: str, problem_analysis: str, modeling_solution: str, problem_type: str, tasknum: int, user_prompt: str=''):
|
| 18 |
+
if self.coo:
|
| 19 |
+
decomposed_principle = self.decomposed_principles.get(problem_type, self.decomposed_principles['C'])
|
| 20 |
+
decomposed_principle = decomposed_principle.get(str(tasknum), decomposed_principle['4'])
|
| 21 |
+
prompt = TASK_DECOMPOSE_PROMPT.format(modeling_problem=modeling_problem, problem_analysis=problem_analysis, modeling_solution=modeling_solution, decomposed_principle=decomposed_principle, tasknum=tasknum, user_prompt=user_prompt)
|
| 22 |
+
# print(prompt)
|
| 23 |
+
answer = self.llm.generate(prompt)
|
| 24 |
+
tasks = [task.strip() for task in answer.split('---') if task.strip()]
|
| 25 |
+
else:
|
| 26 |
+
prompt = TASK_DECOMPOSE_WO_COO_PROMPT.format(modeling_problem=modeling_problem, tasknum=tasknum, user_prompt=user_prompt)
|
| 27 |
+
# print(prompt)
|
| 28 |
+
answer = self.llm.generate(prompt)
|
| 29 |
+
tasks = [task.strip() for task in answer.split('---') if task.strip()]
|
| 30 |
+
return tasks
|
| 31 |
+
|
| 32 |
+
def refine(self, modeling_problem: str, problem_analysis: str, modeling_solution: str, decomposed_subtasks: List[str], task_i: int):
|
| 33 |
+
decomposed_subtasks_str = '\n'.join(decomposed_subtasks)
|
| 34 |
+
prompt = TASK_DESCRIPTION_PROMPT.format(modeling_problem=modeling_problem, problem_analysis=problem_analysis, modeling_solution=modeling_solution, decomposed_subtasks=decomposed_subtasks_str, task_i=task_i+1)
|
| 35 |
+
answer = self.llm.generate(prompt)
|
| 36 |
+
return answer
|
| 37 |
+
|
| 38 |
+
def decompose_and_refine(self, modeling_problem: str, problem_analysis: str, modeling_solution: str, decomposed_principle: str, tasknum: int, user_prompt: str=''):
|
| 39 |
+
if self.coo:
|
| 40 |
+
decomposed_subtasks = self.decompose(modeling_problem, problem_analysis, modeling_solution, decomposed_principle, tasknum, user_prompt)
|
| 41 |
+
for task_i in range(len(decomposed_subtasks)):
|
| 42 |
+
refined_subtask = self.refine(modeling_problem, problem_analysis, modeling_solution, decomposed_subtasks, task_i)
|
| 43 |
+
decomposed_subtasks[task_i] = refined_subtask
|
| 44 |
+
else:
|
| 45 |
+
decomposed_subtasks = self.decompose(modeling_problem, problem_analysis, modeling_solution, decomposed_principle, tasknum, user_prompt)
|
| 46 |
+
|
| 47 |
+
return decomposed_subtasks
|
core/input/__init__.py
ADDED
|
File without changes
|
core/input/problem.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from utils.utils import read_json_file
|
| 2 |
+
|
| 3 |
+
from prompt.template import PROBLEM_PROMPT
|
| 4 |
+
from agent.data_description import DataDescription
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def problem_input(problem_path, llm):
|
| 8 |
+
problem = read_json_file(problem_path)
|
| 9 |
+
data_description = problem.get('dataset_description', {})
|
| 10 |
+
ds = DataDescription(llm)
|
| 11 |
+
|
| 12 |
+
if data_description:
|
| 13 |
+
data_path = problem['dataset_path']
|
| 14 |
+
variable_description = problem['variable_description']
|
| 15 |
+
data_summary = ds.summary(data_description=str(data_description) + '\n' + str(variable_description))
|
| 16 |
+
data_summary = f'Dataset Path:\n{data_path}\n\nData Description:\n{data_summary}'
|
| 17 |
+
else:
|
| 18 |
+
data_summary = ''
|
| 19 |
+
|
| 20 |
+
problem['data_summary'] = data_summary
|
| 21 |
+
problem['data_description'] = data_description
|
| 22 |
+
|
| 23 |
+
if problem.get('addendum', ''):
|
| 24 |
+
addendum = f"Addendum: \n{problem['addendum']}"
|
| 25 |
+
else:
|
| 26 |
+
addendum = ''
|
| 27 |
+
|
| 28 |
+
problem_str = PROBLEM_PROMPT.format(problem_background=problem['background'], problem_requirement=problem['problem_requirement'], addendum=addendum, data_summary=data_summary).strip()
|
| 29 |
+
problem['problem_str'] = problem_str
|
| 30 |
+
return problem_str, problem
|
| 31 |
+
|
core/input/test_middle_result.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
problem_str = """\
|
| 3 |
+
Problem Background:
|
| 4 |
+
In the 2023 Wimbledon Gentlemen’s final, 20-year-old Spanish rising star Carlos Alcaraz defeated 36-year-old Novak Djokovic. The loss was Djokovic’s first at Wimbledon since 2013 and ended a remarkable run for one of the all-time great players in Grand Slams.
|
| 5 |
+
The match itself was a remarkable battle.[1] Djokovic seemed destined to win easily as he dominated the first set 6 – 1 (winning 6 of 7 games). The second set, however, was tense and finally won by Alcarez in a tie-breaker 7 – 6. The third set was the reverse of the first, Alcaraz winning handily 6 – 1. The young Spaniard seemed in total control as the fourth set started, but somehow the match again changed course with Djokovic taking complete control to win the set 6 – 3. The fifth and final set started with Djokovic carrying the edge from the fourth set, but again a change of direction occurred and Alcaraz gained control and the victory 6 – 4. The data for this match is in the provided data set, “match_id” of “2023-wimbledon-1701”. You can see all the points for the first set when Djokovic had the edge using the “set_no” column equal to 1. The incredible swings, sometimes for many points or even games, that occurred in the player who seemed to have the advantage are often attributed to “momentum.”
|
| 6 |
+
|
| 7 |
+
Problem Requirement:
|
| 8 |
+
One dictionary definition of momentum is “strength or force gained by motion or by a series of events.”[2] In sports, a team or player may feel they have the momentum, or “strength/force” during a match/game, but it is difficult to measure such a phenomenon. Further, it is not readily apparent how various events during the match act to create or change momentum if it exists. Data is provided for every point from all Wimbledon 2023 men’s matches after the first 2 rounds. You may choose to include additional player information or other data at your discretion, but you must completely document the sources. Use the data to:
|
| 9 |
+
Develop a model that captures the flow of play as points occur and apply it to one or more of the matches. Your model should identify which player is performing better at a given time in the match, as well as how much better they are performing. Provide a visualization based on your model to depict the match flow. Note: in tennis, the player serving has a much higher probability of winning the point/game. You may wish to factor this into your model in some way.
|
| 10 |
+
A tennis coach is skeptical that “momentum” plays any role in the match. Instead, he postulates that swings in play and runs of success by one player are random. Use your model/metric to assess this claim.
|
| 11 |
+
Coaches would love to know if there are indicators that can help determine when the flow of play is about to change from favoring one player to the other. Using the data provided for at least one match, develop a model that predicts these swings in the match. What factors seem most related (if any)? Given the differential in past match “momentum” swings how do you advise a player going into a new match against a different player? Test the model you developed on one or more of the other matches. How well do you predict the swings in the match? If the model performs poorly at times, can you identify any factors that might need to be included in future models? How generalizable is your model to other matches (such as Women’s matches), tournaments, court surfaces, and other sports such as table tennis.
|
| 12 |
+
Produce a report of no more than 25 pages with your findings and include a one- to two-page memo summarizing your results with advice for coaches on the role of “momentum”, and how to prepare players to respond to events that impact the flow of play during a tennis match.
|
| 13 |
+
|
| 14 |
+
Data Description:
|
| 15 |
+
The dataset provides a comprehensive overview of match statistics from tennis games, specifically detailing individual points within matches at the 2023 Wimbledon tournament. Each entry is associated with a unique match identifier that indicates the round and match number, allowing for easy tracking of specific games throughout the tournament.
|
| 16 |
+
|
| 17 |
+
Key players are identified by their full names, and the dataset captures various metrics that reflect their performance over the course of the match. The elapsed time field records the duration from the start of the first point to the beginning of the current point, providing insight into the pace of play.
|
| 18 |
+
|
| 19 |
+
The dataset includes information on sets and games, indicating how many sets each player has won, as well as their respective game victories in the current set. This allows for analysis of player performance both within individual matches and across the tournament. The scoring system is detailed, with scores recorded in the traditional tennis format (love, 15, 30, 40, advantage), which adds context to the competitive nature of the points being analyzed.
|
| 20 |
+
|
| 21 |
+
Service dynamics are captured through fields indicating which player is serving, the type of serve (first or second), and the outcomes of those serves. Additionally, the dataset tracks critical point outcomes, identifying the winner of each point along with various performance metrics such as aces, double faults, winners, and unforced errors. These statistics are essential for evaluating the players' effectiveness and consistency during the match.
|
| 22 |
+
|
| 23 |
+
The dataset also includes information on strategic elements like break points—opportunities for players to capitalize on their opponent's serve—providing insights into pivotal moments that can influence match outcomes. Furthermore, physical performance is tracked through metrics like distance run during points, which highlights the physical demands placed on players during high-stakes moments.
|
| 24 |
+
|
| 25 |
+
Rally counts and shot speeds contribute to a deeper understanding of match dynamics, revealing how aggressive or defensive a player might be during exchanges. The depth and width of serves and returns further illustrate players' tactical choices, aiding in the analysis of their playing styles.
|
| 26 |
+
|
| 27 |
+
Overall, this dataset serves as a rich resource for analyzing tennis match performance, providing a detailed snapshot of player actions and outcomes throughout specific points in a match, which can be invaluable for coaches, analysts, and fans looking to understand the intricacies of tennis at a professional level.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
problem_analysis = """\
|
| 31 |
+
The problem of modeling momentum in tennis matches, particularly in the context of the 2023 Wimbledon tournament, requires a multi-faceted approach that integrates advanced statistical techniques, machine learning algorithms, and a deep understanding of the sport's dynamics. Momentum in tennis is a complex phenomenon influenced by a combination of player-specific attributes, match-specific conditions, and external variables. To develop a robust model, it is essential to move beyond traditional metrics such as serving advantage and incorporate granular data on serve placement, speed, and depth, as well as return strategies. These serve-specific details can provide deeper insights into the flow of play and help identify moments where momentum may shift. For instance, a player’s ability to consistently place serves in challenging positions or exploit an opponent’s return weaknesses can create sustained advantages that are not fully captured by simple win-loss metrics. Additionally, the model should account for the role of court surface, as different surfaces (e.g., grass, clay, hard court) can influence player performance and the dynamics of momentum. For example, on grass courts like Wimbledon, the faster surface may amplify the impact of serve dominance, while on clay courts, longer rallies and baseline play may shift the balance of momentum differently. By incorporating surface-specific dynamics, the model can better capture the nuances of momentum in different contexts.
|
| 32 |
+
|
| 33 |
+
Psychological factors also play a crucial role in momentum, as player confidence, resilience, and the ability to handle pressure during critical points (e.g., break points or set points) can significantly influence performance. Quantifying these factors requires integrating historical performance data to assess how players typically respond under pressure, as well as leveraging real-time biometric data to gauge mental and physical fatigue. For example, a player may experience a temporary dip in performance due to fatigue, which could be misinterpreted as a loss of momentum if not properly accounted for. Similarly, the model should consider the significance of specific points, such as break points or set points, which can have a disproportionate impact on momentum. By incorporating these contextual factors, the model can provide a more accurate and nuanced depiction of momentum in tennis matches. Furthermore, the model should account for the psychological impact of crowd support or adverse conditions, such as weather, which can influence player performance and momentum shifts. For instance, a player who thrives under pressure may gain momentum from a supportive crowd, while another player may struggle with the added scrutiny of a high-stakes match.
|
| 34 |
+
|
| 35 |
+
To assess the claim that momentum is merely a random phenomenon, the model must employ rigorous statistical methods to test the significance of observed performance swings. This involves analyzing the distribution of point outcomes and comparing them to expected probabilities based on serving advantages and other factors. If the model identifies patterns that deviate significantly from random variations, it would provide evidence supporting the existence of momentum. Conversely, if the observed swings align with random fluctuations, it would lend credence to the coach's skepticism. This analysis should also consider the potential for overfitting, ensuring that the model does not attribute significance to spurious patterns in the data. Additionally, the model should be tested on multiple matches to assess its robustness and generalizability. For example, by applying the model to matches from different rounds of the tournament or different years, we can evaluate whether the observed patterns of momentum are consistent across different contexts. This cross-validation process is critical for establishing the reliability of the model and its ability to distinguish between genuine momentum shifts and random variations.
|
| 36 |
+
|
| 37 |
+
Predicting shifts in the flow of play requires the model to identify indicators that precede changes in momentum. These indicators could include changes in player behavior, such as increased aggression or defensive play, as well as performance metrics like unforced errors or first-serve percentages. By analyzing these factors, the model can provide actionable insights for coaches, helping them anticipate and respond to momentum shifts during a match. For example, if the model detects a pattern of increasing unforced errors by a player, it could signal an impending loss of momentum, prompting the coach to adjust the player's strategy. However, the model's predictive accuracy must be rigorously tested on multiple matches to ensure its reliability. If the model performs poorly in certain scenarios, it may indicate the need to include additional variables or refine the existing ones. For instance, incorporating data on player fatigue or mental state could improve the model's predictive capabilities. Additionally, the model should consider the role of tactical adjustments, such as changes in serve placement or return strategy, which can influence the flow of play and momentum. By integrating these dynamic factors, the model can provide a more comprehensive understanding of momentum and its drivers.
|
| 38 |
+
|
| 39 |
+
The generalizability of the model to other contexts, such as women's matches, different tournaments, or other sports, depends on its ability to capture universal aspects of momentum while remaining adaptable to specific conditions. For instance, the serving advantage in tennis may differ from the serve advantage in table tennis, requiring adjustments to the model. Similarly, the psychological and physical demands of different sports may influence how momentum manifests. By designing the model with flexibility in mind, it can be adapted to analyze momentum in a wide range of competitive settings, providing valuable insights for coaches and players across various disciplines. Additionally, the model should be tested on historical data from different tournaments and surfaces to assess its robustness and applicability. For example, by applying the model to matches played on clay courts, we can evaluate whether the observed patterns of momentum are consistent across different surfaces. This adaptability is crucial for ensuring that the model remains relevant and useful in diverse competitive environments.
|
| 40 |
+
|
| 41 |
+
In conclusion, developing a model to capture momentum in tennis matches requires a comprehensive and dynamic approach that integrates quantitative data with qualitative insights. The model must account for the serving advantage, psychological factors, and time-dependent variables, while also distinguishing between random fluctuations and genuine momentum shifts. By rigorously testing the model's assumptions and predictions, and by incorporating feedback from real-world applications, it can provide valuable insights into the role of momentum in tennis and other sports. This, in turn, can help coaches and players better understand and respond to the ebb and flow of competitive play, ultimately enhancing their performance and strategic decision-making. The model should also be designed with flexibility in mind, allowing it to be adapted to different contexts and providing a robust framework for analyzing momentum across a wide range of competitive settings.
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
selected_models = """\
|
| 45 |
+
The most innovative, advanced, and suitable mathematical and machine learning models for modeling the problem of momentum in tennis matches include:
|
| 46 |
+
- **Logistic Regression** for point outcome predictions.
|
| 47 |
+
- **Random Forest** or **Support Vector Machines** for predicting momentum shifts.
|
| 48 |
+
- **ARIMA Models** and **Markov Chain Models** for analyzing momentum dynamics over time.
|
| 49 |
+
- **Time Series Analysis** for identifying trends in player performance.
|
| 50 |
+
|
| 51 |
+
These models not only capture the nuances of match dynamics but also provide a solid framework for coaches to understand and prepare for momentum shifts during matches. The insights derived from these models can significantly enhance match strategies and player preparation.
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
modeling_solution = """\
|
| 55 |
+
To solve the momentum modeling problem in tennis, we can construct a comprehensive model that captures the flow of play, analyzes momentum shifts, and predicts future changes in the match. The mathematical approach will combine probabilistic, statistical, and machine learning techniques to capture both the player performance and momentum dynamics.
|
| 56 |
+
|
| 57 |
+
### **1. Model Components:**
|
| 58 |
+
The model will be broken down into different components that allow us to track performance and momentum. These components include:
|
| 59 |
+
|
| 60 |
+
- **State Transitions (Markov Chain)**
|
| 61 |
+
- **Performance Metrics (Player Statistics)**
|
| 62 |
+
- **Momentum Indicator**
|
| 63 |
+
- **Prediction of Momentum Shift**
|
| 64 |
+
|
| 65 |
+
Each of these components requires sophisticated mathematical formulas and data representations. Let's discuss each step in detail.
|
| 66 |
+
|
| 67 |
+
### **2. State Transition Modeling:**
|
| 68 |
+
We begin by using **Markov Chains** to model the transition between states during the match. This is ideal for modeling the progression of a tennis match, where the match state is influenced by previous outcomes but does not depend on the entire history (Markov property).
|
| 69 |
+
|
| 70 |
+
Let’s define the state of the match at a given point in time \( t \) as a tuple of the following:
|
| 71 |
+
|
| 72 |
+
\[
|
| 73 |
+
S(t) = \{ \text{score}_{\text{player 1}}, \text{score}_{\text{player 2}}, \text{serve}, \text{set}_1, \text{set}_2, \dots, \text{time}\}
|
| 74 |
+
\]
|
| 75 |
+
|
| 76 |
+
Here:
|
| 77 |
+
- **score** refers to the current game score of both players in terms of tennis scoring.
|
| 78 |
+
- **serve** indicates which player is serving.
|
| 79 |
+
- **set** indicates the current set scores for both players.
|
| 80 |
+
- **time** is the timestamp of the point in the match.
|
| 81 |
+
|
| 82 |
+
At each point, the system transitions to a new state based on the outcome of the point. The transition probabilities between these states can be modeled as a **transition matrix**, denoted by \( P \):
|
| 83 |
+
|
| 84 |
+
\[
|
| 85 |
+
P_{ij} = P(S(t+1) = s_j | S(t) = s_i)
|
| 86 |
+
\]
|
| 87 |
+
|
| 88 |
+
Where \( P_{ij} \) represents the probability of transitioning from state \( s_i \) to \( s_j \), given the match's historical performance. This will allow us to model the evolution of the match and identify significant shifts in momentum.
|
| 89 |
+
|
| 90 |
+
The transition matrix will be derived using the observed data in the dataset, particularly focusing on factors such as:
|
| 91 |
+
- Player performance metrics (e.g., aces, winners, unforced errors)
|
| 92 |
+
- Whether the player is serving (since servers have an advantage)
|
| 93 |
+
- The current score and game state
|
| 94 |
+
- Physical metrics like player movement or serve speed
|
| 95 |
+
|
| 96 |
+
### **3. Momentum Indicator Model:**
|
| 97 |
+
|
| 98 |
+
**Momentum** in tennis is typically thought of as a shift in player performance due to psychological or physical factors, often manifesting in runs of consecutive points won or sudden changes in strategy. We define the momentum \( M(t) \) as a function of multiple match variables:
|
| 99 |
+
|
| 100 |
+
\[
|
| 101 |
+
M(t) = f(P_{\text{player 1}}, P_{\text{player 2}}, \Delta \text{score}, S_{\text{serve}}, R_{\text{streak}}, T_{\text{tension}})
|
| 102 |
+
\]
|
| 103 |
+
|
| 104 |
+
Where:
|
| 105 |
+
- \( P_{\text{player}} \) represents a vector of player performance metrics at time \( t \) (e.g., first-serve percentage, aces, unforced errors, winners).
|
| 106 |
+
- \( \Delta \text{score} \) represents the relative score difference between players at time \( t \).
|
| 107 |
+
- \( S_{\text{serve}} \) is the indicator of the player who is serving.
|
| 108 |
+
- \( R_{\text{streak}} \) is the **run of consecutive points won** by a player (i.e., a player's success streak).
|
| 109 |
+
- \( T_{\text{tension}} \) is a measure of how tense the match is, such as a tie-break or break point situation.
|
| 110 |
+
|
| 111 |
+
A simple formula for momentum might involve calculating the ratio of successful points to total points, adjusted for the player's current performance:
|
| 112 |
+
|
| 113 |
+
\[
|
| 114 |
+
M(t) = \frac{\text{Points Won}_{\text{player 1}}}{\text{Points Played}} - \frac{\text{Points Won}_{\text{player 2}}}{\text{Points Played}} + \alpha \cdot R_{\text{streak}} + \beta \cdot T_{\text{tension}}
|
| 115 |
+
\]
|
| 116 |
+
|
| 117 |
+
Where:
|
| 118 |
+
- The first term represents the win rate of each player up to time \( t \).
|
| 119 |
+
- The second term adjusts momentum based on consecutive points won (with \( \alpha \) as a weight).
|
| 120 |
+
- The third term accounts for match tension, where \( T_{\text{tension}} \) could be quantified by analyzing critical moments (like break points) or the phase of the match.
|
| 121 |
+
|
| 122 |
+
### **4. Statistical Test for Randomness:**
|
| 123 |
+
To test the coach's hypothesis that "momentum" is just random fluctuations in play, we need to compare observed momentum with random fluctuations:
|
| 124 |
+
|
| 125 |
+
- Null Hypothesis \( H_0 \): There is no momentum effect (the swings are random).
|
| 126 |
+
- Alternative Hypothesis \( H_1 \): There is a non-random momentum effect (swings correlate with performance and match dynamics).
|
| 127 |
+
|
| 128 |
+
We use a **Randomization Test** to compare the actual momentum times series with a shuffled version of the same data (where player points are randomly reassigned). The test statistic for momentum could be the **standard deviation** of momentum:
|
| 129 |
+
|
| 130 |
+
\[
|
| 131 |
+
\text{std}(M_{\text{real}}) \quad \text{vs} \quad \text{std}(M_{\text{random}})
|
| 132 |
+
\]
|
| 133 |
+
|
| 134 |
+
If \( \text{std}(M_{\text{real}}) \) is significantly higher than \( \text{std}(M_{\text{random}}) \), we reject \( H_0 \) and conclude that momentum plays a role.
|
| 135 |
+
|
| 136 |
+
### **5. Predicting Momentum Shift (Machine Learning Approach):**
|
| 137 |
+
|
| 138 |
+
To predict future momentum shifts, we can leverage **Random Forests** or **Gradient Boosting Machines (GBM)**. The key features will include:
|
| 139 |
+
- Player statistics (e.g., first serve win percentage, winners, aces)
|
| 140 |
+
- Point streak information
|
| 141 |
+
- Current match state (game, set, or match score)
|
| 142 |
+
- Relative performance (player 1 vs player 2)
|
| 143 |
+
- Tension index (break points, tie-breaks, etc.)
|
| 144 |
+
|
| 145 |
+
We define the momentum shift prediction as a binary classification problem:
|
| 146 |
+
|
| 147 |
+
\[
|
| 148 |
+
\text{Momentum Shift} =
|
| 149 |
+
\begin{cases}
|
| 150 |
+
1 & \text{if momentum shifts in favor of player 1} \\
|
| 151 |
+
0 & \text{if momentum shifts in favor of player 2}
|
| 152 |
+
\end{cases}
|
| 153 |
+
\]
|
| 154 |
+
|
| 155 |
+
The model predicts the likelihood \( P(\text{Shift}) \), and we evaluate the model using standard classification metrics like **accuracy**, **precision**, and **recall**.
|
| 156 |
+
|
| 157 |
+
### **6. Mathematical Formulation for Momentum Prediction:**
|
| 158 |
+
|
| 159 |
+
Given the features \( \mathbf{X}_t \) at time \( t \), the output probability of a momentum shift can be modeled as:
|
| 160 |
+
|
| 161 |
+
\[
|
| 162 |
+
P(\text{Shift} = 1 | \mathbf{X}_t) = \sigma(\mathbf{w}^\top \mathbf{X}_t)
|
| 163 |
+
\]
|
| 164 |
+
|
| 165 |
+
Where:
|
| 166 |
+
- \( \sigma(\cdot) \) is the logistic sigmoid function.
|
| 167 |
+
- \( \mathbf{w} \) are the weights learned by the model.
|
| 168 |
+
- \( \mathbf{X}_t \) is the feature vector at time \( t \) (e.g., player performance, set/game score, etc.).
|
| 169 |
+
|
| 170 |
+
### **7. Model Evaluation and Generalization:**
|
| 171 |
+
|
| 172 |
+
To assess the performance of the momentum shift prediction model:
|
| 173 |
+
- Split the dataset into training and testing sets.
|
| 174 |
+
- Evaluate on multiple matches to assess generalizability.
|
| 175 |
+
- Fine-tune the model using cross-validation.
|
| 176 |
+
- Test the model’s performance across different tournaments, surfaces, and even for female matches.
|
| 177 |
+
|
| 178 |
+
---
|
| 179 |
+
|
| 180 |
+
### **8. Visualization of Momentum:**
|
| 181 |
+
|
| 182 |
+
The visualization could take the form of a **momentum curve**, where the x-axis represents time (or points played) and the y-axis represents the calculated momentum \( M(t) \). The curve will oscillate based on player performance and could be highlighted with vertical lines representing significant shifts in momentum.
|
| 183 |
+
|
| 184 |
+
#### Example:
|
| 185 |
+
|
| 186 |
+
\[
|
| 187 |
+
\text{Momentum Curve: } M(t) \text{ vs } t
|
| 188 |
+
\]
|
| 189 |
+
|
| 190 |
+
---
|
| 191 |
+
|
| 192 |
+
### **Final Remarks:**
|
| 193 |
+
|
| 194 |
+
This model provides a sophisticated framework for understanding momentum in tennis. By leveraging a combination of Markov Chains, machine learning techniques, and statistical testing, it offers a predictive tool for momentum shifts. Coaches can use this model to assess how momentum affects match outcomes and prepare players for psychological and strategic shifts during matches.
|
| 195 |
+
"""
|
| 196 |
+
|
| 197 |
+
modeling_solution = """\
|
| 198 |
+
To effectively model the dynamics of momentum in tennis matches, particularly in the context of the 2023 Wimbledon tournament, we must adopt a structured approach that integrates statistical analysis and machine learning techniques with a nuanced understanding of tennis gameplay. The model should begin with a clear definition of momentum as a quantifiable shift in player performance, characterized by changes in key performance indicators such as point-win probability, serve effectiveness, and error rates. To capture the serving advantage, the model should incorporate player-specific serving statistics, adjusting for the different likelihood of winning points based on whether a player is serving or returning. By using historical data, we can establish baseline probabilities for each player, which will serve as dynamic benchmarks throughout the match.
|
| 199 |
+
|
| 200 |
+
The core of the model will be a probabilistic framework that continuously updates the likelihood of a player gaining or losing momentum based on the unfolding match data. This can be achieved through a Bayesian approach, where prior probabilities are adjusted with new information as the match progresses. The model will incorporate variables such as serve speed, return depth, rally length, and player fatigue, each weighted according to its historical impact on momentum shifts. Additionally, psychological factors can be quantified by analyzing historical performance under pressure situations, such as break points or tiebreaks, allowing the model to estimate a player's mental resilience.
|
| 201 |
+
|
| 202 |
+
Machine learning techniques, such as decision trees or random forests, can be employed to identify patterns and interactions between these variables, providing insights into the critical factors that precede momentum shifts. By training these models on a comprehensive dataset of past matches, we can identify the most predictive indicators of momentum changes. The model should also include a temporal component, using time-series analysis to capture the evolving nature of momentum as the match progresses.
|
| 203 |
+
|
| 204 |
+
To assess the validity of the momentum concept against the claim of randomness, the model will implement statistical tests to compare observed runs and performance swings to those expected under a random-walk hypothesis. This involves simulating matches based on random point distributions and comparing the frequency and magnitude of momentum shifts to actual match data. If the model detects systematic deviations from randomness, it provides evidence for the existence of momentum.
|
| 205 |
+
|
| 206 |
+
For practical application, the model will generate real-time predictions and alerts for coaches, indicating potential shifts in momentum and suggesting tactical adjustments. This can be facilitated through a user-friendly interface that visualizes momentum trends and key performance indicators. The model should be tested and validated across multiple matches, including different rounds and surfaces, to ensure robustness and generalizability. By incorporating cross-validation techniques, we can fine-tune the model parameters and improve predictive accuracy.
|
| 207 |
+
|
| 208 |
+
Furthermore, the model's adaptability to different sports or contexts involves recalibrating for sport-specific dynamics, such as the impact of team interactions in basketball or the influence of equipment in table tennis. By focusing on universal aspects of momentum, such as psychological resilience and performance consistency, the model can be extended to other competitive environments. Ultimately, this refined modeling approach not only addresses the intricacies of momentum in tennis but also provides actionable insights for improving player performance and strategic decision-making in various sports settings.
|
| 209 |
+
"""
|
| 210 |
+
|
| 211 |
+
task_descriptions = ['The first subtask involves establishing a robust probabilistic framework to quantify momentum in tennis matches, focusing on defining momentum as a measurable shift in player performance through variations in key performance indicators such as point-win probability, serve effectiveness, and error rates. The primary goal is to accurately capture the dynamic nature of momentum by integrating player-specific serving statistics, which account for the different likelihoods of point outcomes depending on whether a player is serving or returning. To achieve this, the subtask requires the use of historical match data to create baseline probabilities for each player, serving as dynamic benchmarks that adjust with ongoing match events. The methodology centers on a Bayesian approach, where prior probabilities are continuously updated with new data as the match progresses, reflecting real-time dynamics and shifts in momentum. This involves collecting and analyzing data inputs such as serve speed, return effectiveness, and other relevant match statistics to inform the probabilistic model. Tools and techniques such as Bayesian inference and statistical analysis are crucial for updating probabilities and capturing the nuances of momentum. The outcome of this subtask is a foundational model capable of reflecting the ebb and flow of momentum in real-time, providing a basis for further analysis and integration with additional model components in subsequent subtasks.', "The second subtask aims to enhance the model's ability to discern momentum shifts in tennis matches by leveraging machine learning techniques to identify patterns and interactions among influential variables. This involves the application of models such as decision trees, random forests, or gradient boosting to analyze a rich dataset of historical match data, focusing on uncovering the most predictive indicators of momentum changes. Key variables of interest include serve speed, return depth, rally length, player fatigue, and psychological resilience, with each factor weighted based on its historical impact on momentum. The machine learning model will be trained on labeled datasets where momentum shifts are identified, allowing it to learn complex relationships and interactions between variables. The training process involves feature engineering to extract meaningful insights from raw data, including the creation of derived features that capture temporal dynamics, such as moving averages or momentum scores calculated over a series of points or games. Cross-validation techniques will be employed to ensure the model's robustness and to prevent overfitting, thereby improving its predictive accuracy across different match scenarios. By integrating these machine learning models, the subtask seeks to provide deeper insights into the conditions that precede momentum shifts, ultimately enhancing the model's capacity to predict and quantify momentum changes as they occur during a match.", 'The third subtask focuses on rigorously testing the hypothesis that momentum in tennis matches is merely a random phenomenon. The goal is to determine whether observed performance swings are consistent with random variations or if they indicate genuine momentum shifts. This involves conducting statistical tests that compare the actual match data against a null hypothesis of randomness, often modeled as a random-walk process. The methodology includes simulating matches using randomly distributed point outcomes to create a baseline of expected performance swings under purely stochastic conditions. By analyzing the frequency, duration, and magnitude of momentum shifts in real matches against this random baseline, we can assess whether the observed patterns deviate significantly from what would be expected by chance. The key data inputs for this subtask are point-by-point outcomes from the dataset, which will be used to construct both the observed and simulated match timelines. Statistical techniques such as Monte Carlo simulations, chi-squared tests, or permutation tests may be employed to quantify the degree of deviation from randomness. The outcome of this subtask is to provide statistical evidence either supporting or refuting the existence of momentum, thereby addressing the skepticism about its role in tennis. This evidence is crucial for validating the broader model and confirming whether momentum should be considered a significant factor in match analysis and strategy development.', "Subtask 4 focuses on the practical application and generalizability of the momentum model by developing a real-time prediction system designed to assist coaches in making strategic decisions during a match. The primary goal is to create a system that can predict potential shifts in momentum, providing timely alerts that suggest tactical adjustments to optimize player performance. To achieve this, the subtask involves designing a user-friendly interface that visualizes momentum trends and key performance indicators in an accessible format, allowing coaches to quickly interpret the data. The methodology includes integrating the model with live match data feeds, enabling continuous updates and real-time analysis. The system will leverage machine learning algorithms, such as real-time decision trees or neural networks, to process incoming data and generate predictive insights. Key data inputs for this task include real-time match statistics like serve speed, rally length, player fatigue levels, and psychological resilience metrics, which are processed to detect patterns indicative of momentum shifts. The model's robustness will be tested across a diverse range of matches, including different rounds, surfaces, and player styles, to ensure its adaptability and reliability. Additionally, the subtask emphasizes recalibrating the model for application in other sports contexts, such as basketball or table tennis, by focusing on universal momentum aspects like psychological resilience and consistent performance. This adaptability is crucial for extending the model's utility beyond tennis, providing valuable insights to enhance strategic decision-making and player preparation across various sports settings."]
|
| 212 |
+
|
core/llm/__init__.py
ADDED
|
File without changes
|
core/llm/llm.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import openai
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
class LLM:
|
| 10 |
+
|
| 11 |
+
usages = []
|
| 12 |
+
|
| 13 |
+
def __init__(self, model_name, logger=None, user_id=None):
|
| 14 |
+
self.model_name = model_name
|
| 15 |
+
self.logger = logger
|
| 16 |
+
self.user_id = user_id
|
| 17 |
+
if self.model_name in ['deepseek-chat', 'deepseek-reasoner']:
|
| 18 |
+
self.api_key = os.getenv('DEEPSEEK_API_KEY')
|
| 19 |
+
self.api_base = os.getenv('DEEPSEEK_API_BASE')
|
| 20 |
+
else:
|
| 21 |
+
self.api_key = "key" # os.getenv('OPENAI_API_KEY')
|
| 22 |
+
# self.api_base = "https://gpt-api.hkust-gz.edu.cn/v1/chat/completions" # os.getenv('OPENAI_API_BASE')
|
| 23 |
+
self.api_key = os.getenv('OPENAI_API_KEY')
|
| 24 |
+
self.api_base = "https://api.openai.com/v1/chat/completions"
|
| 25 |
+
|
| 26 |
+
if not self.api_key:
|
| 27 |
+
raise ValueError('API key not found in environment variables')
|
| 28 |
+
|
| 29 |
+
self.client = openai.Client(api_key=self.api_key, base_url=self.api_base)
|
| 30 |
+
|
| 31 |
+
def reset(self, api_key=None, api_base=None, model_name=None):
|
| 32 |
+
if api_key:
|
| 33 |
+
self.api_key = api_key
|
| 34 |
+
if api_base:
|
| 35 |
+
self.api_base = api_base
|
| 36 |
+
if model_name:
|
| 37 |
+
self.model_name = model_name
|
| 38 |
+
self.client = openai.Client(api_key=self.api_key, base_url=self.api_base)
|
| 39 |
+
|
| 40 |
+
def generate(self, prompt, system='', usage=True):
|
| 41 |
+
try:
|
| 42 |
+
if self.model_name in ['deepseek-chat', 'deepseek-reasoner']:
|
| 43 |
+
response = self.client.chat.completions.create(
|
| 44 |
+
model=self.model_name,
|
| 45 |
+
messages=[
|
| 46 |
+
{'role': 'system', 'content': system},
|
| 47 |
+
{'role': 'user', 'content': prompt}
|
| 48 |
+
],
|
| 49 |
+
temperature=0.7,
|
| 50 |
+
top_p=1.0,
|
| 51 |
+
frequency_penalty=0.0,
|
| 52 |
+
presence_penalty=0.0
|
| 53 |
+
)
|
| 54 |
+
answer = response.choices[0].message.content
|
| 55 |
+
usage = {
|
| 56 |
+
'completion_tokens': response.usage.completion_tokens,
|
| 57 |
+
'prompt_tokens': response.usage.prompt_tokens,
|
| 58 |
+
'total_tokens': response.usage.total_tokens
|
| 59 |
+
}
|
| 60 |
+
else:
|
| 61 |
+
messages=[{'role': 'system', 'content': system},
|
| 62 |
+
{'role': 'user', 'content': prompt}]
|
| 63 |
+
raw_request = {
|
| 64 |
+
"model": self.model_name,
|
| 65 |
+
"temperature": 0.7,
|
| 66 |
+
"top_p": 1.0,
|
| 67 |
+
"frequency_penalty": 0.0,
|
| 68 |
+
"presence_penalty": 0.0
|
| 69 |
+
}
|
| 70 |
+
# HKUST-GZ API
|
| 71 |
+
HEADERS = {
|
| 72 |
+
"Content-Type": "application/json",
|
| 73 |
+
"Authorization": "Bearer {}".format(self.api_key)
|
| 74 |
+
}
|
| 75 |
+
response = requests.post(self.api_base, headers=HEADERS, data=json.dumps({"messages": messages, **raw_request}))
|
| 76 |
+
response.raise_for_status()
|
| 77 |
+
response = response.json()
|
| 78 |
+
answer = response["choices"][0]["message"]["content"]
|
| 79 |
+
if self.model_name == 'DeepSeek-R1-671B':
|
| 80 |
+
answer = answer.split('\n</think>\n\n')[1]
|
| 81 |
+
usage = {
|
| 82 |
+
'completion_tokens': response['usage']['completion_tokens'],
|
| 83 |
+
'prompt_tokens': response['usage']['prompt_tokens'],
|
| 84 |
+
'total_tokens': response['usage']['total_tokens']
|
| 85 |
+
}
|
| 86 |
+
if self.logger:
|
| 87 |
+
self.logger.info(f"[LLM] UserID: {self.user_id} Key: {self.api_key}, Model: {self.model_name}, Usage: {usage}")
|
| 88 |
+
if usage:
|
| 89 |
+
self.usages.append(usage)
|
| 90 |
+
return answer
|
| 91 |
+
|
| 92 |
+
except Exception as e:
|
| 93 |
+
return f'An error occurred: {e}'
|
| 94 |
+
|
| 95 |
+
def get_total_usage(self):
|
| 96 |
+
total_usage = {
|
| 97 |
+
'completion_tokens': 0,
|
| 98 |
+
'prompt_tokens': 0,
|
| 99 |
+
'total_tokens': 0
|
| 100 |
+
}
|
| 101 |
+
for usage in self.usages:
|
| 102 |
+
for key, value in usage.items():
|
| 103 |
+
total_usage[key] += value
|
| 104 |
+
return total_usage
|
| 105 |
+
|
| 106 |
+
def clear_usage(self):
|
| 107 |
+
self.usages = []
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
if __name__ == '__main__':
|
| 111 |
+
llm = LLM('deepseek-chat')
|
| 112 |
+
print(llm.generate('Hello, how are you?', 'You are a helpful assistant.', usage=True))
|
| 113 |
+
|
| 114 |
+
# llm = LLM('deepseek-chat')
|
| 115 |
+
# print(llm.generate('Hello, how are you?', 'You are a helpful assistant.'))
|
| 116 |
+
# print(llm.get_total_usage())
|
| 117 |
+
# llm.clear_usage()
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
|
core/prompt/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
core/prompt/__init__.py
ADDED
|
File without changes
|
core/prompt/constants.py
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
modeling_methods = """\
|
| 2 |
+
## Operations Research
|
| 3 |
+
|
| 4 |
+
### Programming Theory
|
| 5 |
+
#### Linear Programming
|
| 6 |
+
- Linear Programming (LP)
|
| 7 |
+
- Integer Programming (IP)
|
| 8 |
+
- Mixed Integer Programming (MIP)
|
| 9 |
+
- Goal Programming (GP)
|
| 10 |
+
- Multi-Objective Programming (MOP)
|
| 11 |
+
- Multi-level Programming
|
| 12 |
+
- Dynamic Programming (DP)
|
| 13 |
+
- Network Optimization Models
|
| 14 |
+
- Parametric Linear Programming
|
| 15 |
+
|
| 16 |
+
#### Nonlinear Programming
|
| 17 |
+
- Convex Programming
|
| 18 |
+
- Quadratic Programming (QP)
|
| 19 |
+
- Nonlinear Programming (NLP)
|
| 20 |
+
- Semi-Definite Programming (SDP)
|
| 21 |
+
- Set Programming
|
| 22 |
+
- Non-Smooth Optimization
|
| 23 |
+
- Penalty Methods in Nonlinear Optimization
|
| 24 |
+
|
| 25 |
+
#### Others
|
| 26 |
+
- Fuzzy Optimization
|
| 27 |
+
- Stochastic Optimization
|
| 28 |
+
- Robust Optimization
|
| 29 |
+
- Approximation Algorithms
|
| 30 |
+
- Cooperative Game Theory
|
| 31 |
+
- Metaheuristic Approaches (Simulated Annealing, Genetic Algorithms, etc.)
|
| 32 |
+
|
| 33 |
+
### Graph Theory
|
| 34 |
+
#### Path
|
| 35 |
+
- Shortest Path Model (S-T, All-Pairs)
|
| 36 |
+
- Dijkstra’s Algorithm
|
| 37 |
+
- A* Algorithm
|
| 38 |
+
- Bellman-Ford Algorithm
|
| 39 |
+
- Eulerian Path Problem
|
| 40 |
+
- Hamiltonian Cycle Problem
|
| 41 |
+
- Traveling Salesman Problem (TSP)
|
| 42 |
+
- Vehicle Routing Problem (VRP)
|
| 43 |
+
- K-Shortest Path Problem
|
| 44 |
+
- Path Planning Algorithms
|
| 45 |
+
|
| 46 |
+
#### Tree
|
| 47 |
+
- Minimum Spanning Tree (MST)
|
| 48 |
+
- Prim’s Algorithm
|
| 49 |
+
- Kruskal’s Algorithm
|
| 50 |
+
- Huffman Tree
|
| 51 |
+
- Steiner Tree Problem
|
| 52 |
+
- Binary Search Tree (BST)
|
| 53 |
+
- AVL Tree
|
| 54 |
+
- K-d Tree
|
| 55 |
+
- Quad Tree
|
| 56 |
+
- B+ Tree
|
| 57 |
+
|
| 58 |
+
#### Flow
|
| 59 |
+
- Max-Flow Min-Cost Max-Flow Problem
|
| 60 |
+
- Ford-Fulkerson Algorithm
|
| 61 |
+
- Edmonds-Karp Algorithm
|
| 62 |
+
- Minimum-Cost Flow Problem
|
| 63 |
+
- Multi-Commodity Flow Problem
|
| 64 |
+
- Network Reliability Models
|
| 65 |
+
|
| 66 |
+
#### Others
|
| 67 |
+
- Bipartite Matching Model
|
| 68 |
+
- Stable Marriage Problem
|
| 69 |
+
- Graph Coloring Problem (Greedy Coloring, Backtracking)
|
| 70 |
+
- Vertex Cover Problem
|
| 71 |
+
- Set Cover Problem
|
| 72 |
+
- Clique Problem
|
| 73 |
+
- Independent Set Problem
|
| 74 |
+
- Algebraic Representation of Graph (Adjacency Matrix, Laplacian Matrix, Incidence Matrix)
|
| 75 |
+
- Spectral Graph Theory Models
|
| 76 |
+
|
| 77 |
+
### Stochastic Programming Theory
|
| 78 |
+
- Stochastic Linear Programming
|
| 79 |
+
- Markov Chains and Models
|
| 80 |
+
- Markov Decision Process (MDP)
|
| 81 |
+
- Queuing Theory (M/M/1, M/G/1, G/G/1 Queues)
|
| 82 |
+
- Inventory Theory (Economic Order Quantity, Newsvendor Problem)
|
| 83 |
+
- Monte Carlo Simulation
|
| 84 |
+
- Reliability Theory
|
| 85 |
+
- Decision Trees and Multi-Stage Decision Problems
|
| 86 |
+
- Dynamic Stochastic Optimization
|
| 87 |
+
|
| 88 |
+
## Optimization Methods
|
| 89 |
+
|
| 90 |
+
### Deterministic Algorithms
|
| 91 |
+
- Greedy Algorithm
|
| 92 |
+
- Divide & Conquer
|
| 93 |
+
- Dynamic Programming
|
| 94 |
+
- Backtracking Algorithms
|
| 95 |
+
- Local Search Algorithms
|
| 96 |
+
- Branch and Bound
|
| 97 |
+
|
| 98 |
+
### Heuristic Algorithms
|
| 99 |
+
- Simulated Annealing (SA)
|
| 100 |
+
- Tabu Search
|
| 101 |
+
- Genetic Algorithm (GA)
|
| 102 |
+
- Particle Swarm Optimization (PSO)
|
| 103 |
+
- Ant Colony Optimization (ACO)
|
| 104 |
+
- Harmony Search Algorithm
|
| 105 |
+
- Differential Evolution
|
| 106 |
+
- Memetic Algorithm
|
| 107 |
+
- Iterative Deepening Search
|
| 108 |
+
|
| 109 |
+
### Iterative Algorithms
|
| 110 |
+
- Gradient Descent
|
| 111 |
+
- Newton's Method
|
| 112 |
+
- Coordinate Descent
|
| 113 |
+
- Conjugate Gradient Method
|
| 114 |
+
- Broyden–Fletcher–Goldfarb–Shanno (BFGS) Method
|
| 115 |
+
- Levenberg-Marquardt Algorithm
|
| 116 |
+
- Golden-Section Search
|
| 117 |
+
- Nelder-Mead Simplex Algorithm
|
| 118 |
+
|
| 119 |
+
### Constrained Optimization
|
| 120 |
+
- Linear Programming (LP) Solvers (Simplex Method, Interior-Point Method)
|
| 121 |
+
- Quadratic Programming (QP) Solvers
|
| 122 |
+
- Feasible Direction Method
|
| 123 |
+
- Projected Gradient Method
|
| 124 |
+
- Augmented Lagrangian Methods
|
| 125 |
+
- Lagrange Multipliers
|
| 126 |
+
- Karush-Kuhn-Tucker Conditions
|
| 127 |
+
- KKT Conditions in Nonlinear Optimization
|
| 128 |
+
- Primal-Dual Methods
|
| 129 |
+
|
| 130 |
+
### Solution Techniques
|
| 131 |
+
- Branch and Bound Method
|
| 132 |
+
- Relaxation Methods
|
| 133 |
+
- Penalty Function Methods
|
| 134 |
+
- Restriction Method
|
| 135 |
+
- Lagrange Relaxation
|
| 136 |
+
- Antithesis Optimization
|
| 137 |
+
- Subgradient Methods
|
| 138 |
+
- Multigrid Methods
|
| 139 |
+
|
| 140 |
+
---
|
| 141 |
+
|
| 142 |
+
## Machine Learning Topics
|
| 143 |
+
|
| 144 |
+
### Classification
|
| 145 |
+
- K-Nearest Neighbors (KNN)
|
| 146 |
+
- Support Vector Machine (SVM)
|
| 147 |
+
- Decision Trees
|
| 148 |
+
- Random Forest
|
| 149 |
+
- Gradient Boosting Machines (GBM)
|
| 150 |
+
- XGBoost, LightGBM, CatBoost
|
| 151 |
+
- Logistic Regression
|
| 152 |
+
- Naive Bayes
|
| 153 |
+
- Linear Discriminant Analysis (LDA)
|
| 154 |
+
- Quadratic Discriminant Analysis (QDA)
|
| 155 |
+
- Neural Networks (Feedforward, Convolutional, Recurrent)
|
| 156 |
+
- Deep Learning (CNN, RNN, LSTM)
|
| 157 |
+
|
| 158 |
+
### Clustering
|
| 159 |
+
- K-Means Algorithm
|
| 160 |
+
- K-Means++ Variant
|
| 161 |
+
- Expectation-Maximization (EM)
|
| 162 |
+
- Self-Organizing Maps (SOM)
|
| 163 |
+
- DBSCAN (Density-Based Spatial Clustering)
|
| 164 |
+
- Hierarchical Clustering
|
| 165 |
+
- Agglomerative and Divisive Clustering
|
| 166 |
+
- Spectral Clustering
|
| 167 |
+
- Gaussian Mixture Models (GMM)
|
| 168 |
+
- Affinity Propagation
|
| 169 |
+
- Birch Clustering
|
| 170 |
+
|
| 171 |
+
### Regression
|
| 172 |
+
- Linear Regression
|
| 173 |
+
- Ridge Regression
|
| 174 |
+
- Lasso Regression
|
| 175 |
+
- Elastic Net Regression
|
| 176 |
+
- Poisson Regression
|
| 177 |
+
- Logistic Regression (for binary classification)
|
| 178 |
+
- Polynomial Regression
|
| 179 |
+
- Generalized Linear Models (GLM)
|
| 180 |
+
- Non-Linear Regression
|
| 181 |
+
- Locally Weighted Regression (Loess)
|
| 182 |
+
|
| 183 |
+
### Dimensionality Reduction
|
| 184 |
+
#### Linear
|
| 185 |
+
- Principal Component Analysis (PCA)
|
| 186 |
+
- Canonical Correlation Analysis (CCA)
|
| 187 |
+
- Independent Component Analysis (ICA)
|
| 188 |
+
- Singular Value Decomposition (SVD)
|
| 189 |
+
|
| 190 |
+
#### Non-Linear
|
| 191 |
+
- Local Linear Embedding (LLE)
|
| 192 |
+
- Laplacian Eigenmaps
|
| 193 |
+
- t-Distributed Stochastic Neighbor Embedding (t-SNE)
|
| 194 |
+
- Isomap
|
| 195 |
+
- Autoencoders
|
| 196 |
+
|
| 197 |
+
### Ensemble Learning Algorithms
|
| 198 |
+
- Bagging Algorithm
|
| 199 |
+
- Boosting Algorithm
|
| 200 |
+
- Random Forest
|
| 201 |
+
- AdaBoost
|
| 202 |
+
- Gradient Boosting
|
| 203 |
+
- Stacking
|
| 204 |
+
- Voting Classifier
|
| 205 |
+
- Bootstrap Aggregating
|
| 206 |
+
|
| 207 |
+
## Prediction Topics
|
| 208 |
+
|
| 209 |
+
### Discrete Prediction
|
| 210 |
+
- Markov Decision Process (MDP)
|
| 211 |
+
- Hidden Markov Models (HMM)
|
| 212 |
+
- Grey Forecasting
|
| 213 |
+
- Bayesian Networks
|
| 214 |
+
- Difference Equations
|
| 215 |
+
- Kalman Filtering
|
| 216 |
+
- Particle Filtering
|
| 217 |
+
|
| 218 |
+
### Continuous Prediction
|
| 219 |
+
#### Time Series Models
|
| 220 |
+
- Autoregressive Integrated Moving Average (ARIMA)
|
| 221 |
+
- Generalized Autoregressive Conditional Heteroskedasticity (GARCH)
|
| 222 |
+
- Exponential Smoothing (Holt-Winters)
|
| 223 |
+
- Seasonal Decomposition of Time Series (STL)
|
| 224 |
+
- Prophet Model
|
| 225 |
+
|
| 226 |
+
#### Differential Equation Models
|
| 227 |
+
- Ordinary Differential Equations (ODE)
|
| 228 |
+
- Stochastic Differential Equations (SDE)
|
| 229 |
+
- Infectious Disease Models (SIR, SEIR)
|
| 230 |
+
- Population Growth Models
|
| 231 |
+
- Lotka-Volterra Models
|
| 232 |
+
- Heat Conduction Models
|
| 233 |
+
- Predator-Prey Models
|
| 234 |
+
- Diffusion Models (e.g., River Pollutant Diffusion)
|
| 235 |
+
- Economic Growth Models
|
| 236 |
+
- Battle Models (e.g., Lotka-Volterra Models)
|
| 237 |
+
|
| 238 |
+
## Evaluation Topics
|
| 239 |
+
|
| 240 |
+
### Scoring Evaluation
|
| 241 |
+
- Fuzzy Comprehensive Evaluation
|
| 242 |
+
- Grey Evaluation Method
|
| 243 |
+
- Analytic Hierarchy Process (AHP)
|
| 244 |
+
- Analytic Network Process (ANP)
|
| 245 |
+
- Data Envelopment Analysis (DEA)
|
| 246 |
+
- Technique for Order Preference by Similarity to Ideal Solution (TOPSIS)
|
| 247 |
+
- Entropy Weight Method
|
| 248 |
+
- Information Entropy Method
|
| 249 |
+
- Weighted Sum Method
|
| 250 |
+
- Weighted Product Method
|
| 251 |
+
- Multi-Criteria Decision Analysis (MCDA)
|
| 252 |
+
- PROMETHEE and GAIA
|
| 253 |
+
|
| 254 |
+
### Statistical Evaluation
|
| 255 |
+
#### Correlation Test
|
| 256 |
+
- Pearson Correlation Coefficient
|
| 257 |
+
- Spearman's Rank Correlation Coefficient
|
| 258 |
+
- Kendall’s Tau Coefficient
|
| 259 |
+
- Wilcoxon's Signed Rank Test
|
| 260 |
+
- Kruskal-Wallis Test
|
| 261 |
+
- Mann-Whitney U Test
|
| 262 |
+
|
| 263 |
+
#### Goodness of Fit Test
|
| 264 |
+
- Analysis of Variance (ANOVA)
|
| 265 |
+
- Chi-Square Goodness-of-Fit Test
|
| 266 |
+
- Kolmogorov-Smirnov Test (KS Test)
|
| 267 |
+
- Anderson-Darling Test
|
| 268 |
+
- Shapiro-Wilk Test
|
| 269 |
+
- Jarque-Bera Test
|
| 270 |
+
- Bayesian Information Criterion (BIC)
|
| 271 |
+
"""
|
core/prompt/template.py
ADDED
|
@@ -0,0 +1,1106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PROBLEM_PROMPT = """\
|
| 2 |
+
Problem Background:
|
| 3 |
+
{problem_background}
|
| 4 |
+
|
| 5 |
+
Problem Requirement:
|
| 6 |
+
{problem_requirement}
|
| 7 |
+
{addendum}
|
| 8 |
+
{data_summary}
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
DATA_DESCRIPTION_PROMPT = """\
|
| 13 |
+
Data Description:
|
| 14 |
+
{data_description}
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
Your task is to generate a detailed summary of the dataset based on the dataset description provided. It needs to cover comprehensive information, but not explain each field one by one. Using plain text to describe in a single paragraph, without any Markdown formatting or syntax.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
PROBLEM_ANALYSIS_PROMPT = """\
|
| 23 |
+
# Mathematical Modeling Problem:
|
| 24 |
+
{modeling_problem}
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
You are tasked with analyzing a mathematical modeling problem with a focus on the underlying concepts, logical reasoning, and assumptions that inform the solution process. Begin by considering the nature of the problem in its broader context. What are the primary objectives of the model, and how do they shape the way you approach the task? Think critically about the assumptions that may be inherently embedded in the problem. What implicit beliefs or constraints have been set up, either explicitly or implicitly, within the problem’s description? Reflect on how these assumptions might influence the interpretation and application of any potential solutions.
|
| 29 |
+
|
| 30 |
+
Dive deeper into the relationships and interdependencies between the different components of the problem. What are the potential hidden complexities that may arise from these interconnections? Are there any conflicts or tensions between different aspects of the problem that need to be resolved? Explore how these interdependencies might lead to unforeseen challenges and require revisiting initial assumptions or redefining the parameters of the task.
|
| 31 |
+
|
| 32 |
+
Consider how the complexity of the problem may evolve across different scales or over time. Are there time-dependent factors or long-term consequences that should be accounted for, especially in terms of the stability or sustainability of the model’s outcomes? Think about how the model’s behavior might change under different scenarios, such as variations in input or changes in external conditions. Reflect on whether any simplifications or idealizations in the problem might inadvertently obscure key dynamics that are crucial for an accurate representation.
|
| 33 |
+
|
| 34 |
+
In your analysis, also give attention to possible alternative perspectives on the problem. Are there different ways to frame the issue that could lead to distinct modeling approaches or solution strategies? How would those alternative perspectives impact the overall approach? Additionally, evaluate the potential risks or uncertainties inherent in the problem, especially when it comes to choosing between competing modeling approaches. Consider how the outcomes might vary depending on the choices you make in constructing the model, and how you would manage such trade-offs.
|
| 35 |
+
|
| 36 |
+
Finally, reflect on the dynamic nature of the modeling process itself. How might your understanding of the problem evolve as you continue to explore its intricacies? Ensure that your thought process remains flexible, with a readiness to revise earlier conclusions as new insights emerge. The goal is to maintain a reflective, iterative analysis that adapts to deeper understandings of the task at hand, rather than pursuing a fixed or rigid approach.
|
| 37 |
+
|
| 38 |
+
{user_prompt}
|
| 39 |
+
|
| 40 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text, without any Markdown formatting or syntax. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
PROBLEM_ANALYSIS_CRITIQUE_PROMPT = """\
|
| 45 |
+
# Mathematical Modeling Problem:
|
| 46 |
+
{modeling_problem}
|
| 47 |
+
|
| 48 |
+
# Problem Analysis:
|
| 49 |
+
{problem_analysis}
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
Critically examine the analysis results of the given mathematical modeling problem, focusing on the following aspects:
|
| 54 |
+
|
| 55 |
+
1. Depth of Thinking: Evaluate whether the analysis demonstrates a comprehensive understanding of the underlying problem. Does it go beyond surface-level observations? Are the assumptions, limitations, and potential implications of the results carefully considered? Assess whether the analysis adequately addresses both the broader context and specific intricacies of the problem.
|
| 56 |
+
2. Novelty of Perspective: Analyze the originality of the approach taken in the analysis. Does it introduce new insights or merely rehash well-established methods or solutions? Are alternative perspectives or unconventional techniques explored, or is the analysis constrained by a narrow set of assumptions or typical approaches?
|
| 57 |
+
3. Critical Evaluation of Results: Consider the extent to which the analysis critically engages with the results. Are the conclusions drawn from the analysis well-supported by the mathematical findings, or do they overlook key uncertainties or counterexamples? Does the analysis acknowledge potential contradictions or ambiguities in the data?
|
| 58 |
+
4. Rigor and Precision: Assess the level of rigor applied in the analysis. Are the steps logically consistent and mathematically sound, or are there overlooked errors, gaps, or assumptions that undermine the conclusions? Does the analysis exhibit a clear, methodical approach, or is it characterized by vague reasoning and imprecision?
|
| 59 |
+
5. Contextual Awareness: Evaluate how well the analysis situates itself within the broader landscape of mathematical modeling in this area. Does it consider previous work or developments in the field? Is there any indication of awareness of real-world implications, practical constraints, or ethical concerns, if applicable?
|
| 60 |
+
|
| 61 |
+
Critique the analysis without offering any constructive suggestions—your focus should solely be on highlighting weaknesses, gaps, and limitations within the approach and its execution.
|
| 62 |
+
"""
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
PROBLEM_ANALYSIS_IMPROVEMENT_PROMPT = """\
|
| 66 |
+
# Mathematical Modeling Problem:
|
| 67 |
+
{modeling_problem}
|
| 68 |
+
|
| 69 |
+
# Problem Analysis:
|
| 70 |
+
{problem_analysis}
|
| 71 |
+
|
| 72 |
+
# Problem Analysis Critique:
|
| 73 |
+
{problem_analysis_critique}
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
Refine and improve the existing problem analysis based on the critique provided to generate insightful analysis.
|
| 78 |
+
|
| 79 |
+
Provide the improved version directly. DO NOT mention any previous analysis content and deficiencies in the improved analysis. Just refer to the above critical suggestions and directly give the new improved analysis.
|
| 80 |
+
{user_prompt}
|
| 81 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text, without any Markdown formatting or syntax. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 82 |
+
|
| 83 |
+
IMPROVED PROBLEM ANALYSIS:
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
METHOD_CRITIQUE_PROMPT = """\
|
| 88 |
+
## Problem Description
|
| 89 |
+
|
| 90 |
+
{problem_description}
|
| 91 |
+
|
| 92 |
+
## Method List
|
| 93 |
+
|
| 94 |
+
{methods}
|
| 95 |
+
|
| 96 |
+
## Evaluation Task
|
| 97 |
+
|
| 98 |
+
Evaluate each method based on the following dimensions. For each dimension, consider the associated criteria and assign a score from 1 (poor) to 5 (excellent).
|
| 99 |
+
|
| 100 |
+
## Criteria Dimensions
|
| 101 |
+
|
| 102 |
+
**1. Assumptions:** Whether the foundational mathematical assumptions align with the intrinsic characteristics of the problem.
|
| 103 |
+
For instance, linear regression assumes linear relationships but fails to capture nonlinear dynamics (e.g., exponential growth). Similarly, deterministic models (e.g., ordinary differential equations) may overlook critical uncertainties in inherently stochastic systems (e.g., financial markets or biological processes). Misaligned assumptions risk oversimplification or systematic bias.
|
| 104 |
+
|
| 105 |
+
**2. Structure:** The mathematical framework’s ability to mirror the problem’s inherent logic, hierarchy, or spatiotemporal relationships.
|
| 106 |
+
Network-based problems (e.g., traffic flow or social interactions) demand graph theory or network flow models, while hierarchical systems (e.g., ecological food webs) may require multi-stage or layered modeling. A mismatch here—such as using static equations for time-dependent phenomena—renders the model structurally inadequate.
|
| 107 |
+
|
| 108 |
+
**3. Variables:** Compatibility between the model’s mathematical tools and the variable types in the problem (continuous, discrete, categorical, stochastic, etc.).
|
| 109 |
+
For example, logistic regression or decision trees suit categorical outcomes, while partial differential equations better model spatially continuous systems. High-dimensional sparse data (e.g., genomics) may necessitate dimensionality reduction (PCA) or sparse optimization, whereas rigid variable handling leads to inefficiency or inaccuracy.
|
| 110 |
+
|
| 111 |
+
**4. Dynamics:** Alignment of the model’s temporal or dynamic properties with the problem’s evolutionary behavior.
|
| 112 |
+
Short-term forecasting might use static models (e.g., linear regression), but long-term ecological or economic systems require dynamic frameworks (e.g., differential equations or agent-based models). Ignoring time delays (e.g., policy impacts in economics) or feedback loops often invalidates predictions.
|
| 113 |
+
|
| 114 |
+
**5. Solvability:** The existence and practicality of solutions under real-world constraints.
|
| 115 |
+
High-dimensional non-convex optimization problems (e.g., neural network training) may rely on heuristic algorithms (genetic algorithms) rather than exact solutions. Similarly, NP-hard problems (e.g., traveling salesman) demand approximations to balance computational feasibility and precision. Overly complex models risk theoretical elegance without actionable results.
|
| 116 |
+
|
| 117 |
+
## Instructions
|
| 118 |
+
1. For each method in the Method List, score its performance on **all** evaluation dimensions.
|
| 119 |
+
2. Return results in JSON format, including the method index and scores for each dimension.
|
| 120 |
+
|
| 121 |
+
## Output Example (Only return the JSON output, no other text)
|
| 122 |
+
```json
|
| 123 |
+
{{
|
| 124 |
+
"methods": [
|
| 125 |
+
{{
|
| 126 |
+
"method_index": 1,
|
| 127 |
+
"scores": {{
|
| 128 |
+
"Assumptions": 4,
|
| 129 |
+
"Structure": 3,
|
| 130 |
+
// Include other dimensions here
|
| 131 |
+
}}
|
| 132 |
+
}},
|
| 133 |
+
// Include other methods here
|
| 134 |
+
]
|
| 135 |
+
}}
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
## Required Output
|
| 139 |
+
Provide the JSON output below:
|
| 140 |
+
```json
|
| 141 |
+
"""
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
PROBLEM_MODELING_PROMPT = """\
|
| 145 |
+
# Reference Modeling Methods:
|
| 146 |
+
{modeling_methods}
|
| 147 |
+
|
| 148 |
+
# Mathematical Modeling Problem:
|
| 149 |
+
{modeling_problem}
|
| 150 |
+
|
| 151 |
+
# Problem Analysis:
|
| 152 |
+
{problem_analysis}
|
| 153 |
+
|
| 154 |
+
---
|
| 155 |
+
|
| 156 |
+
You are tasked with designing an innovative mathematical model to address the given problem. Begin by proposing a comprehensive model that integrates both theoretical and practical considerations, ensuring that the formulation is aligned with the problem's core objectives. This should include a clear set of assumptions that underpin the model, which may involve simplifications, approximations, or idealizations necessary to make the problem tractable, yet still retain fidelity to the real-world phenomena you aim to represent. Clearly define the variables, parameters, and constraints that will shape the mathematical formulation.
|
| 157 |
+
|
| 158 |
+
Next, develop the key equations and relationships that will govern the model. Pay attention to the interdependencies between the various components of the system. These could involve differential equations, algebraic relations, optimization criteria, or probabilistic models, depending on the nature of the problem. Be sure to consider how different aspects of the model might interact, and whether feedback loops or non-linearities should be incorporated. Explore potential novel formulations or extensions of existing models that could offer new insights into the problem's dynamics. If applicable, propose advanced methods such as multi-scale modeling, agent-based simulations, or data-driven approaches like machine learning to improve the model’s adaptability or accuracy.
|
| 159 |
+
|
| 160 |
+
Once the model structure is established, outline a clear strategy for solving it. This may involve analytical techniques such as closed-form solutions or approximations, numerical methods like finite element analysis or Monte Carlo simulations, or optimization algorithms for parameter estimation. Be explicit about the computational resources required and the level of precision expected. If the model is complex or high-dimensional, suggest ways to reduce the computational burden, such as dimensionality reduction, surrogate models, or parallelization techniques.
|
| 161 |
+
|
| 162 |
+
Additionally, consider how the model might evolve over time or under different conditions. Would the model require recalibration or adaptation in the face of changing circumstances? If applicable, provide strategies for sensitivity analysis to assess how the model responds to changes in its assumptions or parameters. Reflect on how the model’s predictions can be validated through empirical data or experimental results, ensuring that the model provides actionable insights and maintains real-world relevance.
|
| 163 |
+
|
| 164 |
+
Finally, propose avenues for further refinement or extension of the model. As new data becomes available or the problem context shifts, what adjustments would you make to improve the model's accuracy or applicability? Explore the possibility of incorporating new dimensions into the model, such as incorporating uncertainty quantification, dynamic optimization, or considering long-term sustainability of the proposed solutions. The ultimate goal is to develop a robust, flexible, and innovative model that not only addresses the problem at hand but also offers deeper insights into its underlying complexities.
|
| 165 |
+
|
| 166 |
+
{user_prompt}
|
| 167 |
+
|
| 168 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text, without any Markdown formatting or syntax. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 169 |
+
"""
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
PROBLEM_MODELING_CRITIQUE_PROMPT = """\
|
| 173 |
+
# Mathematical Modeling Problem:
|
| 174 |
+
{modeling_problem}
|
| 175 |
+
|
| 176 |
+
# Problem Analysis:
|
| 177 |
+
{problem_analysis}
|
| 178 |
+
|
| 179 |
+
# Modeling Solution:
|
| 180 |
+
{modeling_solution}
|
| 181 |
+
|
| 182 |
+
---
|
| 183 |
+
|
| 184 |
+
Critically examine the analysis results of the given mathematical modeling solution, focusing on the following aspects:
|
| 185 |
+
|
| 186 |
+
1. Problem Analysis and Understanding:
|
| 187 |
+
- Clarity of the problem definition: Does the solution demonstrate a clear and comprehensive understanding of the problem? Are all relevant variables, constraints, and objectives identified and well-defined? If not, which aspects of the problem may have been misunderstood or overlooked?
|
| 188 |
+
- Contextualization and framing: How well does the model account for the context in which the problem is situated? Are there any contextual factors that are essential but were not addressed?
|
| 189 |
+
- Scope of the problem: Is the problem's scope appropriately defined? Does the model include all the necessary details, or are there significant components that were neglected or oversimplified?
|
| 190 |
+
|
| 191 |
+
2. Model Development and Rigor:
|
| 192 |
+
- Formulation of the mathematical model: How well is the model constructed mathematically? Does it align with established modeling practices in the relevant domain? Are the mathematical formulations—such as equations, algorithms, or optimization methods—correct and robust?
|
| 193 |
+
- Modeling techniques: What modeling approaches or techniques were used (e.g., linear programming, system dynamics, statistical modeling, etc.)? Are they the most appropriate for the problem at hand? What alternative approaches could have been considered, and how might they impact the solution?
|
| 194 |
+
- Validation and verification: Was the model tested for consistency and accuracy? Are there validation steps in place to ensure the model behaves as expected under a variety of conditions? What specific methods were used for this validation (e.g., cross-validation, sensitivity analysis, etc.)?
|
| 195 |
+
|
| 196 |
+
3. Data and Results Analysis:
|
| 197 |
+
- Data quality and relevance: Were there any significant issues with data availability or quality that could have influenced the model's results?
|
| 198 |
+
- Interpretation of results: How well were the results analyzed and interpreted? Were the outcomes consistent with the problem's real-world implications? Are there any discrepancies between the model’s results and known empirical observations?
|
| 199 |
+
- Sensitivity and robustness analysis: Did the model undergo a sensitivity analysis to determine how the results vary with changes in input parameters? Were the results robust across different assumptions, and if not, what are the implications for the solution's reliability?
|
| 200 |
+
|
| 201 |
+
4. Assumptions and Limitations:
|
| 202 |
+
- Explicit and implicit assumptions: What assumptions underlie the model, and are they clearly articulated? Are these assumptions reasonable, and how might they affect the model's predictions? Were any critical assumptions left implicit or unaddressed?
|
| 203 |
+
- Limitations of the model: What limitations are inherent in the model, and how do they affect its validity and reliability? Are there elements of the problem that are inherently difficult or impossible to model with the chosen approach? Were simplifications made, and what are the trade-offs involved?
|
| 204 |
+
- Model boundaries: Does the model appropriately define its boundaries, and are there any critical factors that lie outside the model’s scope but could significantly influence the results?
|
| 205 |
+
|
| 206 |
+
5. Practicality and Applicability:
|
| 207 |
+
- Real-world applicability: To what extent can the model be applied to real-world scenarios?
|
| 208 |
+
- Practical implementation: How would this model be implemented in practice? What would be the required infrastructure, and what challenges would need to be addressed during implementation?
|
| 209 |
+
|
| 210 |
+
Critique the analysis without offering any constructive suggestions—your focus should solely be on highlighting weaknesses, gaps, and limitations within the approach and its execution.
|
| 211 |
+
"""
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
PROBLEM_MODELING_IMPROVEMENT_PROMPT = """\
|
| 215 |
+
# Mathematical Modeling Problem:
|
| 216 |
+
{modeling_problem}
|
| 217 |
+
|
| 218 |
+
# Problem Analysis:
|
| 219 |
+
{problem_analysis}
|
| 220 |
+
|
| 221 |
+
# Modeling Solution:
|
| 222 |
+
{modeling_solution}
|
| 223 |
+
|
| 224 |
+
# Modeling Solution Critique:
|
| 225 |
+
{modeling_solution_critique}
|
| 226 |
+
|
| 227 |
+
---
|
| 228 |
+
|
| 229 |
+
Refine and improve the existing modeling solution based on the critique provided. The goal is to enhance the formulation, structure, and overall effectiveness of the model while addressing the identified gaps, flaws, or limitations. Propose more appropriate assumptions, more robust mathematical techniques, or alternative modeling approaches if necessary. Focus on improving the model's relevance, accuracy, and computational feasibility while also ensuring its ability to capture the complexity of the problem in real-world contexts.
|
| 230 |
+
|
| 231 |
+
Provide a new version of the modeling solution that integrates these improvements directly. DO NOT mention any previous solution content and deficiencies.
|
| 232 |
+
|
| 233 |
+
{user_prompt}
|
| 234 |
+
|
| 235 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text, without any Markdown formatting or syntax. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 236 |
+
|
| 237 |
+
IMPROVED MODELING SOLUTION:
|
| 238 |
+
"""
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
DECOMPOSE_PRINCIPLE_PROMPT = """\
|
| 242 |
+
The solution to a mathematical modeling problem is typically broken down into a series of subtasks, each addressing a different aspect of the overall challenge. Based on the examples provided below, summarize what each subtask in tasks 1 through {tasknum} generally involves, with a focus on the principles of task decomposition in mathematical modeling.
|
| 243 |
+
|
| 244 |
+
<examples>
|
| 245 |
+
|
| 246 |
+
{examples}
|
| 247 |
+
|
| 248 |
+
</examples>
|
| 249 |
+
|
| 250 |
+
Requirements:
|
| 251 |
+
1. The summary should focus on the general methods and approaches used in mathematical modeling tasks, not tied to any specific examples or cases provided.
|
| 252 |
+
2. The response should not include any details specific to the examples in order to avoid providing any implicit solutions or insights from them.
|
| 253 |
+
3. The summary should present a theoretical description of the techniques used at each stage of task decomposition, without any reference to particular problems or contexts.
|
| 254 |
+
4. Each subtask should be described as comprehensively and in as much detail as possible within a single paragraph, capturing the essential steps and considerations for that task in a general mathematical modeling framework. The description should be comprehensive, highlighting the key methodologies without resorting to bullet points, numbered lists, or overly formalized structure.
|
| 255 |
+
5. Do not provide any form of examples or mention any instances.
|
| 256 |
+
"""
|
| 257 |
+
TASK_DECOMPOSE_WO_COO_PROMPT = """\
|
| 258 |
+
# Mathematical Modeling Problem:
|
| 259 |
+
{modeling_problem}
|
| 260 |
+
|
| 261 |
+
---
|
| 262 |
+
Please decompose the given modeling solution into {tasknum} distinct and well-defined subtasks that collectively contribute to the overall objective.
|
| 263 |
+
{user_prompt}
|
| 264 |
+
Each subtask should be described as comprehensively and in as much detail as possible within a single paragraph using plain text and seperated by '---' for each subtask.
|
| 265 |
+
"""
|
| 266 |
+
|
| 267 |
+
TASK_DECOMPOSE_PROMPT = """\
|
| 268 |
+
# Decompose Principle:
|
| 269 |
+
{decomposed_principle}
|
| 270 |
+
|
| 271 |
+
# Mathematical Modeling Problem:
|
| 272 |
+
{modeling_problem}
|
| 273 |
+
|
| 274 |
+
# Problem Analysis:
|
| 275 |
+
{problem_analysis}
|
| 276 |
+
|
| 277 |
+
# Modeling Solution:
|
| 278 |
+
{modeling_solution}
|
| 279 |
+
|
| 280 |
+
---
|
| 281 |
+
|
| 282 |
+
Please decompose the given modeling solution into {tasknum} distinct and well-defined subtasks that collectively contribute to the overall objective. These subtasks should be clearly separated in their focus, each addressing a specific aspect of the modeling process. The goal is to break down the solution into key stages or methodologies, ensuring that all components of the solution are covered without redundancy. For each subtask, the approach or technique should be explicitly described, detailing the specific data, algorithms, or models required. The decomposition should reflect a logical and comprehensive path toward completing the task, with each part having a clear purpose and contributing to the final result.
|
| 283 |
+
{user_prompt}
|
| 284 |
+
Each subtask should be described as comprehensively and in as much detail as possible within a single paragraph using plain text and seperated by '---' for each subtask. All the contents and details of the original solution need to be covered by the {tasknum} subtasks without omission.
|
| 285 |
+
"""
|
| 286 |
+
|
| 287 |
+
TASK_DESCRIPTION_PROMPT = """\
|
| 288 |
+
# Mathematical Modeling Problem:
|
| 289 |
+
{modeling_problem}
|
| 290 |
+
|
| 291 |
+
# Problem Analysis:
|
| 292 |
+
{problem_analysis}
|
| 293 |
+
|
| 294 |
+
# Modeling Solution:
|
| 295 |
+
{modeling_solution}
|
| 296 |
+
|
| 297 |
+
# Decomposed Subtasks:
|
| 298 |
+
{decomposed_subtasks}
|
| 299 |
+
|
| 300 |
+
---
|
| 301 |
+
|
| 302 |
+
You are tasked with refining and improving the description of subtask {task_i} to ensure it is more detailed, clear, and focused. Provide a precise and comprehensive explanation of the task, specifically elaborating on its scope, goals, and methodology without venturing into other subtasks. Make sure the description includes clear and concise language that defines the necessary steps, techniques, or approaches required for this subtask. If applicable, specify the data inputs, tools, or models to be used, but do not introduce analysis, results, or discussions related to other components of the modeling process. The goal is to enhance the clarity, depth, and precision of this subtask description, ensuring it is fully understood on its own without needing further explanation.
|
| 303 |
+
The description of subtask {task_i} should be as comprehensive and in as much detail as possible within a single paragraph using plain text.
|
| 304 |
+
"""
|
| 305 |
+
|
| 306 |
+
COO_PROMPT= "You are collaborating as part of a multi-agent system to solve a complex mathematical modeling problem. Each agent is responsible for a specific task, and some preprocessing or related tasks may have already been completed by other agents. It is crucial that you **do not repeat any steps that have already been addressed** by other agents. Instead, rely on their outputs when necessary and focus solely on the specific aspects of the task assigned to you."
|
| 307 |
+
|
| 308 |
+
TASK_ANALYSIS_PROMPT = """\
|
| 309 |
+
# Task Description:
|
| 310 |
+
{task_description}
|
| 311 |
+
|
| 312 |
+
---
|
| 313 |
+
{prompt}
|
| 314 |
+
{coo_prompt}
|
| 315 |
+
Provide a thorough and nuanced analysis of the task at hand, drawing on the task description as the primary source of context. Begin by elucidating the core objectives and scope of the task, outlining its significance within the larger context of the project or research. Consider the potential impact or outcomes that are expected from the task, whether they relate to solving a specific problem, advancing knowledge, or achieving a particular practical application. Identify any challenges that may arise during the task execution, including technical, logistical, or theoretical constraints, and describe how these might influence the process or outcomes. In addition, carefully highlight any assumptions that are being made about the data, environment, or system involved in the task, and discuss any external factors that could shape the understanding or execution of the task. Ensure that the analysis is framed in a way that will guide future steps or inform the next stages of work.
|
| 316 |
+
{user_prompt}
|
| 317 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text and LaTeX for formulas only, without any Markdown formatting or syntax. Written as one paragraph. Avoid structuring your answer in bullet points or numbered lists.
|
| 318 |
+
"""
|
| 319 |
+
|
| 320 |
+
TASK_FORMULAS_PROMPT = """\
|
| 321 |
+
# Reference Modeling Methods:
|
| 322 |
+
{modeling_methods}
|
| 323 |
+
|
| 324 |
+
{data_summary}
|
| 325 |
+
|
| 326 |
+
# Task Description:
|
| 327 |
+
{task_description}
|
| 328 |
+
|
| 329 |
+
# Task Analysis:
|
| 330 |
+
{task_analysis}
|
| 331 |
+
|
| 332 |
+
---
|
| 333 |
+
{prompt}
|
| 334 |
+
{coo_prompt}
|
| 335 |
+
|
| 336 |
+
You are tasked with developing a set of precise, insightful, and comprehensive mathematical formulas that effectively model the problem described in the task. Begin by conducting an in-depth analysis of the system, process, or phenomenon outlined, identifying all relevant variables, their interdependencies, and the fundamental principles, laws, or constraints that govern the behavior of the system, as applicable in the relevant field. Clearly define all variables, constants, and parameters, and explicitly state any assumptions, approximations, or simplifications made during the formulation process, including any boundary conditions or initial conditions if necessary.
|
| 337 |
+
|
| 338 |
+
Ensure the formulation considers the full scope of the problem, and if applicable, incorporate innovative mathematical techniques. Your approach should be well-suited for practical computational implementation, addressing potential numerical challenges, stability concerns, or limitations in simulations. Pay careful attention to the dimensional consistency and units of all terms to guarantee physical or conceptual validity, while remaining true to the theoretical foundations of the problem.
|
| 339 |
+
|
| 340 |
+
In the process of deriving the mathematical models, provide a clear, step-by-step explanation of the reasoning behind each formula, highlighting the derivation of key expressions and discussing any assumptions or trade-offs that are made. Identify any potential sources of uncertainty, limitations, or approximations inherent in the model, and provide guidance on how to handle these within the modeling framework.
|
| 341 |
+
|
| 342 |
+
The resulting equations should be both flexible and scalable, allowing for adaptation to different scenarios or the ability to be tested against experimental or real-world data. Strive to ensure that your model is not only rigorous but also interpretable, balancing complexity with practical applicability. List all modeling equations clearly in LaTeX format, ensuring proper mathematical notation and clarity of presentation. Aim for a model that is both theoretically sound and practically relevant, offering a balanced approach to complexity and tractability in its use.
|
| 343 |
+
{user_prompt}
|
| 344 |
+
Respond as comprehensively and in as much detail as possible, ensuring clarity, depth, and rigor throughout. Using plain text and LaTeX for formulas. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 345 |
+
"""
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
TASK_FORMULAS_CRITIQUE_PROMPT = """\
|
| 349 |
+
{data_summary}
|
| 350 |
+
|
| 351 |
+
# Task Description:
|
| 352 |
+
{task_description}
|
| 353 |
+
|
| 354 |
+
# Task Analysis:
|
| 355 |
+
{task_analysis}
|
| 356 |
+
|
| 357 |
+
# Task Modeling Formulas:
|
| 358 |
+
{modeling_formulas}
|
| 359 |
+
|
| 360 |
+
---
|
| 361 |
+
|
| 362 |
+
The goal of this task is to critically evaluate the modeling formulas used to represent a given mathematical modeling problem. Your analysis should address the following dimensions: accuracy and rigor, innovation and insight, and the applicability of the models to real-world scenarios.
|
| 363 |
+
|
| 364 |
+
1. Accuracy and Rigor:
|
| 365 |
+
|
| 366 |
+
- Formula Integrity:
|
| 367 |
+
Evaluate whether the mathematical models and the corresponding formulas are mathematically sound and consistent with the underlying assumptions of the problem. Are the formulas properly derived, free from logical errors, and reflective of the relevant domain knowledge?
|
| 368 |
+
- Are any simplifications or approximations made, and if so, are they justifiable within the context of the model's scope?
|
| 369 |
+
- Examine the assumptions made in formulating the model. Are these assumptions realistic, and how do they affect the model’s precision and robustness?
|
| 370 |
+
|
| 371 |
+
2. Innovation and Insight:
|
| 372 |
+
|
| 373 |
+
- Novelty of Approach:
|
| 374 |
+
Critique the originality of the modeling approach. Does the model present a new or unconventional way of solving the problem, or does it simply rely on established methodologies without offering new insights?
|
| 375 |
+
- Consider whether any innovative methods, such as the introduction of novel variables or the use of innovative computational techniques, contribute to improving the model.
|
| 376 |
+
|
| 377 |
+
- Theoretical Insight:
|
| 378 |
+
Evaluate the depth of the theoretical insights provided by the model. Does it offer a fresh perspective or new understanding of the problem? How well does it illuminate the key dynamics and relationships within the system under study?
|
| 379 |
+
- Does the model reveal previously unnoticed phenomena, or does it suggest new directions for further research?
|
| 380 |
+
|
| 381 |
+
- Integration of Existing Knowledge:
|
| 382 |
+
Assess the extent to which the model integrates existing mathematical, theoretical, and empirical work. Does it build on prior research, and if so, does it do so in a way that adds substantial value or clarity? Are there gaps where additional cross-disciplinary knowledge could enhance the model?
|
| 383 |
+
|
| 384 |
+
---
|
| 385 |
+
|
| 386 |
+
3. Applicable:
|
| 387 |
+
|
| 388 |
+
- Real-World Relevance:
|
| 389 |
+
Evaluate the model’s practical applicability. How well does it apply to real-world problems, and to what extent does it provide actionable insights for decision-making or problem-solving in the field?
|
| 390 |
+
|
| 391 |
+
Critique the analysis without offering any constructive suggestions—your focus should solely be on highlighting weaknesses, gaps, and limitations within the formulas.
|
| 392 |
+
"""
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
TASK_FORMULAS_IMPROVEMENT_PROMPT = """\
|
| 396 |
+
{data_summary}
|
| 397 |
+
|
| 398 |
+
# Task Description:
|
| 399 |
+
{task_description}
|
| 400 |
+
|
| 401 |
+
# Task Analysis:
|
| 402 |
+
{task_analysis}
|
| 403 |
+
|
| 404 |
+
# Task Modeling Formulas:
|
| 405 |
+
{modeling_formulas}
|
| 406 |
+
|
| 407 |
+
# Task Modeling Formulas Critique:
|
| 408 |
+
{modeling_formulas_critique}
|
| 409 |
+
|
| 410 |
+
---
|
| 411 |
+
|
| 412 |
+
Based on the provided critique and analysis, refine the existing modeling formulas to address the identified limitations and gaps.
|
| 413 |
+
|
| 414 |
+
Respond as comprehensively and in as much detail as possible, ensuring clarity, depth, and rigor throughout. Using plain text and LaTeX for formulas. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 415 |
+
{user_prompt}
|
| 416 |
+
Provide a new version of the task modeling formulas that integrates these improvements directly. DO NOT mention any previous formulas content and deficiencies.
|
| 417 |
+
|
| 418 |
+
IMPROVED TASK MODELING FORMULAS:
|
| 419 |
+
"""
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
# TASK_MODELING_PROMPT = """\
|
| 423 |
+
# {data_summary}
|
| 424 |
+
|
| 425 |
+
# # Task Description:
|
| 426 |
+
# {task_description}
|
| 427 |
+
|
| 428 |
+
# # Task Analysis:
|
| 429 |
+
# {task_analysis}
|
| 430 |
+
|
| 431 |
+
# # Task Modeling Formulas:
|
| 432 |
+
# {modeling_formulas}
|
| 433 |
+
|
| 434 |
+
# ---
|
| 435 |
+
|
| 436 |
+
# You are tasked with designing an innovative and advanced mathematical model to address the given problem. Begin by proposing a comprehensive model that integrates both theoretical and practical considerations, ensuring that the formulation is aligned with the problem's core objectives. This should include a clear set of assumptions that underpin the model, which may involve simplifications, approximations, or idealizations necessary to make the problem tractable, yet still retain fidelity to the real-world phenomena you aim to represent. Clearly define the variables, parameters, and constraints that will shape the mathematical formulation.
|
| 437 |
+
|
| 438 |
+
# Next, develop the key equations and relationships that will govern the model. Pay attention to the interdependencies between the various components of the system. These could involve differential equations, algebraic relations, optimization criteria, or probabilistic models, depending on the nature of the problem. Be sure to consider how different aspects of the model might interact, and whether feedback loops or non-linearities should be incorporated. Explore potential novel formulations or extensions of existing models that could offer new insights into the problem's dynamics. If applicable, propose advanced methods such as multi-scale modeling, agent-based simulations, or data-driven approaches like machine learning to improve the model’s adaptability or accuracy.
|
| 439 |
+
|
| 440 |
+
# Once the model structure is established, outline a clear strategy for solving it. This may involve analytical techniques such as closed-form solutions or approximations, numerical methods like finite element analysis or Monte Carlo simulations, or optimization algorithms for parameter estimation. Be explicit about the computational resources required and the level of precision expected. If the model is complex or high-dimensional, suggest ways to reduce the computational burden, such as dimensionality reduction, surrogate models, or parallelization techniques.
|
| 441 |
+
|
| 442 |
+
# Additionally, consider how the model might evolve over time or under different conditions. Would the model require recalibration or adaptation in the face of changing circumstances? If applicable, provide strategies for sensitivity analysis to assess how the model responds to changes in its assumptions or parameters. Reflect on how the model’s predictions can be validated through empirical data or experimental results, ensuring that the model provides actionable insights and maintains real-world relevance.
|
| 443 |
+
|
| 444 |
+
# Finally, propose avenues for further refinement or extension of the model. As new data becomes available or the problem context shifts, what adjustments would you make to improve the model's accuracy or applicability? Explore the possibility of incorporating new dimensions into the model, such as incorporating uncertainty quantification, dynamic optimization, or considering long-term sustainability of the proposed solutions. The ultimate goal is to develop a robust, flexible, and innovative model that not only addresses the problem at hand but also offers deeper insights into its underlying complexities.
|
| 445 |
+
|
| 446 |
+
# Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text, without any Markdown formatting or syntax. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 447 |
+
# """
|
| 448 |
+
|
| 449 |
+
TASK_MODELING_PROMPT = """\
|
| 450 |
+
{data_summary}
|
| 451 |
+
|
| 452 |
+
# Task Description:
|
| 453 |
+
{task_description}
|
| 454 |
+
|
| 455 |
+
# Task Analysis:
|
| 456 |
+
{task_analysis}
|
| 457 |
+
|
| 458 |
+
# Task Modeling Formulas:
|
| 459 |
+
{modeling_formulas}
|
| 460 |
+
|
| 461 |
+
---
|
| 462 |
+
{prompt}
|
| 463 |
+
{coo_prompt}
|
| 464 |
+
|
| 465 |
+
Please continue the modeling formula section by building upon the previous introduction to the formula. Provide comprehensive and detailed explanations and instructions that elaborate on each component of the formula. Describe the modeling process thoroughly, including the underlying assumptions, step-by-step derivations, and any necessary instructions for application. Expand on the formula by incorporating relevant mathematical expressions where appropriate, ensuring that each addition enhances the reader’s understanding of the model. Make sure to seamlessly integrate the new content with the existing section, maintaining a natural flow and avoiding any repetition or conflicts with previously covered material. Your continuation should offer a clear and in-depth exploration of the modeling formula, providing all necessary details to facilitate a complete and coherent understanding of the modeling process.
|
| 466 |
+
{user_prompt}
|
| 467 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text, without any Markdown formatting or syntax. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 468 |
+
"""
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
TASK_MODELING_CRITIQUE_PROMPT = """\
|
| 472 |
+
{data_summary}
|
| 473 |
+
|
| 474 |
+
# Task Description:
|
| 475 |
+
{task_description}
|
| 476 |
+
|
| 477 |
+
# Task Analysis:
|
| 478 |
+
{task_analysis}
|
| 479 |
+
|
| 480 |
+
# Task Modeling Formulas:
|
| 481 |
+
{modeling_formulas}
|
| 482 |
+
|
| 483 |
+
# Task Modeling Process:
|
| 484 |
+
{modeling_process}
|
| 485 |
+
|
| 486 |
+
---
|
| 487 |
+
|
| 488 |
+
Critically examine the analysis results of the given mathematical modeling solution, focusing on the following aspects:
|
| 489 |
+
|
| 490 |
+
1. Problem Analysis and Understanding:
|
| 491 |
+
- Clarity of the problem definition: Does the solution demonstrate a clear and comprehensive understanding of the problem? Are all relevant variables, constraints, and objectives identified and well-defined? If not, which aspects of the problem may have been misunderstood or overlooked?
|
| 492 |
+
- Contextualization and framing: How well does the model account for the context in which the problem is situated? Are there any contextual factors that are essential but were not addressed?
|
| 493 |
+
- Scope of the problem: Is the problem's scope appropriately defined? Does the model include all the necessary details, or are there significant components that were neglected or oversimplified?
|
| 494 |
+
|
| 495 |
+
2. Model Development and Rigor:
|
| 496 |
+
- Formulation of the mathematical model: How well is the model constructed mathematically? Does it align with established modeling practices in the relevant domain? Are the mathematical formulations—such as equations, algorithms, or optimization methods—correct and robust?
|
| 497 |
+
- Modeling techniques: What modeling approaches or techniques were used (e.g., linear programming, system dynamics, statistical modeling, etc.)? Are they the most appropriate for the problem at hand? What alternative approaches could have been considered, and how might they impact the solution?
|
| 498 |
+
- Validation and verification: Was the model tested for consistency and accuracy? Are there validation steps in place to ensure the model behaves as expected under a variety of conditions? What specific methods were used for this validation (e.g., cross-validation, sensitivity analysis, etc.)?
|
| 499 |
+
|
| 500 |
+
3. Data and Results Analysis:
|
| 501 |
+
- Data quality and relevance: Were there any significant issues with data availability or quality that could have influenced the model's results?
|
| 502 |
+
- Interpretation of results: How well were the results analyzed and interpreted? Were the outcomes consistent with the problem's real-world implications? Are there any discrepancies between the model’s results and known empirical observations?
|
| 503 |
+
- Sensitivity and robustness analysis: Did the model undergo a sensitivity analysis to determine how the results vary with changes in input parameters? Were the results robust across different assumptions, and if not, what are the implications for the solution's reliability?
|
| 504 |
+
|
| 505 |
+
4. Assumptions and Limitations:
|
| 506 |
+
- Explicit and implicit assumptions: What assumptions underlie the model, and are they clearly articulated? Are these assumptions reasonable, and how might they affect the model's predictions? Were any critical assumptions left implicit or unaddressed?
|
| 507 |
+
- Limitations of the model: What limitations are inherent in the model, and how do they affect its validity and reliability? Are there elements of the problem that are inherently difficult or impossible to model with the chosen approach? Were simplifications made, and what are the trade-offs involved?
|
| 508 |
+
- Model boundaries: Does the model appropriately define its boundaries, and are there any critical factors that lie outside the model’s scope but could significantly influence the results?
|
| 509 |
+
|
| 510 |
+
5. Practicality and Applicability:
|
| 511 |
+
- Real-world applicability: To what extent can the model be applied to real-world scenarios?
|
| 512 |
+
- Practical implementation: How would this model be implemented in practice? What would be the required infrastructure, and what challenges would need to be addressed during implementation?
|
| 513 |
+
|
| 514 |
+
Critique the analysis without offering any constructive suggestions—your focus should solely be on highlighting weaknesses, gaps, and limitations within the approach and its execution.
|
| 515 |
+
"""
|
| 516 |
+
|
| 517 |
+
|
| 518 |
+
TASK_MODELING_IMPROVEMENT_PROMPT = """\
|
| 519 |
+
{data_summary}
|
| 520 |
+
|
| 521 |
+
# Task Description:
|
| 522 |
+
{task_description}
|
| 523 |
+
|
| 524 |
+
# Task Analysis:
|
| 525 |
+
{task_analysis}
|
| 526 |
+
|
| 527 |
+
# Task Modeling Formulas:
|
| 528 |
+
{modeling_formulas}
|
| 529 |
+
|
| 530 |
+
# Task Modeling Process:
|
| 531 |
+
{modeling_process}
|
| 532 |
+
|
| 533 |
+
# Task Modeling Process Critique:
|
| 534 |
+
{modeling_process_critique}
|
| 535 |
+
|
| 536 |
+
---
|
| 537 |
+
|
| 538 |
+
Refine and improve the existing modeling process based on the critique provided. The goal is to enhance the formulation, structure, and overall effectiveness of the model while addressing the identified gaps, flaws, or limitations. Propose more appropriate assumptions, more robust mathematical techniques, or alternative modeling approaches if necessary. Focus on improving the model's relevance, accuracy, and computational feasibility while also ensuring its ability to capture the complexity of the problem in real-world contexts.
|
| 539 |
+
|
| 540 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text, without any Markdown formatting or syntax. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 541 |
+
{user_prompt}
|
| 542 |
+
Provide a new version of the modeling process that integrates these improvements directly. DO NOT mention any previous process content and deficiencies.
|
| 543 |
+
|
| 544 |
+
IMPROVED MODELING PROCESS:
|
| 545 |
+
"""
|
| 546 |
+
|
| 547 |
+
TASK_CODING_PROMPT = """\
|
| 548 |
+
# Dataset Path:
|
| 549 |
+
{data_file}
|
| 550 |
+
|
| 551 |
+
# Data Description:
|
| 552 |
+
{data_summary}
|
| 553 |
+
|
| 554 |
+
# Variable Description:
|
| 555 |
+
{variable_description}
|
| 556 |
+
|
| 557 |
+
# Other files (Generated by Other Agents):
|
| 558 |
+
{dependent_file_prompt}
|
| 559 |
+
|
| 560 |
+
# Task Description:
|
| 561 |
+
{task_description}
|
| 562 |
+
|
| 563 |
+
# Task Analysis:
|
| 564 |
+
{task_analysis}
|
| 565 |
+
|
| 566 |
+
# Task Modeling Formulas:
|
| 567 |
+
{modeling_formulas}
|
| 568 |
+
|
| 569 |
+
# Task Modeling Process:
|
| 570 |
+
{modeling_process}
|
| 571 |
+
|
| 572 |
+
# Code Template:
|
| 573 |
+
{code_template}
|
| 574 |
+
|
| 575 |
+
---
|
| 576 |
+
|
| 577 |
+
## Role & Collaboration:
|
| 578 |
+
You are an expert programmer working as part of a multi-agent system. Your role is to implement the code based on the provided dataset (**refer to the Dataset Path, Dataset Description, and Variable Description**) **or preprocessed files generated by other agents** (**refer to "Other Files"**), along with the modeling process and given code template. Other agents will use your results to make decisions, but they will **not** review your code. Therefore, it is crucial that:
|
| 579 |
+
1. **Ensure the code is executable** and will successfully run without errors, producing the expected results. **It should be tested to verify it works in the intended environment**.
|
| 580 |
+
2. **Reuse files from "Other Files" whenever possible** instead of redoing tasks that have already been completed by other agents.
|
| 581 |
+
3. **All data processing steps must save the processed results to local files (CSV, JSON, or pickle) for easy access by other agents.**
|
| 582 |
+
4. **The output should be as detailed as possible**, including intermediate results and final outputs.
|
| 583 |
+
5. **Ensure transparency** by logging key computation steps and providing clear outputs.
|
| 584 |
+
|
| 585 |
+
## Implementation Guidelines:
|
| 586 |
+
- **Prioritize using files from "Other Files" before processing raw data** to avoid redundant computation.
|
| 587 |
+
- Follow the provided **modeling formulas** and **modeling process** precisely.
|
| 588 |
+
- The **code must be executable**: ensure that the Python code you generate runs without errors. Do not just focus on producing the correct output format; **focus on producing a working solution** that can be executed successfully in a Python environment.
|
| 589 |
+
- **Store intermediate and final data processing results to local** in appropriate formats (e.g., CSV, JSON, or pickle).
|
| 590 |
+
- Provide **detailed print/logging outputs** to ensure that other agents can understand the results without needing to read the code.
|
| 591 |
+
{user_prompt}
|
| 592 |
+
|
| 593 |
+
## Expected Response Format:
|
| 594 |
+
You **MUST** return the Python implementation in the following format:
|
| 595 |
+
```python
|
| 596 |
+
# Here is the Python code.
|
| 597 |
+
"""
|
| 598 |
+
|
| 599 |
+
TASK_CODING_WO_COO_PROMPT = """\
|
| 600 |
+
# Dataset Path:
|
| 601 |
+
{data_file}
|
| 602 |
+
|
| 603 |
+
# Data Description:
|
| 604 |
+
{data_summary}
|
| 605 |
+
|
| 606 |
+
# Variable Description:
|
| 607 |
+
{variable_description}
|
| 608 |
+
|
| 609 |
+
# Task Description:
|
| 610 |
+
{task_description}
|
| 611 |
+
|
| 612 |
+
# Task Analysis:
|
| 613 |
+
{task_analysis}
|
| 614 |
+
|
| 615 |
+
# Task Modeling Formulas:
|
| 616 |
+
{modeling_formulas}
|
| 617 |
+
|
| 618 |
+
# Task Modeling Process:
|
| 619 |
+
{modeling_process}
|
| 620 |
+
|
| 621 |
+
# Code Template:
|
| 622 |
+
{code_template}
|
| 623 |
+
|
| 624 |
+
---
|
| 625 |
+
|
| 626 |
+
## Role & Collaboration:
|
| 627 |
+
You are an expert programmer. Your role is to implement the code based on the provided dataset (**refer to the Dataset Path, Dataset Description, and Variable Description**), along with the modeling process and given code template. It is crucial that:
|
| 628 |
+
1. **Ensure the code is executable** and will successfully run without errors, producing the expected results. **It should be tested to verify it works in the intended environment**.
|
| 629 |
+
2. **All data processing steps must save the processed results to local files (CSV, JSON, or pickle).**
|
| 630 |
+
3. **The output should be as detailed as possible**, including intermediate results and final outputs.
|
| 631 |
+
4. **Ensure transparency** by logging key computation steps and providing clear outputs.
|
| 632 |
+
|
| 633 |
+
## Implementation Guidelines:
|
| 634 |
+
- Follow the provided **modeling formulas** and **modeling process** precisely.
|
| 635 |
+
- The **code must be executable**: ensure that the Python code you generate runs without errors. Do not just focus on producing the correct output format; **focus on producing a working solution** that can be executed successfully in a Python environment.
|
| 636 |
+
- **Store intermediate and final data processing results to local** in appropriate formats (e.g., CSV, JSON, or pickle).
|
| 637 |
+
- Provide **detailed print/logging outputs** to ensure that other people can understand the results without needing to read the code.
|
| 638 |
+
{user_prompt}
|
| 639 |
+
|
| 640 |
+
## Expected Response Format:
|
| 641 |
+
You **MUST** return the Python implementation in the following format:
|
| 642 |
+
```python
|
| 643 |
+
# Here is the Python code.
|
| 644 |
+
"""
|
| 645 |
+
|
| 646 |
+
TASK_CODING_DEBUG_PROMPT = """\
|
| 647 |
+
# Code Template:
|
| 648 |
+
{code_template}
|
| 649 |
+
|
| 650 |
+
# Modeling Process:
|
| 651 |
+
{modeling_process}
|
| 652 |
+
|
| 653 |
+
# Current Code:
|
| 654 |
+
{code}
|
| 655 |
+
|
| 656 |
+
However, there are some bugs in this version. Here is the execution result:
|
| 657 |
+
# Execution Result:
|
| 658 |
+
{observation}
|
| 659 |
+
|
| 660 |
+
---
|
| 661 |
+
|
| 662 |
+
You are a helpful programming expert. Based on the provided execution result, please revise the script to fix these bugs. Your task is to address the error indicated in the result, and refine or modify the code as needed to ensure it works correctly.
|
| 663 |
+
{user_prompt}
|
| 664 |
+
Please respond exactly in the following format:
|
| 665 |
+
```python
|
| 666 |
+
# Provide the corrected python code here.
|
| 667 |
+
```
|
| 668 |
+
"""
|
| 669 |
+
|
| 670 |
+
|
| 671 |
+
TASK_RESULT_PROMPT = """\
|
| 672 |
+
# Task Description:
|
| 673 |
+
{task_description}
|
| 674 |
+
|
| 675 |
+
# Task Analysis:
|
| 676 |
+
{task_analysis}
|
| 677 |
+
|
| 678 |
+
# Task Modeling Formulas:
|
| 679 |
+
{task_formulas}
|
| 680 |
+
|
| 681 |
+
# Task Modeling:
|
| 682 |
+
{task_modeling}
|
| 683 |
+
|
| 684 |
+
---
|
| 685 |
+
|
| 686 |
+
Based on the task description, analysis, and modeling framework, present a comprehensive and detailed account of the intermediate results, calculations, and outcomes generated during the task. Clearly articulate the results of any simulations, experiments, or calculations, providing numerical values, data trends, or statistical measures as necessary. If visual representations such as graphs, charts, or tables were used to communicate the results, ensure they are clearly labeled and explained, highlighting their relevance to the overall task. Discuss the intermediate steps or processes that led to the results, including any transformations or assumptions made during calculations. If applicable, compare and contrast these results with expected outcomes or previously known results to gauge the task’s success. Provide a thoughtful interpretation of the findings, considering how they contribute to advancing understanding or solving the problem at hand, and highlight any areas where further investigation or refinement may be needed.
|
| 687 |
+
{user_prompt}
|
| 688 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text and LaTeX for formulas only, without any Markdown formatting or syntax. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 689 |
+
"""
|
| 690 |
+
|
| 691 |
+
TASK_RESULT_WITH_CODE_PROMPT = """\
|
| 692 |
+
# Task Description:
|
| 693 |
+
{task_description}
|
| 694 |
+
|
| 695 |
+
# Task Analysis:
|
| 696 |
+
{task_analysis}
|
| 697 |
+
|
| 698 |
+
# Task Modeling Formulas:
|
| 699 |
+
{task_formulas}
|
| 700 |
+
|
| 701 |
+
# Task Modeling:
|
| 702 |
+
{task_modeling}
|
| 703 |
+
|
| 704 |
+
# Code Execution Result:
|
| 705 |
+
{execution_result}
|
| 706 |
+
|
| 707 |
+
---
|
| 708 |
+
|
| 709 |
+
Based on the task description, analysis, modeling framework, and code execution result, present a comprehensive and detailed account of the intermediate results, calculations, and outcomes generated during the task. Clearly articulate the results of any computations or operations performed, providing numerical values, data trends, or statistical measures as necessary. If visual representations such as graphs, charts, or tables were used to communicate the results, ensure they are clearly labeled and explained, highlighting their relevance to the overall task. Discuss the intermediate steps or processes that led to the results, including any transformations or assumptions made during calculations. If applicable, compare and contrast these results with expected outcomes or previously known results to gauge the task’s success. Provide a thoughtful interpretation of the findings, considering how they contribute to advancing understanding or solving the problem at hand, and highlight any areas where further investigation or refinement may be needed.
|
| 710 |
+
{user_prompt}
|
| 711 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text and LaTeX for formulas only, without any Markdown formatting or syntax. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 712 |
+
"""
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
TASK_ANSWER_PROMPT = """\
|
| 716 |
+
# Task Description:
|
| 717 |
+
{task_description}
|
| 718 |
+
|
| 719 |
+
# Task Analysis:
|
| 720 |
+
{task_analysis}
|
| 721 |
+
|
| 722 |
+
# Task Modeling Formulas:
|
| 723 |
+
{task_formulas}
|
| 724 |
+
|
| 725 |
+
# Task Modeling:
|
| 726 |
+
{task_modeling}
|
| 727 |
+
|
| 728 |
+
# Task Result:
|
| 729 |
+
{task_result}
|
| 730 |
+
|
| 731 |
+
---
|
| 732 |
+
|
| 733 |
+
Craft a comprehensive and insightful answer section that synthesizes the findings presented in the results section to directly address the research questions and objectives outlined at the outset of the study. Begin by clearly stating the primary conclusions drawn from the analysis, ensuring that each conclusion is explicitly linked to specific aspects of the results. Discuss how these conclusions validate or challenge the initial hypotheses or theoretical expectations, providing a coherent narrative that illustrates the progression from data to insight.
|
| 734 |
+
|
| 735 |
+
Evaluate the effectiveness and reliability of the mathematical models employed, highlighting strengths such as predictive accuracy, robustness, or computational efficiency. Address any limitations encountered during the modeling process, explaining how they may impact the validity of the conclusions and suggesting potential remedies or alternative approaches. Consider the sensitivity of the model to various parameters and the extent to which the results are generalizable to other contexts or applications.
|
| 736 |
+
|
| 737 |
+
Analyze potential biases that may have influenced the results, including data bias, model bias, and computational bias. Discuss whether the dataset is representative of the problem space and whether any imbalances, selection biases, or sampling limitations might have affected the conclusions. Examine modeling assumptions, parameter choices, and architectural constraints that could introduce systematic deviations in the results. Assess how numerical precision, algorithmic approximations, or implementation details might influence the stability and fairness of the model’s predictions.
|
| 738 |
+
|
| 739 |
+
Discuss strategies to mitigate identified biases and improve the reliability of the conclusions. Consider adjustments in data preprocessing, such as resampling, normalization, or augmentation, to address distribution imbalances. Explore refinements to the modeling process, including regularization techniques, fairness constraints, and sensitivity analyses, to ensure robustness across different scenarios. Evaluate the impact of alternative modeling approaches and discuss the extent to which the proposed methods can generalize beyond the given dataset or problem context.
|
| 740 |
+
|
| 741 |
+
Explore the broader implications of the findings for the field of study, identifying how they contribute to existing knowledge, inform future research directions, or influence practical applications. Discuss any unexpected outcomes and their significance, offering interpretations that may reveal new avenues for exploration or theoretical development. Reflect on the societal, economic, or environmental relevance of the results, if applicable, and propose recommendations based on the study’s insights.
|
| 742 |
+
|
| 743 |
+
Conclude the section by summarizing the key takeaways, emphasizing the contribution of the research to solving the problem at hand, and outlining the next steps for further investigation or implementation. Ensure that the discussion is logically structured, with each paragraph building upon the previous ones to form a cohesive and persuasive argument that underscores the study’s value and impact.
|
| 744 |
+
|
| 745 |
+
The content of this Task Answer section should be distinct and not merely a repetition of the Task Result section. Ensure that there is no duplication.
|
| 746 |
+
|
| 747 |
+
{user_prompt}
|
| 748 |
+
|
| 749 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text and LaTeX for formulas only, without any Markdown formatting or syntax. Written as one or more cohesive paragraphs. Avoid structuring your answer in bullet points or numbered lists.
|
| 750 |
+
"""
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
CREATE_CHART_PROMPT = """\
|
| 754 |
+
## Instruction
|
| 755 |
+
Create a highly detailed and comprehensive chart that effectively visualizes the complex mathematical relationships and insights presented in the provided mathematical modeling paper. Begin by selecting the most appropriate type of chart—such as a line graph, bar chart, scatter plot, heatmap, or 3D surface plot—based on the nature of the data and the specific relationships being analyzed. Clearly define the variables involved, including their units and scales, and incorporate any derived metrics that enhance interpretability. Ensure that the axes are labeled accurately and descriptively, with appropriate units and scales, whether linear or logarithmic, to best represent the data distribution and relationships. Include a clear and concise legend that distinguishes between different datasets or variables, using distinct colors or patterns that are both aesthetically pleasing and easily distinguishable. Utilize gridlines to aid in the accurate reading of values, and choose a color scheme that enhances readability while maintaining visual appeal.
|
| 756 |
+
|
| 757 |
+
Emphasize the core purpose of the chart, whether it is to highlight trends over time, compare different values, show distributions, illustrate correlations, validate theoretical models, or support key arguments within the paper. Articulate the intended message of the chart clearly, ensuring that every design choice—from the type of chart to the specific visual elements used—aligns with the objectives of the mathematical modeling paper. Incorporate multiple lines or bars if comparing different datasets, use shading or contouring for density representation, and add error bars to indicate uncertainty where applicable. Include annotations to highlight significant data points, trends, or anomalies that are critical to the analysis, providing context and explanations that guide the viewer’s understanding.
|
| 758 |
+
|
| 759 |
+
Balance aesthetics with functionality by selecting colors and contrasts that not only make the chart visually compelling but also enhance readability and comprehension. Avoid unnecessary complexity by keeping the design clean and focused, ensuring that the chart remains clear and easy to interpret without sacrificing accuracy or depth of information. If beneficial, incorporate supplementary visual aids such as trend lines, regression curves, or overlays of empirical and theoretical results to strengthen the analysis and provide additional layers of insight. The final chart should serve as a precise and compelling visualization that effectively conveys the mathematical insights, facilitates understanding, and robustly supports the overall narrative and conclusions of the mathematical modeling paper.
|
| 760 |
+
|
| 761 |
+
{user_prompt}
|
| 762 |
+
|
| 763 |
+
## Paper Content
|
| 764 |
+
<paper>
|
| 765 |
+
{paper_content}
|
| 766 |
+
</paper>
|
| 767 |
+
|
| 768 |
+
## Existing Charts
|
| 769 |
+
{existing_charts}
|
| 770 |
+
|
| 771 |
+
## Create a New Chart
|
| 772 |
+
|
| 773 |
+
Please create a chart that aligns closely with the above paper content while avoiding redundancy with existing charts. Follow the markdown format below to describe your chart:
|
| 774 |
+
|
| 775 |
+
**Chart Title**
|
| 776 |
+
[Provide a clear and descriptive title for the chart]
|
| 777 |
+
|
| 778 |
+
**Chart Type**
|
| 779 |
+
[Specify the type of chart]
|
| 780 |
+
|
| 781 |
+
**Purpose**
|
| 782 |
+
[Describe the core purpose of the chart in a paragraph]
|
| 783 |
+
|
| 784 |
+
**Data or Variables**
|
| 785 |
+
[Describe the data or variables used in the chart in a paragraph]
|
| 786 |
+
|
| 787 |
+
**Chart Presentation Guidelines**
|
| 788 |
+
[A comprehensive guide on chart presentation, covering data representation, key layout elements, units, axis labels, legends, gridlines, annotations, and other essential considerations for effective visualization.]
|
| 789 |
+
|
| 790 |
+
**Intended Message**
|
| 791 |
+
[Articulate the key message or insight the chart is intended to convey in a paragraph]
|
| 792 |
+
"""
|
| 793 |
+
|
| 794 |
+
|
| 795 |
+
|
| 796 |
+
PROBLEM_EXTRACT_PROMPT = """\
|
| 797 |
+
You are tasked with extracting detailed and complete information from the following mathematical modeling question.
|
| 798 |
+
|
| 799 |
+
<MODELING_QUESTION>
|
| 800 |
+
{question}
|
| 801 |
+
</MODELING_QUESTION>
|
| 802 |
+
|
| 803 |
+
### Extraction Requirements:
|
| 804 |
+
From the provided `<MODELING_QUESTION>`, extract and organize the following information as accurately and comprehensively as possible. Preserve the original text wherever applicable and do not omit any relevant details.
|
| 805 |
+
|
| 806 |
+
1. **"BACKGROUND"**: Extract all background information that provides context for the problem. This includes the problem’s domain, motivation, assumptions, or any other relevant introductory details.
|
| 807 |
+
2. **"TASK_REQUIREMENTS"**: A String to list all the requirements that need to be solved and satisfied, including specific instructions, constraints, objectives, and expected outputs.
|
| 808 |
+
3. **"DATA_FILES"**: A List to identify and list all dataset filenames mentioned in the question (if applicable). There may be multiple dataset files.
|
| 809 |
+
4. **"DATA_DESCRIPTIONS"**: Extract dataset descriptions, including details about the structure, features, variables, or metadata. If dataset descriptions are provided in a separate file, extract and list the filename instead.
|
| 810 |
+
5. **"ADDENDUM"**: Include any additional information that might be useful for solving the problem. This can include notes, references, clarifications, hints, or supplementary instructions.
|
| 811 |
+
|
| 812 |
+
### Expected Response Format:
|
| 813 |
+
Provide the extracted information in the following structured JSON format:
|
| 814 |
+
|
| 815 |
+
```json
|
| 816 |
+
{{
|
| 817 |
+
"background": "",
|
| 818 |
+
"task_requirements": "",
|
| 819 |
+
"data_files": [],
|
| 820 |
+
"data_descriptions": "",
|
| 821 |
+
"addendum": ""
|
| 822 |
+
}}
|
| 823 |
+
```
|
| 824 |
+
|
| 825 |
+
Ensure maximum fidelity to the original text and extract details as comprehensively as possible.
|
| 826 |
+
"""
|
| 827 |
+
|
| 828 |
+
|
| 829 |
+
|
| 830 |
+
TASK_DEPENDENCY_ANALYSIS_PROMPT = """\
|
| 831 |
+
Understanding the dependencies among different tasks in a mathematical modeling process is crucial for ensuring a coherent, logically structured, and efficient solution. Given a mathematical modeling problem and its solution decomposition into {tasknum} subtasks, analyze the interdependencies among these subtasks.
|
| 832 |
+
|
| 833 |
+
## Input Information:
|
| 834 |
+
- **Mathematical Modeling Problem:** {modeling_problem}
|
| 835 |
+
- **Problem Analysis:** {problem_analysis}
|
| 836 |
+
- **Modeling Solution:** {modeling_solution}
|
| 837 |
+
- **Decomposed Tasks:** {task_descriptions}
|
| 838 |
+
|
| 839 |
+
## Task Dependency Analysis Instructions:
|
| 840 |
+
1. **Identify Task Dependencies:** For each task, determine which preceding tasks provide necessary input, data, or conditions for its execution. Clearly outline how earlier tasks influence or constrain later ones.
|
| 841 |
+
2. **Describe Dependency Types:** Specify the nature of the dependencies between tasks. This includes:
|
| 842 |
+
- *Data Dependency:* When one task produces outputs that are required as inputs for another task.
|
| 843 |
+
- *Methodological Dependency:* When a later task builds upon a theoretical framework, assumptions, or models established by an earlier task.
|
| 844 |
+
- *Computational Dependency:* When a task requires prior computations or optimizations to be completed before proceeding.
|
| 845 |
+
- *Structural Dependency:* When a task is logically required to be completed before another due to hierarchical or sequential constraints.
|
| 846 |
+
3. **Ensure Completeness:** Verify that all tasks in the decomposition are accounted for in the dependency analysis and that no essential dependencies are missing.
|
| 847 |
+
|
| 848 |
+
## Output Format:
|
| 849 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text, without any Markdown formatting or syntax. Written as {tasknum} cohesive paragraphs, each paragraph is a dependency analysis of a task.
|
| 850 |
+
|
| 851 |
+
The response should be comprehensive and written in a clear, well-structured format without bullet points, ensuring a logical flow of dependency relationships and their implications.
|
| 852 |
+
"""
|
| 853 |
+
|
| 854 |
+
|
| 855 |
+
TASK_DEPENDENCY_ANALYSIS_WITH_CODE_PROMPT = """\
|
| 856 |
+
Understanding the dependencies among different tasks in a mathematical modeling process is crucial for ensuring a coherent, logically structured, and efficient solution. Given a mathematical modeling problem and its solution decomposition into {tasknum} subtasks, analyze the interdependencies among these subtasks.
|
| 857 |
+
|
| 858 |
+
## Input Information:
|
| 859 |
+
- **Mathematical Modeling Problem:** {modeling_problem}
|
| 860 |
+
- **Problem Analysis:** {problem_analysis}
|
| 861 |
+
- **Modeling Solution:** {modeling_solution}
|
| 862 |
+
- **Decomposed Tasks:** {task_descriptions}
|
| 863 |
+
|
| 864 |
+
## Task Dependency Analysis Instructions:
|
| 865 |
+
1. **Identify Task Dependencies:** For each task, determine which preceding tasks provide necessary input, data, or conditions for its execution. Clearly outline how earlier tasks influence or constrain later ones.
|
| 866 |
+
2. **Describe Dependency Types:** Specify the nature of the dependencies between tasks. This includes:
|
| 867 |
+
- *Data Dependency:* When one task produces outputs that are required as inputs for another task.
|
| 868 |
+
- *Methodological Dependency:* When a later task builds upon a theoretical framework, assumptions, or models established by an earlier task.
|
| 869 |
+
- *Computational Dependency:* When a task requires prior computations or optimizations to be completed before proceeding.
|
| 870 |
+
- *Structural Dependency:* When a task is logically required to be completed before another due to hierarchical or sequential constraints.
|
| 871 |
+
- *Code Dependency:* When one task relies on code structures, functions, or modules that are defined or executed in a preceding task. This includes shared variables, functions, or libraries that must be defined before their use in later tasks.
|
| 872 |
+
3. **Ensure Completeness:** Verify that all tasks in the decomposition are accounted for in the dependency analysis and that no essential dependencies are missing.
|
| 873 |
+
|
| 874 |
+
## Output Format:
|
| 875 |
+
Respond as comprehensively and in as much detail as possible. Do not format your response in Markdown. Using plain text, without any Markdown formatting or syntax. Written as {tasknum} cohesive paragraphs, each paragraph is a dependency analysis of a task.
|
| 876 |
+
|
| 877 |
+
The response should be comprehensive and written in a clear, well-structured format without bullet points, ensuring a logical flow of dependency relationships and their implications.
|
| 878 |
+
"""
|
| 879 |
+
|
| 880 |
+
|
| 881 |
+
DAG_CONSTRUCTION_PROMPT = """\
|
| 882 |
+
A well-structured Directed Acyclic Graph (DAG) is essential for visualizing and optimizing the dependencies between different tasks in a mathematical modeling process. Given a problem and its solution decomposition into {tasknum} subtasks, construct a DAG that accurately represents the dependency relationships among these tasks. The DAG should capture all necessary dependencies while ensuring that no cycles exist in the structure.
|
| 883 |
+
|
| 884 |
+
## Input Information:
|
| 885 |
+
- **Mathematical Modeling Problem:** {modeling_problem}
|
| 886 |
+
- **Problem Analysis:** {problem_analysis}
|
| 887 |
+
- **Modeling Solution:** {modeling_solution}
|
| 888 |
+
- **Decomposed Tasks:** {task_descriptions}
|
| 889 |
+
- **Dependency Analysis:** {task_dependency_analysis}
|
| 890 |
+
|
| 891 |
+
## Output Format (STRICT REQUIREMENT):
|
| 892 |
+
You **MUST** return a valid JSON-formatted adjacency list **without** any additional text, explanations, or comments. **Only** output the JSON object.
|
| 893 |
+
|
| 894 |
+
### JSON Format (Strictly Follow This Format):
|
| 895 |
+
```json
|
| 896 |
+
{{
|
| 897 |
+
"task_ID": [dependent_IDs],
|
| 898 |
+
...
|
| 899 |
+
}}
|
| 900 |
+
|
| 901 |
+
## Example Output:
|
| 902 |
+
```json
|
| 903 |
+
{{
|
| 904 |
+
"1": []
|
| 905 |
+
"2": ['1']
|
| 906 |
+
"3": ['1']
|
| 907 |
+
"4": ['2', '3']
|
| 908 |
+
}}
|
| 909 |
+
```
|
| 910 |
+
"""
|
| 911 |
+
|
| 912 |
+
# TASK_ANALYSIS_APPEND_PROMPT = """\
|
| 913 |
+
# When analyzing the current task, please pay careful attention to its dependencies on other tasks. Ensure that you consider how the outputs or results from preceding tasks influence the execution and outcomes of this task. Identify any tasks that provide necessary inputs, data, or models, and explain how these dependencies shape the approach, methods, and overall execution of the task at hand. This analysis should be informed by the task dependency relationships, which will help clarify how the current task fits into the broader project or workflow. Keep in mind that the successful completion of this task may depend on the timely and correct completion of other tasks, and any delays or issues in the dependent tasks could impact the current task’s progress and outcomes.
|
| 914 |
+
# """
|
| 915 |
+
#
|
| 916 |
+
# TASK_FORMULAS_APPEND_PROMPT = """\
|
| 917 |
+
# When formulating the mathematical model for the current task, it is essential to consider how this task depends on other tasks in the overall process. Be sure to analyze how the results, data, or models produced by preceding tasks influence the formulation of the current task. Identify any critical inputs or assumptions that come from earlier tasks and explain how these shape the approach, variables, or constraints in the mathematical formulation. In particular, pay attention to how the completion of dependent tasks impacts the accuracy, feasibility, or computational aspects of the model. This dependency analysis will help ensure that the model reflects the correct sequence of steps, and that any limitations or challenges arising from earlier tasks are properly accounted for. Ensure that the interdependencies between tasks are fully integrated into the mathematical formulation to maintain consistency and validity across the entire modeling process.
|
| 918 |
+
# """
|
| 919 |
+
#
|
| 920 |
+
# TASK_MODELING_APPEND_PROMPT = """\
|
| 921 |
+
# Please continue the modeling process by considering the dependencies between the current task and the preceding tasks. Begin by analyzing how the outputs or models from earlier tasks influence the formulation and execution of the current task. Describe the interdependencies in detail, explaining how the results from previous tasks provide necessary data, constraints, or assumptions that affect the current task's modeling approach. Identify any key variables, parameters, or methods that are directly linked to earlier tasks and discuss how their incorporation into the current task ensures consistency and accuracy across the entire modeling framework. Additionally, consider any potential challenges or limitations introduced by the dependencies, such as delays or uncertainty in the results from prior tasks, and explain how these factors might be addressed in the modeling process. Ensure that these dependencies are clearly integrated into the continued modeling effort, providing a cohesive and comprehensive understanding of how the tasks interconnect and contribute to the overall solution.
|
| 922 |
+
# """
|
| 923 |
+
|
| 924 |
+
TASK_ANALYSIS_APPEND_PROMPT = """\
|
| 925 |
+
When analyzing the current task, please pay careful attention to its dependencies on other tasks.
|
| 926 |
+
"""
|
| 927 |
+
|
| 928 |
+
TASK_FORMULAS_APPEND_PROMPT = """\
|
| 929 |
+
When formulating the mathematical model for the current task, it is essential to consider how this task depends on other tasks in the overall process.
|
| 930 |
+
"""
|
| 931 |
+
|
| 932 |
+
TASK_MODELING_APPEND_PROMPT = """\
|
| 933 |
+
Please consider the dependencies between the current task and the preceding tasks.
|
| 934 |
+
"""
|
| 935 |
+
|
| 936 |
+
CODE_STRUCTURE_PROMPT = """\
|
| 937 |
+
You are a programming expert. Please extract the structure from the following code and output it in the following JSON format, please return an empty list if the corresponding item is not available.:
|
| 938 |
+
The code is:
|
| 939 |
+
```python
|
| 940 |
+
{code}
|
| 941 |
+
```
|
| 942 |
+
The output format is:
|
| 943 |
+
```json
|
| 944 |
+
{{
|
| 945 |
+
"script_path": {save_path}
|
| 946 |
+
"class": [
|
| 947 |
+
{{
|
| 948 |
+
"name": class name,
|
| 949 |
+
"description": description of class,
|
| 950 |
+
"class_functions": [
|
| 951 |
+
{{
|
| 952 |
+
"name": function name,
|
| 953 |
+
"description": description of class function,
|
| 954 |
+
"parameters": [
|
| 955 |
+
{{
|
| 956 |
+
"name": param name,
|
| 957 |
+
"type": param type,
|
| 958 |
+
"description": description of param,
|
| 959 |
+
}},
|
| 960 |
+
...
|
| 961 |
+
],
|
| 962 |
+
"returns": {{
|
| 963 |
+
"description": "return of the function."
|
| 964 |
+
}},
|
| 965 |
+
}}
|
| 966 |
+
]
|
| 967 |
+
}}
|
| 968 |
+
],
|
| 969 |
+
"function": [
|
| 970 |
+
{{
|
| 971 |
+
"name": function name,
|
| 972 |
+
"description": description of class function,
|
| 973 |
+
"parameters": [
|
| 974 |
+
{{
|
| 975 |
+
"name": param name,
|
| 976 |
+
"type": param type,
|
| 977 |
+
"description": description of param,
|
| 978 |
+
}},
|
| 979 |
+
...
|
| 980 |
+
],
|
| 981 |
+
"returns": {{
|
| 982 |
+
"description": "return of the function."
|
| 983 |
+
}},
|
| 984 |
+
}}
|
| 985 |
+
],
|
| 986 |
+
"file_outputs": [
|
| 987 |
+
{{
|
| 988 |
+
"path": "file_path",
|
| 989 |
+
"file_description": "description of the file",
|
| 990 |
+
"column_name": ["column_name_if_csv_else_None"]
|
| 991 |
+
}},
|
| 992 |
+
...
|
| 993 |
+
]
|
| 994 |
+
}}
|
| 995 |
+
```
|
| 996 |
+
"""
|
| 997 |
+
|
| 998 |
+
|
| 999 |
+
PAPER_CHAPTER_PROMPT = """\
|
| 1000 |
+
You are tasked with creating a publication-quality LaTeX chapter for a mathematical modeling research paper. Carefully transform the provided structured draft into a coherent, rigorous, and concise narrative chapter that aligns logically and seamlessly with the previously written content.
|
| 1001 |
+
|
| 1002 |
+
## Target Chapter:
|
| 1003 |
+
{chapter_path}
|
| 1004 |
+
|
| 1005 |
+
## Structured Draft:
|
| 1006 |
+
<structured_draft>
|
| 1007 |
+
{json_context}
|
| 1008 |
+
</structured_draft>
|
| 1009 |
+
|
| 1010 |
+
## Preceding Chapters (for seamless narrative integration and avoiding repetition):
|
| 1011 |
+
<preceding_content>
|
| 1012 |
+
{previous_chapters}
|
| 1013 |
+
</preceding_content>
|
| 1014 |
+
|
| 1015 |
+
|
| 1016 |
+
## Requirements:
|
| 1017 |
+
- Write exclusively in accurate, idiomatic LaTeX; avoid Markdown syntax and symbols entirely.
|
| 1018 |
+
- Clearly indicate the chapter content corresponds precisely to the target chapter `{chapter_path}`; do not repeat or reference explicitly the content of other chapters.
|
| 1019 |
+
- Integrate any mathematical formulas properly using correct LaTeX environments (`\\begin{{align}}`). Truncate and wrap long formulas and symbols.
|
| 1020 |
+
- Present the chapter as a continuous, fluent narrative without section headings, subsections, bullet points, or numbered lists, Response only chapter content, do not include headlines and anything else.
|
| 1021 |
+
- Critically evaluate the structured draft, selecting only most high-quality important and relevant content. Remove all redundancy, eliminate low-value statements, and distill essential information clearly and succinctly.
|
| 1022 |
+
- Maintain rigorous academic style, logical coherence, and clarity throughout, ensuring that the chapter integrates naturally with preceding chapters.
|
| 1023 |
+
|
| 1024 |
+
## Output Format:
|
| 1025 |
+
```latex
|
| 1026 |
+
CHAPTER_CONTENT_TEXT
|
| 1027 |
+
```
|
| 1028 |
+
|
| 1029 |
+
"""
|
| 1030 |
+
|
| 1031 |
+
PAPER_CHAPTER_WITH_PRECEDING_PROMPT = """\
|
| 1032 |
+
You are tasked with generating a publication-quality LaTeX chapter for a mathematical modeling paper. Write a cohesive, academically rigorous chapter that integrates seamlessly with the preceding content of the paper.
|
| 1033 |
+
|
| 1034 |
+
## Chapter to write:
|
| 1035 |
+
{chapter_path}
|
| 1036 |
+
|
| 1037 |
+
## Preceding Content:
|
| 1038 |
+
<preceding_content>
|
| 1039 |
+
{previous_chapters}
|
| 1040 |
+
</preceding_content>
|
| 1041 |
+
|
| 1042 |
+
## Writing Requirements:
|
| 1043 |
+
- Use accurate and proper LaTeX syntax throughout, avoid all Markdown syntax or symbols.
|
| 1044 |
+
- Present the content as a continuous, coherent narrative without using sections, subsections, or bullet points. Response only chapter content, do not include headlines and anything else.
|
| 1045 |
+
- Make it clear that the section you need to write is `{chapter_path}`. Do not involve the content of other chapters.
|
| 1046 |
+
"""
|
| 1047 |
+
|
| 1048 |
+
PAPER_NOTATION_PROMPT = """
|
| 1049 |
+
You are an AI assistant trained to extract and typeset the Notations table from a mathematical modeling paper in LaTeX format. Your task is to take the input paper and output a properly formatted LaTeX table displaying the notations used in the paper.
|
| 1050 |
+
|
| 1051 |
+
1. Well-structured and easy to read.
|
| 1052 |
+
2. Properly typeset for LaTeX documents.
|
| 1053 |
+
3. Adaptive in size and position to fit neatly into any document.
|
| 1054 |
+
4. Truncate and wrap long formulas, symbols and text in the table for better readability.
|
| 1055 |
+
|
| 1056 |
+
<paper>
|
| 1057 |
+
{previous_chapters}
|
| 1058 |
+
</paper>
|
| 1059 |
+
|
| 1060 |
+
Exmple of Table Format:
|
| 1061 |
+
```latex
|
| 1062 |
+
\\begin{{table}}[H]
|
| 1063 |
+
\\centering
|
| 1064 |
+
\\renewcommand{{\\arraystretch}}{{1.3}}
|
| 1065 |
+
\\begin{{tabular}}{{>{{\\raggedright\\arraybackslash}}p{{3cm}}>{{\\raggedright\\arraybackslash}}p{{11cm}}}}
|
| 1066 |
+
\\toprule
|
| 1067 |
+
\\textbf{{Notation}} & \\textbf{{Description}} \\\\
|
| 1068 |
+
\\midrule
|
| 1069 |
+
\\( f(x) \\) & description... \\\\
|
| 1070 |
+
\\bottomrule
|
| 1071 |
+
\\end{{tabular}}
|
| 1072 |
+
\\caption{{Table of Notations}}
|
| 1073 |
+
\\label{{tab:notations}}
|
| 1074 |
+
\\end{{table}}
|
| 1075 |
+
```
|
| 1076 |
+
|
| 1077 |
+
Response only latex table content, do not include headlines and anything else.
|
| 1078 |
+
"""
|
| 1079 |
+
|
| 1080 |
+
|
| 1081 |
+
PAPER_INFO_PROMPT = """\
|
| 1082 |
+
You are an expert academic writer tasked with analyzing paper chapters and generating key metadata for a mathematical modeling paper.
|
| 1083 |
+
|
| 1084 |
+
# Input Chapters
|
| 1085 |
+
{paper_chapters}
|
| 1086 |
+
|
| 1087 |
+
Based on the content of these chapters, please generate:
|
| 1088 |
+
1. A concise, descriptive title that reflects the paper's main focus
|
| 1089 |
+
2. A comprehensive and detailed summary highlighting key findings and methodology
|
| 1090 |
+
3. 4-6 relevant keywords that capture the paper's main themes
|
| 1091 |
+
|
| 1092 |
+
Returns the Legal JSON Format:
|
| 1093 |
+
```Json
|
| 1094 |
+
{{
|
| 1095 |
+
"title": "A clear, concise title",
|
| 1096 |
+
"summary": "A well-structured summary covering the following information: \n- Restatement and Clarification of the Problem: Describe the problem to be solved in your own words.\n- Explanation of Assumptions and Their Rationality: Highlight the assumptions made in the modeling process and clearly list all the variables required for the model.\n- Model Design and Rationality Argumentation: Specify the type of model used or describe the construction of a new model, explain how it was established and the rationale behind its design.\n- Description of Model Testing and Sensitivity Analysis: Include error analysis and other testing items.",
|
| 1097 |
+
"keywords": "keyword1; keyword2; keyword3; keyword4..."
|
| 1098 |
+
}}
|
| 1099 |
+
```
|
| 1100 |
+
|
| 1101 |
+
Requirements:
|
| 1102 |
+
- Title should be specific and academic in tone
|
| 1103 |
+
- Summary should follow standard academic abstract structure and be approximately 400 words
|
| 1104 |
+
- Keywords should be ordered from general to specific
|
| 1105 |
+
- must return a strictly legal JSON
|
| 1106 |
+
"""
|
core/run_batch.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llm.llm import LLM
|
| 2 |
+
from prompt.constants import modeling_methods
|
| 3 |
+
from input.problem import problem_input
|
| 4 |
+
# from input.test_middle_result import problem_str, problem_analysis, selected_models, modeling_solution, modeling_solution, task_descriptions
|
| 5 |
+
from agent.problem_analysis import ProblemAnalysis
|
| 6 |
+
from agent.method_ranking import MethodRanking
|
| 7 |
+
from agent.problem_modeling import ProblemModeling
|
| 8 |
+
from agent.task_decompse import TaskDecompose
|
| 9 |
+
from agent.task import Task
|
| 10 |
+
from agent.create_charts import Chart
|
| 11 |
+
from agent.coordinator import Coordinator
|
| 12 |
+
from utils.utils import read_json_file, write_json_file, write_text_file, json_to_markdown
|
| 13 |
+
from prompt.template import TASK_ANALYSIS_APPEND_PROMPT, TASK_FORMULAS_APPEND_PROMPT, TASK_MODELING_APPEND_PROMPT
|
| 14 |
+
# from utils.convert_format import markdown_to_latex
|
| 15 |
+
import os
|
| 16 |
+
from datetime import datetime
|
| 17 |
+
import shutil
|
| 18 |
+
import time
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def run_batch(problem_path, config, name, dataset_path, output_path):
|
| 22 |
+
# Initialize LLM
|
| 23 |
+
llm = LLM(config['model_name'])
|
| 24 |
+
|
| 25 |
+
# Get problem input
|
| 26 |
+
problem_str, problem = problem_input(problem_path, llm)
|
| 27 |
+
problem_type = os.path.splitext(os.path.basename(problem_path))[0].split('_')[-1]
|
| 28 |
+
|
| 29 |
+
# Initialize paper dictionary
|
| 30 |
+
paper = {'tasks': []}
|
| 31 |
+
paper['problem_background'] = problem['background']
|
| 32 |
+
paper['problem_requirement'] = problem['problem_requirement']
|
| 33 |
+
|
| 34 |
+
# Problem analysis
|
| 35 |
+
pa = ProblemAnalysis(llm)
|
| 36 |
+
problem_analysis = pa.analysis(problem_str, round=config['problem_analysis_round'])
|
| 37 |
+
paper['problem_analysis'] = problem_analysis
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
modeling_methods = ""
|
| 42 |
+
# High level probelm understanding modeling
|
| 43 |
+
pm = ProblemModeling(llm)
|
| 44 |
+
modeling_solution = pm.modeling(problem_str, problem_analysis, modeling_methods, round=config['problem_modeling_round'])
|
| 45 |
+
|
| 46 |
+
# Task decomposition
|
| 47 |
+
td = TaskDecompose(llm)
|
| 48 |
+
task_descriptions = td.decompose_and_refine(problem_str, problem_analysis, modeling_solution, problem_type, config['tasknum'])
|
| 49 |
+
|
| 50 |
+
# Analyze dependency
|
| 51 |
+
with_code = len(problem['dataset_path']) > 0
|
| 52 |
+
coordinator = Coordinator(llm)
|
| 53 |
+
order = coordinator.analyze_dependencies(problem_str, problem_analysis, modeling_solution, task_descriptions, with_code)
|
| 54 |
+
order = [int(i) for i in order]
|
| 55 |
+
|
| 56 |
+
if with_code:
|
| 57 |
+
shutil.copytree(dataset_path, os.path.join(output_path,'code'), dirs_exist_ok=True)
|
| 58 |
+
|
| 59 |
+
# Process tasks
|
| 60 |
+
task = Task(llm)
|
| 61 |
+
mr = MethodRanking(llm)
|
| 62 |
+
chart = Chart(llm)
|
| 63 |
+
for id in order:
|
| 64 |
+
task_dependency = [int(i) for i in coordinator.DAG[str(id)]]
|
| 65 |
+
dependent_file_prompt = ""
|
| 66 |
+
if len(task_dependency) > 0:
|
| 67 |
+
dependency_prompt = f"""\
|
| 68 |
+
This task is Task {id}, which depends on the following tasks: {task_dependency}. The dependencies for this task are analyzed as follows: {coordinator.task_dependency_analysis[id - 1]}
|
| 69 |
+
"""
|
| 70 |
+
for task_id in task_dependency:
|
| 71 |
+
dependency_prompt += f"""\
|
| 72 |
+
---
|
| 73 |
+
# The Description of Task {task_id}:
|
| 74 |
+
{coordinator.memory[str(task_id)]['task_description']}
|
| 75 |
+
# The modeling method for Task {task_id}:
|
| 76 |
+
{coordinator.memory[str(task_id)]['mathematical_modeling_process']}
|
| 77 |
+
"""
|
| 78 |
+
if with_code:
|
| 79 |
+
dependency_prompt += f"""\
|
| 80 |
+
# The structure of code for Task {task_id}:
|
| 81 |
+
{coordinator.code_memory[str(task_id)]}
|
| 82 |
+
# The result for Task {task_id}:
|
| 83 |
+
{coordinator.memory[str(task_id)]['solution_interpretation']}
|
| 84 |
+
---
|
| 85 |
+
"""
|
| 86 |
+
dependent_file_prompt += f"""\
|
| 87 |
+
# The files generated by code for Task {task_id}:
|
| 88 |
+
{coordinator.code_memory[str(task_id)]}
|
| 89 |
+
"""
|
| 90 |
+
coordinator.code_memory[str(task_id)]['file_outputs']
|
| 91 |
+
else:
|
| 92 |
+
dependency_prompt += f"""\
|
| 93 |
+
# The result for Task {task_id}:
|
| 94 |
+
{coordinator.memory[str(task_id)]['solution_interpretation']}
|
| 95 |
+
---
|
| 96 |
+
"""
|
| 97 |
+
|
| 98 |
+
task_analysis_prompt = dependency_prompt + TASK_ANALYSIS_APPEND_PROMPT
|
| 99 |
+
task_formulas_prompt = dependency_prompt + TASK_FORMULAS_APPEND_PROMPT
|
| 100 |
+
task_modeling_prompt = dependency_prompt + TASK_MODELING_APPEND_PROMPT
|
| 101 |
+
else:
|
| 102 |
+
task_analysis_prompt = ""
|
| 103 |
+
task_formulas_prompt = ""
|
| 104 |
+
task_modeling_prompt = ""
|
| 105 |
+
|
| 106 |
+
code_template = open(os.path.join('data/actor_data/input/code_template','main{}.py'.format(id))).read()
|
| 107 |
+
save_path = os.path.join(output_path,'code/main{}.py'.format(id))
|
| 108 |
+
work_dir = os.path.join(output_path,'code')
|
| 109 |
+
script_name = 'main{}.py'.format(id)
|
| 110 |
+
|
| 111 |
+
task_description = task_descriptions[id - 1]
|
| 112 |
+
task_analysis = task.analysis(task_analysis_prompt, task_description)
|
| 113 |
+
description_and_analysis = f'## Task Description\n{task_description}\n\n## Task Analysis\n{task_analysis}'
|
| 114 |
+
top_modeling_methods = mr.top_methods(description_and_analysis, top_k=config['top_method_num'])
|
| 115 |
+
|
| 116 |
+
task_formulas = task.formulas(task_formulas_prompt, problem['data_description'], task_description, task_analysis, top_modeling_methods, round=config['task_formulas_round'])
|
| 117 |
+
task_modeling = task.modeling(task_modeling_prompt, problem['data_description'], task_description, task_analysis, task_formulas)
|
| 118 |
+
if with_code:
|
| 119 |
+
task_code, is_pass, execution_result = task.coding(problem['dataset_path'], problem['data_description'], problem['variable_description'], task_description, task_analysis, task_formulas, task_modeling, dependent_file_prompt, code_template, script_name, work_dir)
|
| 120 |
+
code_structure = task.extract_code_structure(id, task_code, save_path)
|
| 121 |
+
task_result = task.result(task_description, task_analysis, task_formulas, task_modeling, execution_result)
|
| 122 |
+
task_answer = task.answer(task_description, task_analysis, task_formulas, task_modeling, task_result)
|
| 123 |
+
task_dict = {
|
| 124 |
+
'task_description': task_description,
|
| 125 |
+
'task_analysis': task_analysis,
|
| 126 |
+
'preliminary_formulas': task_formulas,
|
| 127 |
+
'mathematical_modeling_process': task_modeling,
|
| 128 |
+
'task_code': task_code,
|
| 129 |
+
'is_pass': is_pass,
|
| 130 |
+
'execution_result': execution_result,
|
| 131 |
+
'solution_interpretation': task_result,
|
| 132 |
+
'subtask_outcome_analysis': task_answer
|
| 133 |
+
}
|
| 134 |
+
coordinator.code_memory[str(id)] = code_structure
|
| 135 |
+
else:
|
| 136 |
+
task_result = task.result(task_description, task_analysis, task_formulas, task_modeling)
|
| 137 |
+
task_answer = task.answer(task_description, task_analysis, task_formulas, task_modeling, task_result)
|
| 138 |
+
task_dict = {
|
| 139 |
+
'task_description': task_description,
|
| 140 |
+
'task_analysis': task_analysis,
|
| 141 |
+
'preliminary_formulas': task_formulas,
|
| 142 |
+
'mathematical_modeling_process': task_modeling,
|
| 143 |
+
'solution_interpretation': task_result,
|
| 144 |
+
'subtask_outcome_analysis': task_answer
|
| 145 |
+
}
|
| 146 |
+
coordinator.memory[str(id)] = task_dict
|
| 147 |
+
charts = chart.create_charts(str(task_dict), config['chart_num'])
|
| 148 |
+
task_dict['charts'] = charts
|
| 149 |
+
paper['tasks'].append(task_dict)
|
| 150 |
+
save_paper(paper, name, output_path)
|
| 151 |
+
|
| 152 |
+
print(paper)
|
| 153 |
+
print('Usage:', llm.get_total_usage())
|
| 154 |
+
write_json_file(f'{output_path}/usage/{name}.json', llm.get_total_usage())
|
| 155 |
+
return paper
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def save_paper(paper, name, path):
|
| 159 |
+
write_json_file(f'{path}/json/{name}.json', paper)
|
| 160 |
+
markdown_str = json_to_markdown(paper)
|
| 161 |
+
write_text_file(f'{path}/markdown/{name}.md', markdown_str)
|
| 162 |
+
# write_text_file(f'data/actor_data/output/latex/{name}.tex', markdown_to_latex(markdown_str))
|
| 163 |
+
|
| 164 |
+
def mkdir(path):
|
| 165 |
+
os.mkdir(path)
|
| 166 |
+
os.mkdir(path + '/json')
|
| 167 |
+
os.mkdir(path + '/markdown')
|
| 168 |
+
os.mkdir(path + '/latex')
|
| 169 |
+
os.mkdir(path + '/code')
|
| 170 |
+
os.mkdir(path + '/usage')
|
| 171 |
+
|
| 172 |
+
if __name__ == "__main__":
|
| 173 |
+
import glob
|
| 174 |
+
file_name_list = []
|
| 175 |
+
for year in range(2025, 2026):
|
| 176 |
+
if year == 2025:
|
| 177 |
+
letters = "CDEF"
|
| 178 |
+
else:
|
| 179 |
+
letters = "ABCDEF"
|
| 180 |
+
|
| 181 |
+
for letter in letters:
|
| 182 |
+
file_name_list.append(f'data/actor_data/input/problem/{year}_{letter}*')
|
| 183 |
+
|
| 184 |
+
files = []
|
| 185 |
+
for pattern in file_name_list:
|
| 186 |
+
files.extend(glob.glob(pattern))
|
| 187 |
+
|
| 188 |
+
config_list = [{
|
| 189 |
+
'top_method_num': 6,
|
| 190 |
+
'problem_analysis_round': 1,
|
| 191 |
+
'problem_modeling_round': 1,
|
| 192 |
+
'task_formulas_round': 1,
|
| 193 |
+
'tasknum': 4,
|
| 194 |
+
'chart_num': 3,
|
| 195 |
+
'model_name': 'gpt-4o',
|
| 196 |
+
"method_name": "MM-Agent-gpt-4o-v3-probelm-modleing"
|
| 197 |
+
# 'model_name': 'chatgpt-4o-latest'
|
| 198 |
+
}]
|
| 199 |
+
|
| 200 |
+
for i, config in enumerate(config_list, start=1):
|
| 201 |
+
for file in files:
|
| 202 |
+
try:
|
| 203 |
+
name = file.split('/')[-1].split('.')[0]
|
| 204 |
+
dataset_path = os.path.join('data/actor_data/input/dataset', file.split('/')[-1].split('.')[0])
|
| 205 |
+
output_dir = 'data/actor_data/exps/{}'.format(config["method_name"])
|
| 206 |
+
if not os.path.exists(output_dir):
|
| 207 |
+
os.makedirs(output_dir)
|
| 208 |
+
output_path = os.path.join(output_dir, name + '_{}'.format(datetime.now().strftime('%Y%m%d-%H%M%S')))
|
| 209 |
+
if not os.path.exists(output_path):
|
| 210 |
+
mkdir(output_path)
|
| 211 |
+
print(f'Processing {file}..., config: {config}')
|
| 212 |
+
start = time.time()
|
| 213 |
+
paper = run_batch(problem_path=file, config=config, name=name, dataset_path=dataset_path, output_path=output_path)
|
| 214 |
+
end = time.time()
|
| 215 |
+
with open(output_path + '/usage/runtime.txt', 'w') as f:
|
| 216 |
+
f.write("{:.2f}s".format(end - start))
|
| 217 |
+
# save_paper(paper, name)
|
| 218 |
+
except Exception as e:
|
| 219 |
+
raise
|
| 220 |
+
print(f'Error: {e}')
|
| 221 |
+
continue
|
core/run_batch_wo_coo.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llm.llm import LLM
|
| 2 |
+
from prompt.constants import modeling_methods
|
| 3 |
+
from input.problem import problem_input
|
| 4 |
+
# from input.test_middle_result import problem_str, problem_analysis, selected_models, modeling_solution, modeling_solution, task_descriptions
|
| 5 |
+
from agent.problem_analysis import ProblemAnalysis
|
| 6 |
+
from agent.method_ranking import MethodRanking
|
| 7 |
+
from agent.problem_modeling import ProblemModeling
|
| 8 |
+
from agent.task_decompse import TaskDecompose
|
| 9 |
+
from agent.task import Task
|
| 10 |
+
from agent.create_charts import Chart
|
| 11 |
+
from agent.coordinator import Coordinator
|
| 12 |
+
from utils.utils import read_json_file, write_json_file, write_text_file, json_to_markdown
|
| 13 |
+
from prompt.template import TASK_ANALYSIS_APPEND_PROMPT, TASK_FORMULAS_APPEND_PROMPT, TASK_MODELING_APPEND_PROMPT
|
| 14 |
+
# from utils.convert_format import markdown_to_latex
|
| 15 |
+
import os
|
| 16 |
+
from datetime import datetime
|
| 17 |
+
import shutil
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def run_batch(problem_path, config, name, dataset_path, output_path):
|
| 21 |
+
# Initialize LLM
|
| 22 |
+
llm = LLM(config['model_name'])
|
| 23 |
+
|
| 24 |
+
# Get problem input
|
| 25 |
+
problem_str, problem = problem_input(problem_path, llm)
|
| 26 |
+
problem_type = ""
|
| 27 |
+
|
| 28 |
+
# Initialize paper dictionary
|
| 29 |
+
paper = {'tasks': []}
|
| 30 |
+
paper['problem_background'] = problem['background']
|
| 31 |
+
paper['problem_requirement'] = problem['problem_requirement']
|
| 32 |
+
|
| 33 |
+
# Problem analysis
|
| 34 |
+
problem_analysis = ""
|
| 35 |
+
paper['problem_analysis'] = problem_analysis
|
| 36 |
+
|
| 37 |
+
# Problem modeling
|
| 38 |
+
modeling_solution = ""
|
| 39 |
+
|
| 40 |
+
# Task decomposition
|
| 41 |
+
td = TaskDecompose(llm, coo = False)
|
| 42 |
+
task_descriptions = td.decompose_and_refine(problem_str, problem_analysis, modeling_solution, problem_type, config['tasknum'])
|
| 43 |
+
|
| 44 |
+
# Analyze dependency
|
| 45 |
+
with_code = len(problem['dataset_path']) > 0
|
| 46 |
+
|
| 47 |
+
if with_code:
|
| 48 |
+
shutil.copytree(dataset_path, os.path.join(output_path,'code'), dirs_exist_ok=True)
|
| 49 |
+
|
| 50 |
+
# Process tasks
|
| 51 |
+
task = Task(llm, coo = False)
|
| 52 |
+
mr = MethodRanking(llm)
|
| 53 |
+
chart = Chart(llm)
|
| 54 |
+
for id in range(1, len(task_descriptions)+1):
|
| 55 |
+
code_template = open(os.path.join('data/actor_data/input/code_template','main{}.py'.format(id))).read()
|
| 56 |
+
work_dir = os.path.join(output_path,'code')
|
| 57 |
+
script_name = 'main{}.py'.format(id)
|
| 58 |
+
|
| 59 |
+
task_description = task_descriptions[id - 1]
|
| 60 |
+
task_analysis = task.analysis("", task_description)
|
| 61 |
+
description_and_analysis = f'## Task Description\n{task_description}\n\n## Task Analysis\n{task_analysis}'
|
| 62 |
+
top_modeling_methods = mr.top_methods(description_and_analysis, top_k=config['top_method_num'])
|
| 63 |
+
|
| 64 |
+
task_formulas = task.formulas("", problem['data_description'], task_description, task_analysis, top_modeling_methods, round=config['task_formulas_round'])
|
| 65 |
+
task_modeling = task.modeling("", problem['data_description'], task_description, task_analysis, task_formulas)
|
| 66 |
+
if with_code:
|
| 67 |
+
task_code, is_pass, execution_result = task.coding(problem['dataset_path'], problem['data_description'], problem['variable_description'], task_description, task_analysis, task_formulas, task_modeling, "", code_template, script_name, work_dir)
|
| 68 |
+
task_result = task.result(task_description, task_analysis, task_formulas, task_modeling, execution_result)
|
| 69 |
+
task_answer = task.answer(task_description, task_analysis, task_formulas, task_modeling, task_result)
|
| 70 |
+
task_dict = {
|
| 71 |
+
'task_description': task_description,
|
| 72 |
+
'task_analysis': task_analysis,
|
| 73 |
+
'preliminary_formulas': task_formulas,
|
| 74 |
+
'mathematical_modeling_process': task_modeling,
|
| 75 |
+
'task_code': task_code,
|
| 76 |
+
'is_pass': is_pass,
|
| 77 |
+
'execution_result': execution_result,
|
| 78 |
+
'solution_interpretation': task_result,
|
| 79 |
+
'subtask_outcome_analysis': task_answer
|
| 80 |
+
}
|
| 81 |
+
else:
|
| 82 |
+
task_result = task.result(task_description, task_analysis, task_formulas, task_modeling)
|
| 83 |
+
task_answer = task.answer(task_description, task_analysis, task_formulas, task_modeling, task_result)
|
| 84 |
+
task_dict = {
|
| 85 |
+
'task_description': task_description,
|
| 86 |
+
'task_analysis': task_analysis,
|
| 87 |
+
'preliminary_formulas': task_formulas,
|
| 88 |
+
'mathematical_modeling_process': task_modeling,
|
| 89 |
+
'solution_interpretation': task_result,
|
| 90 |
+
'subtask_outcome_analysis': task_answer
|
| 91 |
+
}
|
| 92 |
+
charts = chart.create_charts(str(task_dict), config['chart_num'])
|
| 93 |
+
task_dict['charts'] = charts
|
| 94 |
+
paper['tasks'].append(task_dict)
|
| 95 |
+
save_paper(paper, name, output_path)
|
| 96 |
+
|
| 97 |
+
print(paper)
|
| 98 |
+
print('Usage:', llm.get_total_usage())
|
| 99 |
+
write_json_file(f'{output_path}/usage/{name}.json', llm.get_total_usage())
|
| 100 |
+
return paper
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def save_paper(paper, name, path):
|
| 104 |
+
write_json_file(f'{path}/json/{name}.json', paper)
|
| 105 |
+
markdown_str = json_to_markdown(paper)
|
| 106 |
+
write_text_file(f'{path}/markdown/{name}.md', markdown_str)
|
| 107 |
+
# write_text_file(f'data/actor_data/output/latex/{name}.tex', markdown_to_latex(markdown_str))
|
| 108 |
+
|
| 109 |
+
def mkdir(path):
|
| 110 |
+
os.mkdir(path)
|
| 111 |
+
os.mkdir(path + '/json')
|
| 112 |
+
os.mkdir(path + '/markdown')
|
| 113 |
+
os.mkdir(path + '/latex')
|
| 114 |
+
os.mkdir(path + '/code')
|
| 115 |
+
os.mkdir(path + '/usage')
|
| 116 |
+
|
| 117 |
+
if __name__ == "__main__":
|
| 118 |
+
import glob
|
| 119 |
+
# files = glob.glob('data/actor_data/input/problem/2024*')
|
| 120 |
+
files = glob.glob('data/actor_data/input/problem/2024_C*')
|
| 121 |
+
|
| 122 |
+
# config_list = [{
|
| 123 |
+
# 'top_method_num': 6,
|
| 124 |
+
# 'problem_analysis_round': 1,
|
| 125 |
+
# 'problem_modeling_round': 1,
|
| 126 |
+
# 'task_formulas_round': 1,
|
| 127 |
+
# 'tasknum': 4,
|
| 128 |
+
# 'chart_num': 3,
|
| 129 |
+
# 'model_name': 'gpt-4'
|
| 130 |
+
# # 'model_name': 'chatgpt-4o-latest'
|
| 131 |
+
# }, {
|
| 132 |
+
# 'top_method_num': 6,
|
| 133 |
+
# 'problem_analysis_round': 1,
|
| 134 |
+
# 'problem_modeling_round': 1,
|
| 135 |
+
# 'task_formulas_round': 1,
|
| 136 |
+
# 'tasknum': 4,
|
| 137 |
+
# 'chart_num': 3,
|
| 138 |
+
# 'model_name': 'deepseek-reasoner'
|
| 139 |
+
# }, {
|
| 140 |
+
# 'top_method_num': 6,
|
| 141 |
+
# 'problem_analysis_round': 1,
|
| 142 |
+
# 'problem_modeling_round': 1,
|
| 143 |
+
# 'task_formulas_round': 1,
|
| 144 |
+
# 'tasknum': 4,
|
| 145 |
+
# 'chart_num': 3,
|
| 146 |
+
# 'model_name': 'DeepSeek-R1-671B'
|
| 147 |
+
# }][0:]
|
| 148 |
+
config_list = [{
|
| 149 |
+
'top_method_num': 6,
|
| 150 |
+
'problem_analysis_round': 1,
|
| 151 |
+
'problem_modeling_round': 1,
|
| 152 |
+
'task_formulas_round': 1,
|
| 153 |
+
'tasknum': 4,
|
| 154 |
+
'chart_num': 3,
|
| 155 |
+
'model_name': 'gpt-4'
|
| 156 |
+
}][0:]
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
for i, config in enumerate(config_list, start=1):
|
| 160 |
+
for file in files:
|
| 161 |
+
try:
|
| 162 |
+
name = file.split('/')[-1].split('.')[0] + '_wo_coo'
|
| 163 |
+
dataset_path = os.path.join('data/actor_data/input/dataset', file.split('/')[-1].split('.')[0])
|
| 164 |
+
output_dir = 'data/actor_data/output'
|
| 165 |
+
if not os.path.exists(output_dir):
|
| 166 |
+
os.makedirs(output_dir)
|
| 167 |
+
output_path = os.path.join(output_dir, name + '_{}'.format(datetime.now().strftime('%Y%m%d-%H%M%S')))
|
| 168 |
+
if not os.path.exists(output_path):
|
| 169 |
+
mkdir(output_path)
|
| 170 |
+
print(f'Processing {file}..., config: {config}')
|
| 171 |
+
paper = run_batch(problem_path=file, config=config, name=name, dataset_path=dataset_path, output_path=output_path)
|
| 172 |
+
# save_paper(paper, name)
|
| 173 |
+
except Exception as e:
|
| 174 |
+
raise
|
| 175 |
+
print(f'Error: {e}')
|
| 176 |
+
continue
|
core/run_batch_wo_rag.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llm.llm import LLM
|
| 2 |
+
from prompt.constants import modeling_methods
|
| 3 |
+
from input.problem import problem_input
|
| 4 |
+
# from input.test_middle_result import problem_str, problem_analysis, selected_models, modeling_solution, modeling_solution, task_descriptions
|
| 5 |
+
from agent.problem_analysis import ProblemAnalysis
|
| 6 |
+
from agent.method_ranking import MethodRanking
|
| 7 |
+
from agent.problem_modeling import ProblemModeling
|
| 8 |
+
from agent.task_decompse import TaskDecompose
|
| 9 |
+
from agent.task import Task
|
| 10 |
+
from agent.create_charts import Chart
|
| 11 |
+
from agent.coordinator import Coordinator
|
| 12 |
+
from utils.utils import read_json_file, write_json_file, write_text_file, json_to_markdown
|
| 13 |
+
from prompt.template import TASK_ANALYSIS_APPEND_PROMPT, TASK_FORMULAS_APPEND_PROMPT, TASK_MODELING_APPEND_PROMPT
|
| 14 |
+
# from utils.convert_format import markdown_to_latex
|
| 15 |
+
import os
|
| 16 |
+
from datetime import datetime
|
| 17 |
+
import shutil
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def run_batch(problem_path, config, name, dataset_path, output_path):
|
| 21 |
+
# Initialize LLM
|
| 22 |
+
llm = LLM(config['model_name'])
|
| 23 |
+
|
| 24 |
+
# Get problem input
|
| 25 |
+
problem_str, problem = problem_input(problem_path, llm)
|
| 26 |
+
problem_type = os.path.splitext(os.path.basename(problem_path))[0].split('_')[-1]
|
| 27 |
+
|
| 28 |
+
# Initialize paper dictionary
|
| 29 |
+
paper = {'tasks': []}
|
| 30 |
+
paper['problem_background'] = problem['background']
|
| 31 |
+
paper['problem_requirement'] = problem['problem_requirement']
|
| 32 |
+
|
| 33 |
+
# Problem analysis
|
| 34 |
+
pa = ProblemAnalysis(llm)
|
| 35 |
+
problem_analysis = pa.analysis(problem_str, round=config['problem_analysis_round'])
|
| 36 |
+
paper['problem_analysis'] = problem_analysis
|
| 37 |
+
|
| 38 |
+
# Problem modeling
|
| 39 |
+
pm = ProblemModeling(llm)
|
| 40 |
+
modeling_solution = pm.modeling(problem_str, problem_analysis, modeling_methods, round=config['problem_modeling_round'])
|
| 41 |
+
|
| 42 |
+
# Task decomposition
|
| 43 |
+
td = TaskDecompose(llm)
|
| 44 |
+
task_descriptions = td.decompose_and_refine(problem_str, problem_analysis, modeling_solution, problem_type, config['tasknum'])
|
| 45 |
+
|
| 46 |
+
# Analyze dependency
|
| 47 |
+
with_code = len(problem['dataset_path']) > 0
|
| 48 |
+
coordinator = Coordinator(llm)
|
| 49 |
+
order = coordinator.analyze_dependencies(problem_str, problem_analysis, modeling_solution, task_descriptions, with_code)
|
| 50 |
+
order = [int(i) for i in order]
|
| 51 |
+
|
| 52 |
+
if with_code:
|
| 53 |
+
shutil.copytree(dataset_path, os.path.join(output_path,'code'), dirs_exist_ok=True)
|
| 54 |
+
|
| 55 |
+
# Process tasks
|
| 56 |
+
task = Task(llm, rag=False)
|
| 57 |
+
chart = Chart(llm)
|
| 58 |
+
for id in order:
|
| 59 |
+
task_dependency = [int(i) for i in coordinator.DAG[str(id)]]
|
| 60 |
+
dependent_file_prompt = ""
|
| 61 |
+
if len(task_dependency) > 0:
|
| 62 |
+
dependency_prompt = f"""\
|
| 63 |
+
This task is Task {id}, which depends on the following tasks: {task_dependency}. The dependencies for this task are analyzed as follows: {coordinator.task_dependency_analysis[id - 1]}
|
| 64 |
+
"""
|
| 65 |
+
for task_id in task_dependency:
|
| 66 |
+
dependency_prompt += f"""\
|
| 67 |
+
---
|
| 68 |
+
# The Description of Task {task_id}:
|
| 69 |
+
{coordinator.memory[str(task_id)]['task_description']}
|
| 70 |
+
# The modeling method for Task {task_id}:
|
| 71 |
+
{coordinator.memory[str(task_id)]['mathematical_modeling_process']}
|
| 72 |
+
"""
|
| 73 |
+
if with_code:
|
| 74 |
+
dependency_prompt += f"""\
|
| 75 |
+
# The structure of code for Task {task_id}:
|
| 76 |
+
{coordinator.code_memory[str(task_id)]}
|
| 77 |
+
# The result for Task {task_id}:
|
| 78 |
+
{coordinator.memory[str(task_id)]['solution_interpretation']}
|
| 79 |
+
---
|
| 80 |
+
"""
|
| 81 |
+
dependent_file_prompt += f"""\
|
| 82 |
+
# The files generated by code for Task {task_id}:
|
| 83 |
+
{coordinator.code_memory[str(task_id)]}
|
| 84 |
+
"""
|
| 85 |
+
coordinator.code_memory[str(task_id)]['file_outputs']
|
| 86 |
+
else:
|
| 87 |
+
dependency_prompt += f"""\
|
| 88 |
+
# The result for Task {task_id}:
|
| 89 |
+
{coordinator.memory[str(task_id)]['solution_interpretation']}
|
| 90 |
+
---
|
| 91 |
+
"""
|
| 92 |
+
|
| 93 |
+
task_analysis_prompt = dependency_prompt + TASK_ANALYSIS_APPEND_PROMPT
|
| 94 |
+
task_formulas_prompt = dependency_prompt + TASK_FORMULAS_APPEND_PROMPT
|
| 95 |
+
task_modeling_prompt = dependency_prompt + TASK_MODELING_APPEND_PROMPT
|
| 96 |
+
else:
|
| 97 |
+
task_analysis_prompt = ""
|
| 98 |
+
task_formulas_prompt = ""
|
| 99 |
+
task_modeling_prompt = ""
|
| 100 |
+
|
| 101 |
+
code_template = open(os.path.join('data/actor_data/input/code_template','main{}.py'.format(id))).read()
|
| 102 |
+
save_path = os.path.join(output_path,'code/main{}.py'.format(id))
|
| 103 |
+
work_dir = os.path.join(output_path,'code')
|
| 104 |
+
script_name = 'main{}.py'.format(id)
|
| 105 |
+
|
| 106 |
+
task_description = task_descriptions[id - 1]
|
| 107 |
+
task_analysis = task.analysis(task_analysis_prompt, task_description)
|
| 108 |
+
top_modeling_methods = ""
|
| 109 |
+
|
| 110 |
+
task_formulas = task.formulas(task_formulas_prompt, problem['data_description'], task_description, task_analysis, top_modeling_methods, round=config['task_formulas_round'])
|
| 111 |
+
task_modeling = task.modeling(task_modeling_prompt, problem['data_description'], task_description, task_analysis, task_formulas)
|
| 112 |
+
if with_code:
|
| 113 |
+
task_code, is_pass, execution_result = task.coding(problem['dataset_path'], problem['data_description'], problem['variable_description'], task_description, task_analysis, task_formulas, task_modeling, dependent_file_prompt, code_template, script_name, work_dir)
|
| 114 |
+
code_structure = task.extract_code_structure(id, task_code, save_path)
|
| 115 |
+
task_result = task.result(task_description, task_analysis, task_formulas, task_modeling, execution_result)
|
| 116 |
+
task_answer = task.answer(task_description, task_analysis, task_formulas, task_modeling, task_result)
|
| 117 |
+
task_dict = {
|
| 118 |
+
'task_description': task_description,
|
| 119 |
+
'task_analysis': task_analysis,
|
| 120 |
+
'preliminary_formulas': task_formulas,
|
| 121 |
+
'mathematical_modeling_process': task_modeling,
|
| 122 |
+
'task_code': task_code,
|
| 123 |
+
'is_pass': is_pass,
|
| 124 |
+
'execution_result': execution_result,
|
| 125 |
+
'solution_interpretation': task_result,
|
| 126 |
+
'subtask_outcome_analysis': task_answer
|
| 127 |
+
}
|
| 128 |
+
coordinator.code_memory[str(id)] = code_structure
|
| 129 |
+
else:
|
| 130 |
+
task_result = task.result(task_description, task_analysis, task_formulas, task_modeling)
|
| 131 |
+
task_answer = task.answer(task_description, task_analysis, task_formulas, task_modeling, task_result)
|
| 132 |
+
task_dict = {
|
| 133 |
+
'task_description': task_description,
|
| 134 |
+
'task_analysis': task_analysis,
|
| 135 |
+
'preliminary_formulas': task_formulas,
|
| 136 |
+
'mathematical_modeling_process': task_modeling,
|
| 137 |
+
'solution_interpretation': task_result,
|
| 138 |
+
'subtask_outcome_analysis': task_answer
|
| 139 |
+
}
|
| 140 |
+
coordinator.memory[str(id)] = task_dict
|
| 141 |
+
charts = chart.create_charts(str(task_dict), config['chart_num'])
|
| 142 |
+
task_dict['charts'] = charts
|
| 143 |
+
paper['tasks'].append(task_dict)
|
| 144 |
+
save_paper(paper, name, output_path)
|
| 145 |
+
|
| 146 |
+
print(paper)
|
| 147 |
+
print('Usage:', llm.get_total_usage())
|
| 148 |
+
write_json_file(f'{output_path}/usage/{name}.json', llm.get_total_usage())
|
| 149 |
+
return paper
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def save_paper(paper, name, path):
|
| 153 |
+
write_json_file(f'{path}/json/{name}.json', paper)
|
| 154 |
+
markdown_str = json_to_markdown(paper)
|
| 155 |
+
write_text_file(f'{path}/markdown/{name}.md', markdown_str)
|
| 156 |
+
# write_text_file(f'data/actor_data/output/latex/{name}.tex', markdown_to_latex(markdown_str))
|
| 157 |
+
|
| 158 |
+
def mkdir(path):
|
| 159 |
+
os.mkdir(path)
|
| 160 |
+
os.mkdir(path + '/json')
|
| 161 |
+
os.mkdir(path + '/markdown')
|
| 162 |
+
os.mkdir(path + '/latex')
|
| 163 |
+
os.mkdir(path + '/code')
|
| 164 |
+
os.mkdir(path + '/usage')
|
| 165 |
+
|
| 166 |
+
if __name__ == "__main__":
|
| 167 |
+
import glob
|
| 168 |
+
# files = glob.glob('data/actor_data/input/problem/2024*')
|
| 169 |
+
files = glob.glob('data/actor_data/input/problem/2024_C*')
|
| 170 |
+
|
| 171 |
+
# config_list = [{
|
| 172 |
+
# 'top_method_num': 6,
|
| 173 |
+
# 'problem_analysis_round': 1,
|
| 174 |
+
# 'problem_modeling_round': 1,
|
| 175 |
+
# 'task_formulas_round': 1,
|
| 176 |
+
# 'tasknum': 4,
|
| 177 |
+
# 'chart_num': 3,
|
| 178 |
+
# 'model_name': 'gpt-4'
|
| 179 |
+
# # 'model_name': 'chatgpt-4o-latest'
|
| 180 |
+
# }, {
|
| 181 |
+
# 'top_method_num': 6,
|
| 182 |
+
# 'problem_analysis_round': 1,
|
| 183 |
+
# 'problem_modeling_round': 1,
|
| 184 |
+
# 'task_formulas_round': 1,
|
| 185 |
+
# 'tasknum': 4,
|
| 186 |
+
# 'chart_num': 3,
|
| 187 |
+
# 'model_name': 'deepseek-reasoner'
|
| 188 |
+
# }, {
|
| 189 |
+
# 'top_method_num': 6,
|
| 190 |
+
# 'problem_analysis_round': 1,
|
| 191 |
+
# 'problem_modeling_round': 1,
|
| 192 |
+
# 'task_formulas_round': 1,
|
| 193 |
+
# 'tasknum': 4,
|
| 194 |
+
# 'chart_num': 3,
|
| 195 |
+
# 'model_name': 'DeepSeek-R1-671B'
|
| 196 |
+
# }][0:]
|
| 197 |
+
config_list = [{
|
| 198 |
+
'top_method_num': 6,
|
| 199 |
+
'problem_analysis_round': 1,
|
| 200 |
+
'problem_modeling_round': 1,
|
| 201 |
+
'task_formulas_round': 1,
|
| 202 |
+
'tasknum': 4,
|
| 203 |
+
'chart_num': 3,
|
| 204 |
+
'model_name': 'gpt-4'
|
| 205 |
+
}][0:]
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
for i, config in enumerate(config_list, start=1):
|
| 209 |
+
for file in files:
|
| 210 |
+
try:
|
| 211 |
+
name = file.split('/')[-1].split('.')[0] + '_wo_rag'
|
| 212 |
+
dataset_path = os.path.join('data/actor_data/input/dataset', file.split('/')[-1].split('.')[0])
|
| 213 |
+
output_dir = 'data/actor_data/output'
|
| 214 |
+
if not os.path.exists(output_dir):
|
| 215 |
+
os.makedirs(output_dir)
|
| 216 |
+
output_path = os.path.join(output_dir, name + '_{}'.format(datetime.now().strftime('%Y%m%d-%H%M%S')))
|
| 217 |
+
if not os.path.exists(output_path):
|
| 218 |
+
mkdir(output_path)
|
| 219 |
+
print(f'Processing {file}..., config: {config}')
|
| 220 |
+
paper = run_batch(problem_path=file, config=config, name=name, dataset_path=dataset_path, output_path=output_path)
|
| 221 |
+
# save_paper(paper, name)
|
| 222 |
+
except Exception as e:
|
| 223 |
+
raise
|
| 224 |
+
print(f'Error: {e}')
|
| 225 |
+
continue
|
core/test.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llm.llm import LLM
|
| 2 |
+
from input.problem import problem_input
|
| 3 |
+
from input.test_middle_result import problem_str, selected_models, modeling_solution, task_descriptions
|
| 4 |
+
from agent.model_selection import ModelSelection
|
| 5 |
+
from agent.modeling import Modeling
|
| 6 |
+
from agent.task_decompse import TaskDecompose
|
| 7 |
+
from agent.task import Task
|
| 8 |
+
from utils.utils import write_json_file, write_markdown_file, json_to_markdown
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
if __name__ == "__main__":
|
| 12 |
+
llm = LLM('deepseek-chat')
|
| 13 |
+
paper = {'tasks': []}
|
| 14 |
+
|
| 15 |
+
problem_path = 'data/actor_data/input/problem/2024_C.json'
|
| 16 |
+
problem_str, problem = problem_input(problem_path, llm)
|
| 17 |
+
# print(problem_str)
|
| 18 |
+
# print('---')
|
| 19 |
+
paper['problem_background'] = problem['background']
|
| 20 |
+
paper['problem_requirement'] = problem['problem_requirement']
|
| 21 |
+
|
| 22 |
+
ms = ModelSelection(llm)
|
| 23 |
+
selected_models = ms.select_models(problem_str)
|
| 24 |
+
print(selected_models)
|
| 25 |
+
print('---')
|
| 26 |
+
|
| 27 |
+
mm = Modeling(llm)
|
| 28 |
+
modeling_solution = mm.modeling(problem_str, selected_models)
|
| 29 |
+
print(modeling_solution)
|
| 30 |
+
print('---')
|
| 31 |
+
|
| 32 |
+
td = TaskDecompose(llm)
|
| 33 |
+
task_descriptions = td.decompose(problem_str, modeling_solution)
|
| 34 |
+
print(task_descriptions)
|
| 35 |
+
print('---')
|
| 36 |
+
|
| 37 |
+
task = Task(llm)
|
| 38 |
+
for task_description in task_descriptions[:]:
|
| 39 |
+
task_analysis = task.analysis(task_description)
|
| 40 |
+
task_modeling = task.modeling(task_description, task_analysis, problem['data_summary'])
|
| 41 |
+
task_result = task.result(task_description, task_analysis, task_modeling)
|
| 42 |
+
task_answer = task.answer(task_description, task_analysis, task_modeling, task_result)
|
| 43 |
+
paper['tasks'].append({
|
| 44 |
+
'task_description': task_description,
|
| 45 |
+
'task_analysis': task_analysis,
|
| 46 |
+
'mathematical_modeling_process': task_modeling,
|
| 47 |
+
'result': task_result,
|
| 48 |
+
'answer': task_answer
|
| 49 |
+
})
|
| 50 |
+
print(paper)
|
| 51 |
+
|
| 52 |
+
print(llm.get_total_usage())
|
| 53 |
+
|
| 54 |
+
write_json_file('data/actor_data/output/paper4.json', paper)
|
| 55 |
+
write_markdown_file('data/actor_data/output/paper4.md', json_to_markdown(paper))
|
| 56 |
+
|
core/test2.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llm.llm import LLM
|
| 2 |
+
from input.problem import problem_input
|
| 3 |
+
from input.test_middle_result import problem_str, problem_analysis, selected_models, modeling_solution, modeling_solution, task_descriptions
|
| 4 |
+
from agent.problem_analysis import ProblemAnalysis
|
| 5 |
+
from agent.problem_modeling import ProblemModeling
|
| 6 |
+
from agent.task_decompse import TaskDecompose
|
| 7 |
+
from agent.task import Task
|
| 8 |
+
from utils.utils import read_json_file, write_json_file, write_markdown_file, json_to_markdown
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
if __name__ == "__main__":
|
| 12 |
+
# llm = LLM('deepseek-chat')
|
| 13 |
+
llm = LLM('deepseek-reasoner')
|
| 14 |
+
# llm = LLM('gpt-4o')
|
| 15 |
+
paper = {'tasks': []}
|
| 16 |
+
|
| 17 |
+
problem_path = 'data/actor_data/input/problem/2024_C.json'
|
| 18 |
+
problem_str, problem = problem_input(problem_path, llm)
|
| 19 |
+
problem_type = problem_path.split('/')[-1].split('_')[-1].split('.')[0] # 'C'
|
| 20 |
+
tasknum = 4
|
| 21 |
+
|
| 22 |
+
print(problem_str)
|
| 23 |
+
print('---')
|
| 24 |
+
paper['problem_background'] = problem['background']
|
| 25 |
+
paper['problem_requirement'] = problem['problem_requirement']
|
| 26 |
+
|
| 27 |
+
# pa = ProblemAnalysis(llm)
|
| 28 |
+
# problem_analysis = pa.analysis(problem_str, round=1)
|
| 29 |
+
# print(problem_analysis)
|
| 30 |
+
# print('---')
|
| 31 |
+
|
| 32 |
+
# pm = ProblemModeling(llm)
|
| 33 |
+
# modeling_solution = pm.modeling(problem_str, problem_analysis, round=1)
|
| 34 |
+
# print(modeling_solution)
|
| 35 |
+
# print('---')
|
| 36 |
+
|
| 37 |
+
# td = TaskDecompose(llm)
|
| 38 |
+
# task_descriptions = td.decompose_and_refine(problem_str, problem_analysis, modeling_solution, problem_type, tasknum)
|
| 39 |
+
# print(task_descriptions)
|
| 40 |
+
# print('---')
|
| 41 |
+
|
| 42 |
+
task = Task(llm)
|
| 43 |
+
for task_description in task_descriptions[:1]:
|
| 44 |
+
task_analysis = task.analysis(task_description)
|
| 45 |
+
task_formulas = task.formulas(problem['data_description'], task_description, task_analysis)
|
| 46 |
+
task_modeling = task.modeling(problem['data_description'], task_description, task_analysis, task_formulas)
|
| 47 |
+
task_result = task.result(task_description, task_analysis, task_formulas, task_modeling)
|
| 48 |
+
task_answer = task.answer(task_description, task_analysis, task_formulas, task_modeling, task_result)
|
| 49 |
+
paper['tasks'].append({
|
| 50 |
+
'task_description': task_description,
|
| 51 |
+
'task_analysis': task_analysis,
|
| 52 |
+
'mathematical_formulas': task_formulas,
|
| 53 |
+
'mathematical_modeling_process': task_modeling,
|
| 54 |
+
'result': task_result,
|
| 55 |
+
'answer': task_answer
|
| 56 |
+
})
|
| 57 |
+
print(paper['tasks'])
|
| 58 |
+
|
| 59 |
+
print(llm.get_total_usage())
|
core/utils/convert_format.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import re
|
| 3 |
+
import pypandoc
|
| 4 |
+
|
| 5 |
+
# A sample Markdown string
|
| 6 |
+
markdown_text = """
|
| 7 |
+
# My Document
|
| 8 |
+
|
| 9 |
+
Some **bold** text here, and some *italic* text there.
|
| 10 |
+
|
| 11 |
+
- Bullet point 1
|
| 12 |
+
- Bullet point 2
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def markdown_to_latex(markdown_text):
|
| 17 |
+
# Convert Markdown string to LaTeX
|
| 18 |
+
latex_text = pypandoc.convert_text(markdown_text, to='latex', format='md')
|
| 19 |
+
return latex_text
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def markdown_to_json_method(markdown_text):
|
| 23 |
+
# 初始化根节点和层级堆栈,初始层级设为 0,以便支持一级标题
|
| 24 |
+
root = {"method_class": "root", "children": []}
|
| 25 |
+
stack = [{"node": root, "level": 0}] # 用堆栈跟踪层级关系
|
| 26 |
+
|
| 27 |
+
lines = markdown_text.strip().split('\n')
|
| 28 |
+
i = 0
|
| 29 |
+
|
| 30 |
+
while i < len(lines):
|
| 31 |
+
line = lines[i].strip()
|
| 32 |
+
i += 1
|
| 33 |
+
|
| 34 |
+
if not line:
|
| 35 |
+
continue
|
| 36 |
+
|
| 37 |
+
# 匹配标题
|
| 38 |
+
if line.startswith('#'):
|
| 39 |
+
match = re.match(r'^(#+)\s*(.*?)$', line)
|
| 40 |
+
if not match:
|
| 41 |
+
continue
|
| 42 |
+
hashes, method_class = match.groups()
|
| 43 |
+
current_level = len(hashes)
|
| 44 |
+
|
| 45 |
+
# 创建新节点
|
| 46 |
+
new_node = {"method_class": method_class, "children": [], "description": ""}
|
| 47 |
+
|
| 48 |
+
# 寻找合适的父节点
|
| 49 |
+
while stack and stack[-1]["level"] >= current_level:
|
| 50 |
+
stack.pop()
|
| 51 |
+
|
| 52 |
+
# 如果没有找到合适的父节点,则将 new_node 加入到 root 下
|
| 53 |
+
if stack:
|
| 54 |
+
parent = stack[-1]["node"]
|
| 55 |
+
else:
|
| 56 |
+
parent = root
|
| 57 |
+
parent["children"].append(new_node)
|
| 58 |
+
|
| 59 |
+
# 更新堆栈
|
| 60 |
+
stack.append({"node": new_node, "level": current_level})
|
| 61 |
+
|
| 62 |
+
# 查找紧随标题后的描述文本
|
| 63 |
+
description_lines = []
|
| 64 |
+
while i < len(lines) and lines[i].strip() and not lines[i].strip().startswith('#') and not lines[i].strip().startswith('-'):
|
| 65 |
+
description_lines.append(lines[i].strip())
|
| 66 |
+
i += 1
|
| 67 |
+
|
| 68 |
+
if description_lines:
|
| 69 |
+
new_node["description"] = " ".join(description_lines)
|
| 70 |
+
|
| 71 |
+
# 回退一行,因为下一行可能是列表项或新标题
|
| 72 |
+
if i < len(lines):
|
| 73 |
+
i -= 1
|
| 74 |
+
|
| 75 |
+
# 匹配列表项
|
| 76 |
+
elif line.startswith('-'):
|
| 77 |
+
item = {}
|
| 78 |
+
if ': ' in line:
|
| 79 |
+
method, description = line[1:].strip().split(': ', 1)
|
| 80 |
+
description = description
|
| 81 |
+
item = {"method": method.strip(), "description": description.strip()}
|
| 82 |
+
else:
|
| 83 |
+
item = {"method": line[1:].strip(), "description": ""}
|
| 84 |
+
|
| 85 |
+
# 添加到当前层级的子节点;若无标题节点,则直接添加到 root
|
| 86 |
+
if stack:
|
| 87 |
+
current_node = stack[-1]["node"]
|
| 88 |
+
current_node.setdefault("children", []).append(item)
|
| 89 |
+
else:
|
| 90 |
+
root.setdefault("children", []).append(item)
|
| 91 |
+
|
| 92 |
+
# 返回所有解析到的顶级标题节点
|
| 93 |
+
return root["children"]
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
with open("../data/actor_data/docs/method_en_v1.md", "r", encoding="utf-8") as f:
|
| 98 |
+
markdown_text = f.read()
|
| 99 |
+
|
| 100 |
+
result = markdown_to_json_method(markdown_text)
|
| 101 |
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
# AIzaSyCfcnYh7jBDnjP7kex7HEj4rpUpHRxvM_0
|
core/utils/decompose_analysis.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
from llm.llm import LLM
|
| 3 |
+
from collections import Counter, defaultdict
|
| 4 |
+
from prompt.template import DECOMPOSE_PRINCIPLE_PROMPT
|
| 5 |
+
|
| 6 |
+
from utils.utils import read_json_file, write_json_file
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def read_problem_papers(problem_name):
|
| 10 |
+
paper_dict = read_json_file('../data/paper_info_dataset.json')['data']
|
| 11 |
+
papers = []
|
| 12 |
+
for paper in paper_dict:
|
| 13 |
+
if paper['paper'].startswith(problem_name):
|
| 14 |
+
papers.append(paper['info'])
|
| 15 |
+
return papers
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def generate_decompose_prompt(data):
|
| 19 |
+
# llm = LLM('deepseek-reasoner')
|
| 20 |
+
llm = LLM('chatgpt-4o-latest')
|
| 21 |
+
# Step 1: Filter papers from 2015 and later
|
| 22 |
+
filtered_papers = [paper for paper in data if paper['paper'].split('/')[0] >= '2014']
|
| 23 |
+
|
| 24 |
+
# Step 2: Group by type (A, B, C, D, E, F)
|
| 25 |
+
problem_papers = defaultdict(list)
|
| 26 |
+
|
| 27 |
+
# Loop through the filtered papers and organize by problem type
|
| 28 |
+
for paper in filtered_papers:
|
| 29 |
+
problem = paper['paper'].split('/')[0]
|
| 30 |
+
problem_papers[problem].append(paper['info'])
|
| 31 |
+
|
| 32 |
+
# keep 2 papers for each problem:
|
| 33 |
+
for problem, papers in problem_papers.items():
|
| 34 |
+
if len(papers) > 3:
|
| 35 |
+
problem_papers[problem] = random.sample(papers, 3)
|
| 36 |
+
else:
|
| 37 |
+
problem_papers[problem] = papers
|
| 38 |
+
|
| 39 |
+
# Step 3: Group papers by problem type (second part of the problem identifier)
|
| 40 |
+
problem_type_papers = defaultdict(list)
|
| 41 |
+
for problem, papers in problem_papers.items():
|
| 42 |
+
problem_type = problem.split('_')[1]
|
| 43 |
+
problem_type_papers[problem_type] += papers
|
| 44 |
+
|
| 45 |
+
# Step 4: Group by tasknum (problem_type, len(tasks))
|
| 46 |
+
tasknum_papers = defaultdict(list)
|
| 47 |
+
for problem_type, papers in problem_type_papers.items():
|
| 48 |
+
for paper in papers:
|
| 49 |
+
tasknum_papers[(problem_type, len(paper['tasks']))].append(paper)
|
| 50 |
+
|
| 51 |
+
filtered_tasknum_papers = tasknum_papers
|
| 52 |
+
|
| 53 |
+
# # Step 5: Calculate the top 2 frequent tasknum for each problem_type
|
| 54 |
+
# filtered_tasknum_papers = defaultdict(list)
|
| 55 |
+
# for problem_type, papers in problem_type_papers.items():
|
| 56 |
+
# # Count the frequencies of tasknum within this problem_type
|
| 57 |
+
# tasknum_counts = Counter(len(paper['tasks']) for paper in papers)
|
| 58 |
+
# # Get the two most frequent tasknums
|
| 59 |
+
# most_common_tasknums = [tasknum for tasknum, _ in tasknum_counts.most_common(3)]
|
| 60 |
+
# print(problem_type, most_common_tasknums)
|
| 61 |
+
# # Keep only the papers with the top 2 frequent tasknums
|
| 62 |
+
# for paper in papers:
|
| 63 |
+
# if len(paper['tasks']) in most_common_tasknums:
|
| 64 |
+
# filtered_tasknum_papers[(problem_type, len(paper['tasks']))].append(paper)
|
| 65 |
+
|
| 66 |
+
result = defaultdict(dict)
|
| 67 |
+
for (problem_type, tasknum), papers in filtered_tasknum_papers.items():
|
| 68 |
+
if tasknum not in [3, 4, 5] or problem_type not in ['A', 'B', 'C', 'D', 'E', 'F']:
|
| 69 |
+
continue
|
| 70 |
+
# if tasknum not in [4] or problem_type not in ['C']:
|
| 71 |
+
# continue
|
| 72 |
+
print(f"Problem Type: {problem_type}, Task Number: {tasknum}, size: {len(papers)}")
|
| 73 |
+
selected_papers = random.sample(papers, min(len(papers), 6))
|
| 74 |
+
examples = '---'.join(([task_decompose(paper) for paper in selected_papers]))
|
| 75 |
+
prompt = DECOMPOSE_PRINCIPLE_PROMPT.format(examples=examples, tasknum=tasknum)
|
| 76 |
+
answer = llm.generate(prompt)
|
| 77 |
+
result[problem_type][int(tasknum)] = answer
|
| 78 |
+
|
| 79 |
+
return result
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def task_decompose(paper):
|
| 83 |
+
return '\n'.join([f"- Subtask {i}: {task['task_description'][:]}" for i, task in enumerate(paper['tasks'], start=1)])
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
data = read_json_file('../data/actor_data/input/paper_info_dataset.json')
|
| 88 |
+
result = generate_decompose_prompt(data['data'])
|
| 89 |
+
write_json_file('../data/actor_data/input/decompose_prompt.json', result)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
core/utils/embedding.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List
|
| 2 |
+
import numpy as np
|
| 3 |
+
import torch
|
| 4 |
+
import torch.nn.functional as F
|
| 5 |
+
from transformers import AutoModel, AutoTokenizer
|
| 6 |
+
|
| 7 |
+
class EmbeddingScorer:
|
| 8 |
+
"""
|
| 9 |
+
A class for performing semantic search using embeddings.
|
| 10 |
+
Uses the gte-multilingual-base model from Alibaba-NLP.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
def __init__(self, model_name='Alibaba-NLP/gte-multilingual-base'):
|
| 14 |
+
"""
|
| 15 |
+
Initialize the EmbeddingScorer with the specified model.
|
| 16 |
+
|
| 17 |
+
Args:
|
| 18 |
+
model_name (str): Name of the model to use.
|
| 19 |
+
"""
|
| 20 |
+
# Load the tokenizer and model
|
| 21 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 22 |
+
self.model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
|
| 23 |
+
self.dimension = 768 # The output dimension of the embedding
|
| 24 |
+
|
| 25 |
+
def score_method(self, query: str, methods: List[dict]) -> List[dict]:
|
| 26 |
+
"""
|
| 27 |
+
Calculate similarity between a query and a list of methods.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
query (str): The query sentence.
|
| 31 |
+
methods (list): List of method dictionaries to compare against the query.
|
| 32 |
+
|
| 33 |
+
Returns:
|
| 34 |
+
list: List of similarity scores between the query and each method.
|
| 35 |
+
"""
|
| 36 |
+
# Prepare sentences
|
| 37 |
+
sentences = [f"{method['method']}: {method.get('description', '')}" for method in methods]
|
| 38 |
+
texts = [query] + sentences
|
| 39 |
+
|
| 40 |
+
# Tokenize the input texts
|
| 41 |
+
batch_dict = self.tokenizer(texts, max_length=8192, padding=True, truncation=True, return_tensors='pt')
|
| 42 |
+
|
| 43 |
+
# Get embeddings
|
| 44 |
+
with torch.no_grad():
|
| 45 |
+
outputs = self.model(**batch_dict)
|
| 46 |
+
|
| 47 |
+
# Get embeddings from the last hidden state
|
| 48 |
+
embeddings = outputs.last_hidden_state[:, 0][:self.dimension]
|
| 49 |
+
|
| 50 |
+
# Normalize embeddings
|
| 51 |
+
embeddings = F.normalize(embeddings, p=2, dim=1)
|
| 52 |
+
|
| 53 |
+
# Calculate similarities
|
| 54 |
+
query_embedding = embeddings[0].unsqueeze(0) # Shape: [1, dimension]
|
| 55 |
+
method_embeddings = embeddings[1:] # Shape: [num_methods, dimension]
|
| 56 |
+
|
| 57 |
+
# Calculate cosine similarities (scaled by 100 as in the example)
|
| 58 |
+
similarities = (query_embedding @ method_embeddings.T) * 100
|
| 59 |
+
similarities = similarities.squeeze().tolist()
|
| 60 |
+
|
| 61 |
+
# If only one method, similarities will be a scalar
|
| 62 |
+
if not isinstance(similarities, list):
|
| 63 |
+
similarities = [similarities]
|
| 64 |
+
|
| 65 |
+
# Format results
|
| 66 |
+
result = []
|
| 67 |
+
for i, similarity in enumerate(similarities, start=1):
|
| 68 |
+
result.append({
|
| 69 |
+
"method_index": i,
|
| 70 |
+
"score": float(similarity)
|
| 71 |
+
})
|
| 72 |
+
|
| 73 |
+
return result
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
es = EmbeddingScorer()
|
| 77 |
+
print(es.score_method("How to solve the problem of the user", [{"method": "Method 1", "description": "Description 1"}, {"method": "Method 2", "description": "Description 2"}]))
|
core/utils/generate_paper.py
ADDED
|
@@ -0,0 +1,736 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Academic Paper Generator
|
| 3 |
+
|
| 4 |
+
Generates academic papers in LaTeX format from structured JSON data using
|
| 5 |
+
language models to create content for each section.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import json
|
| 9 |
+
import subprocess
|
| 10 |
+
import os
|
| 11 |
+
import re
|
| 12 |
+
from typing import Dict, List, Any, Optional
|
| 13 |
+
from dataclasses import dataclass
|
| 14 |
+
|
| 15 |
+
# Import statements would be here in a real application
|
| 16 |
+
from prompt.template import PAPER_CHAPTER_PROMPT, PAPER_CHAPTER_WITH_PRECEDING_PROMPT, PAPER_INFO_PROMPT, PAPER_NOTATION_PROMPT
|
| 17 |
+
from llm.llm import LLM
|
| 18 |
+
from utils.utils import parse_llm_output_to_json
|
| 19 |
+
|
| 20 |
+
# --------------------------------
|
| 21 |
+
# Data Models
|
| 22 |
+
# --------------------------------
|
| 23 |
+
|
| 24 |
+
@dataclass
|
| 25 |
+
class Chapter:
|
| 26 |
+
"""Represents a chapter in the paper with its hierarchical structure and content."""
|
| 27 |
+
path: List[str] # Hierarchical path (e.g., ["Problem Analysis", "Task 1 Analysis"])
|
| 28 |
+
content: str = ""
|
| 29 |
+
title: str = ""
|
| 30 |
+
is_generated: bool = False
|
| 31 |
+
needs_content: bool = False
|
| 32 |
+
|
| 33 |
+
@property
|
| 34 |
+
def path_string(self) -> str:
|
| 35 |
+
"""Returns the full path as a string (e.g., 'Problem Analysis > Task 1 Analysis')"""
|
| 36 |
+
return " > ".join(self.path)
|
| 37 |
+
|
| 38 |
+
@property
|
| 39 |
+
def depth(self) -> int:
|
| 40 |
+
"""Returns the heading level (depth in hierarchy)"""
|
| 41 |
+
return len(self.path)
|
| 42 |
+
|
| 43 |
+
@property
|
| 44 |
+
def display_title(self) -> str:
|
| 45 |
+
"""Returns the chapter title to display (custom title or last path element)"""
|
| 46 |
+
return self.title if self.title else self.path[-1]
|
| 47 |
+
|
| 48 |
+
# --------------------------------
|
| 49 |
+
# Language Model Interface
|
| 50 |
+
# --------------------------------
|
| 51 |
+
|
| 52 |
+
def escape_underscores_in_quotes(text):
|
| 53 |
+
pattern = r'(".*?")|(\'.*?\')'
|
| 54 |
+
def replace_underscores(match):
|
| 55 |
+
content = match.group(0)[1:-1]
|
| 56 |
+
escaped_content = content.replace('_', r'\_')
|
| 57 |
+
return f'"{escaped_content}"' if match.group(0).startswith('"') else f"'{escaped_content}'"
|
| 58 |
+
|
| 59 |
+
result = re.sub(pattern, replace_underscores, text, flags=re.DOTALL)
|
| 60 |
+
return result
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
class ContentGenerator:
|
| 64 |
+
"""Interface for generating content using language models"""
|
| 65 |
+
|
| 66 |
+
def __init__(self, llm):
|
| 67 |
+
self.llm = llm
|
| 68 |
+
|
| 69 |
+
def generate_chapter_content(self, prompt: str) -> Dict[str, str]:
|
| 70 |
+
"""Generate chapter content using the language model"""
|
| 71 |
+
response = self.llm.generate(prompt)
|
| 72 |
+
response = escape_underscores_in_quotes(response)
|
| 73 |
+
response = response.replace("```latex", "").replace("```", "")
|
| 74 |
+
# return self._parse_latex_response(response)
|
| 75 |
+
return response
|
| 76 |
+
|
| 77 |
+
def _parse_latex_response(self, latex_string: str) -> Dict[str, str]:
|
| 78 |
+
"""Parse LLM response from LaTeX format"""
|
| 79 |
+
pattern = r"```latex\s*\\chapter{\s*(.*?)\s*}\s*(.*)```"
|
| 80 |
+
match = re.match(pattern, latex_string.strip(), re.DOTALL)
|
| 81 |
+
|
| 82 |
+
if match:
|
| 83 |
+
return {
|
| 84 |
+
"title": match.group(1).strip(),
|
| 85 |
+
"content": match.group(2).strip()
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
# Fallback if format doesn't match
|
| 89 |
+
return {
|
| 90 |
+
"title": "",
|
| 91 |
+
"content": latex_string
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
# --------------------------------
|
| 95 |
+
# Paper Structure
|
| 96 |
+
# --------------------------------
|
| 97 |
+
|
| 98 |
+
class OutlineGenerator:
|
| 99 |
+
"""Creates the hierarchical structure of the paper"""
|
| 100 |
+
|
| 101 |
+
def create_outline(self, task_count: int) -> List[Chapter]:
|
| 102 |
+
"""Create a complete chapter structure based on number of tasks"""
|
| 103 |
+
print(f"Creating paper outline for {task_count} tasks")
|
| 104 |
+
|
| 105 |
+
# Define the structure template
|
| 106 |
+
outline = self._create_base_outline(task_count)
|
| 107 |
+
|
| 108 |
+
# Create chapter objects
|
| 109 |
+
chapters = []
|
| 110 |
+
for path in outline:
|
| 111 |
+
# A chapter needs content if it's a leaf node (has no children)
|
| 112 |
+
needs_content = not any(other[:len(path)] == path and len(other) > len(path)
|
| 113 |
+
for other in outline)
|
| 114 |
+
chapters.append(Chapter(path=path, needs_content=needs_content))
|
| 115 |
+
|
| 116 |
+
content_chapters = sum(1 for c in chapters if c.needs_content)
|
| 117 |
+
print(f"Created {len(chapters)} sections, {content_chapters} require content generation")
|
| 118 |
+
for chapter in chapters:
|
| 119 |
+
print(chapter.path_string)
|
| 120 |
+
return chapters
|
| 121 |
+
|
| 122 |
+
def _create_base_outline(self, task_count: int) -> List[List[str]]:
|
| 123 |
+
"""Define the hierarchical structure of the paper"""
|
| 124 |
+
# Define the template structure
|
| 125 |
+
outline = [
|
| 126 |
+
["Problem Restatement", "Problem Background"],
|
| 127 |
+
["Problem Restatement", "Problem Statement"],
|
| 128 |
+
["Model Assumptions"],
|
| 129 |
+
["Explanation of Assumptions"],
|
| 130 |
+
["Problem Analysis"]
|
| 131 |
+
]
|
| 132 |
+
|
| 133 |
+
# Add task-specific analysis chapters
|
| 134 |
+
for i in range(1, task_count + 1):
|
| 135 |
+
outline.append(["Problem Analysis", f"Task {i} Analysis"])
|
| 136 |
+
|
| 137 |
+
outline.append(["Solution to the Problem"])
|
| 138 |
+
|
| 139 |
+
# Add task-specific solution chapters
|
| 140 |
+
for i in range(1, task_count + 1):
|
| 141 |
+
outline.append(["Solution to the Problem", f"Task {i} Solution", "Model Setup: Assumptions and Chain Models"])
|
| 142 |
+
outline.append(["Solution to the Problem", f"Task {i} Solution", "Model Calculation"])
|
| 143 |
+
|
| 144 |
+
# Add conclusion and reference sections
|
| 145 |
+
outline.extend([
|
| 146 |
+
["Model Conclusion", "Model Advantages"],
|
| 147 |
+
["Model Conclusion", "Model Limitations"],
|
| 148 |
+
["Notation and Explanations"]
|
| 149 |
+
])
|
| 150 |
+
|
| 151 |
+
return outline
|
| 152 |
+
|
| 153 |
+
def generate_chapter_relevance_map(self, task_count: int) -> Dict[str, List[str]]:
|
| 154 |
+
"""
|
| 155 |
+
Dynamically generate chapter relevance mapping based on the number of tasks.
|
| 156 |
+
|
| 157 |
+
Args:
|
| 158 |
+
task_count: Number of tasks in the paper
|
| 159 |
+
|
| 160 |
+
Returns:
|
| 161 |
+
Dictionary mapping chapter paths to lists of related chapter paths
|
| 162 |
+
"""
|
| 163 |
+
relevance_map = {}
|
| 164 |
+
|
| 165 |
+
for i in range(1, task_count + 1):
|
| 166 |
+
setup_path = f"Solution to the Problem > Task {i} Solution > Model Setup: Assumptions and Chain Models"
|
| 167 |
+
relevance_map[setup_path] = [f"Problem Analysis > Task {i} Analysis"]
|
| 168 |
+
|
| 169 |
+
for i in range(1, task_count + 1):
|
| 170 |
+
calculation_path = f"Solution to the Problem > Task {i} Solution > Model Calculation"
|
| 171 |
+
relevance_map[calculation_path] = [
|
| 172 |
+
f"Problem Analysis > Task {i} Analysis",
|
| 173 |
+
f"Solution to the Problem > Task {i} Solution > Model Setup: Assumptions and Chain Models",
|
| 174 |
+
]
|
| 175 |
+
|
| 176 |
+
# Model conclusion chapters should include all task solutions
|
| 177 |
+
task_solutions = []
|
| 178 |
+
for i in range(1, task_count + 1):
|
| 179 |
+
task_solutions += [
|
| 180 |
+
f"Solution to the Problem > Task {i} Solution > Model Calculation",
|
| 181 |
+
f"Solution to the Problem > Task {i} Solution > Model Setup: Assumptions and Chain Models"
|
| 182 |
+
]
|
| 183 |
+
|
| 184 |
+
relevance_map["Model Conclusion > Model Advantages"] = task_solutions.copy()
|
| 185 |
+
relevance_map["Model Conclusion > Model Limitations"] = task_solutions.copy()
|
| 186 |
+
relevance_map["Notation and Explanations"] = task_solutions.copy()
|
| 187 |
+
|
| 188 |
+
return relevance_map
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
# --------------------------------
|
| 192 |
+
# Context Extraction
|
| 193 |
+
# --------------------------------
|
| 194 |
+
|
| 195 |
+
class ContextExtractor:
|
| 196 |
+
"""Extracts relevant data from JSON for each chapter"""
|
| 197 |
+
|
| 198 |
+
def get_context_for_chapter(self, chapter: Chapter, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 199 |
+
"""Extract relevant JSON data for a specific chapter"""
|
| 200 |
+
path = chapter.path
|
| 201 |
+
|
| 202 |
+
# Handle different chapter types
|
| 203 |
+
if path == ["Problem Restatement", "Problem Background"]:
|
| 204 |
+
return {"problem_background": data.get("problem_background", "")}
|
| 205 |
+
|
| 206 |
+
elif path == ["Problem Restatement", "Problem Statement"]:
|
| 207 |
+
return {"problem_requirement": data.get("problem_requirement", "")}
|
| 208 |
+
|
| 209 |
+
elif path == ["Model Assumptions"]:
|
| 210 |
+
return self._get_assumptions_context(data)
|
| 211 |
+
|
| 212 |
+
elif path == ["Explanation of Assumptions"]:
|
| 213 |
+
return {}
|
| 214 |
+
|
| 215 |
+
elif self._is_task_analysis(path):
|
| 216 |
+
return self._get_task_analysis_context(path, data)
|
| 217 |
+
|
| 218 |
+
elif self._is_model_setup(path):
|
| 219 |
+
return self._get_model_setup_context(path, data)
|
| 220 |
+
|
| 221 |
+
elif self._is_model_calculation(path):
|
| 222 |
+
return self._get_model_calculation_context(path, data)
|
| 223 |
+
|
| 224 |
+
# Default empty context for other sections
|
| 225 |
+
return {}
|
| 226 |
+
|
| 227 |
+
def _get_assumptions_context(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 228 |
+
"""Get context for assumptions sections"""
|
| 229 |
+
context = {"problem_analysis": data.get("problem_analysis", "")}
|
| 230 |
+
|
| 231 |
+
# Extract task modeling information
|
| 232 |
+
keys = ['task_description', 'task_analysis', 'mathematical_modeling_process']
|
| 233 |
+
context["tasks"] = [
|
| 234 |
+
{k: v for k, v in task.items() if k in keys}
|
| 235 |
+
for task in data['tasks']
|
| 236 |
+
]
|
| 237 |
+
|
| 238 |
+
return context
|
| 239 |
+
|
| 240 |
+
def _get_task_analysis_context(self, path: List[str], data: Dict[str, Any]) -> Dict[str, Any]:
|
| 241 |
+
"""Get context for task analysis sections"""
|
| 242 |
+
task_num = self._extract_task_number(path[1])
|
| 243 |
+
if not self._is_valid_task_index(task_num, data):
|
| 244 |
+
return {}
|
| 245 |
+
|
| 246 |
+
task_data = data["tasks"][task_num]
|
| 247 |
+
keys = ['task_analysis', 'task_description']
|
| 248 |
+
return {
|
| 249 |
+
f'task_{task_num+1}': {
|
| 250 |
+
k: v for k, v in task_data.items() if k in keys
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
def _get_model_setup_context(self, path: List[str], data: Dict[str, Any]) -> Dict[str, Any]:
|
| 255 |
+
"""Get context for model setup sections"""
|
| 256 |
+
task_num = self._extract_task_number(path[1])
|
| 257 |
+
if not self._is_valid_task_index(task_num, data):
|
| 258 |
+
return {}
|
| 259 |
+
|
| 260 |
+
task_data = data["tasks"][task_num]
|
| 261 |
+
keys = ['preliminary_formulas', 'mathematical_modeling_process']
|
| 262 |
+
return {
|
| 263 |
+
f'task_{task_num+1}': {
|
| 264 |
+
k: task_data.get(k, "") for k in keys
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
def _get_model_calculation_context(self, path: List[str], data: Dict[str, Any]) -> Dict[str, Any]:
|
| 269 |
+
"""Get context for model calculation sections"""
|
| 270 |
+
task_num = self._extract_task_number(path[1])
|
| 271 |
+
if not self._is_valid_task_index(task_num, data):
|
| 272 |
+
return {}
|
| 273 |
+
|
| 274 |
+
task_data = data["tasks"][task_num]
|
| 275 |
+
keys = ['mathematical_modeling_process', 'execution_result', 'solution_interpretation', 'subtask_outcome_analysis']
|
| 276 |
+
return {
|
| 277 |
+
f'task_{task_num+1}': {
|
| 278 |
+
k: task_data.get(k, "") for k in keys
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
def _is_task_analysis(self, path: List[str]) -> bool:
|
| 283 |
+
"""Check if path is a task analysis section"""
|
| 284 |
+
return (len(path) == 2 and
|
| 285 |
+
path[0] == "Problem Analysis" and
|
| 286 |
+
path[1].startswith("Task "))
|
| 287 |
+
|
| 288 |
+
def _is_model_setup(self, path: List[str]) -> bool:
|
| 289 |
+
"""Check if path is a model setup section"""
|
| 290 |
+
return (len(path) == 3 and
|
| 291 |
+
path[0] == "Solution to the Problem" and
|
| 292 |
+
path[1].startswith("Task ") and
|
| 293 |
+
path[2] == "Model Setup: Assumptions and Chain Models")
|
| 294 |
+
|
| 295 |
+
def _is_model_calculation(self, path: List[str]) -> bool:
|
| 296 |
+
"""Check if path is a model calculation section"""
|
| 297 |
+
return (len(path) == 3 and
|
| 298 |
+
path[0] == "Solution to the Problem" and
|
| 299 |
+
path[1].startswith("Task ") and
|
| 300 |
+
path[2] == "Model Calculation")
|
| 301 |
+
|
| 302 |
+
def _extract_task_number(self, task_string: str) -> int:
|
| 303 |
+
"""Extract task number from strings like 'Task 1 Analysis'"""
|
| 304 |
+
try:
|
| 305 |
+
return int(task_string.split()[1]) - 1 # Convert to 0-indexed
|
| 306 |
+
except (IndexError, ValueError):
|
| 307 |
+
return -1
|
| 308 |
+
|
| 309 |
+
def _is_valid_task_index(self, index: int, data: Dict[str, Any]) -> bool:
|
| 310 |
+
"""Check if the task index is valid"""
|
| 311 |
+
return 0 <= index < len(data.get("tasks", []))
|
| 312 |
+
|
| 313 |
+
# --------------------------------
|
| 314 |
+
# Prompt Creation
|
| 315 |
+
# --------------------------------
|
| 316 |
+
|
| 317 |
+
class PromptCreator:
|
| 318 |
+
"""Creates prompts for the language model"""
|
| 319 |
+
|
| 320 |
+
def __init__(self):
|
| 321 |
+
pass
|
| 322 |
+
|
| 323 |
+
def create_prompt(self,
|
| 324 |
+
chapter: Chapter,
|
| 325 |
+
context: Dict[str, Any],
|
| 326 |
+
previous_chapters: List[Chapter]) -> str:
|
| 327 |
+
"""Create a prompt for generating chapter content"""
|
| 328 |
+
# Format JSON context
|
| 329 |
+
json_str = json.dumps(context, indent=2)
|
| 330 |
+
|
| 331 |
+
# Format previous chapters
|
| 332 |
+
previous_text = self._format_previous_chapters(previous_chapters)
|
| 333 |
+
|
| 334 |
+
if chapter.path == ["Notation and Explanations"]:
|
| 335 |
+
return PAPER_NOTATION_PROMPT.format(
|
| 336 |
+
previous_chapters=previous_text,
|
| 337 |
+
)
|
| 338 |
+
else:
|
| 339 |
+
if json_str == '{}':
|
| 340 |
+
return PAPER_CHAPTER_WITH_PRECEDING_PROMPT.format(
|
| 341 |
+
chapter_path=chapter.path_string,
|
| 342 |
+
previous_chapters=previous_text
|
| 343 |
+
)
|
| 344 |
+
else:
|
| 345 |
+
# Build the prompt using the template
|
| 346 |
+
return PAPER_CHAPTER_PROMPT.format(
|
| 347 |
+
chapter_path=chapter.path_string,
|
| 348 |
+
json_context=json_str,
|
| 349 |
+
previous_chapters=previous_text
|
| 350 |
+
)
|
| 351 |
+
|
| 352 |
+
def _format_previous_chapters(self, previous_chapters: List[Chapter]) -> str:
|
| 353 |
+
"""Format previously completed chapters for context"""
|
| 354 |
+
if not previous_chapters:
|
| 355 |
+
return ""
|
| 356 |
+
|
| 357 |
+
text = ""
|
| 358 |
+
for chapter in previous_chapters:
|
| 359 |
+
text += f"Chapter: {chapter.path_string}\n"
|
| 360 |
+
# text += f"Title: {chapter.display_title}\n"
|
| 361 |
+
text += f"{chapter.content}\n\n"
|
| 362 |
+
return text
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
# --------------------------------
|
| 366 |
+
# Document Assembly
|
| 367 |
+
# --------------------------------
|
| 368 |
+
|
| 369 |
+
class LatexDocumentAssembler:
|
| 370 |
+
"""Assembles the final LaTeX document from generated chapters"""
|
| 371 |
+
|
| 372 |
+
def create_document(self, chapters: List[Chapter], metadata: Dict[str, Any]) -> str:
|
| 373 |
+
"""Create a complete LaTeX document"""
|
| 374 |
+
# Reorder chapters (move Notation chapter after Explanation of Assumptions)
|
| 375 |
+
ordered_chapters = self._reorder_chapters(chapters)
|
| 376 |
+
|
| 377 |
+
# Build document parts
|
| 378 |
+
document_parts = [
|
| 379 |
+
self._create_preamble(metadata),
|
| 380 |
+
self._create_abstract(metadata),
|
| 381 |
+
"\\maketitle",
|
| 382 |
+
"\\renewcommand\\cfttoctitlefont{\\hfil\\Large\\bfseries}",
|
| 383 |
+
"\\tableofcontents",
|
| 384 |
+
"\\newpage",
|
| 385 |
+
self._create_body(ordered_chapters, metadata),
|
| 386 |
+
"\\end{document}"
|
| 387 |
+
]
|
| 388 |
+
|
| 389 |
+
return "\n\n".join(document_parts)
|
| 390 |
+
|
| 391 |
+
def _reorder_chapters(self, chapters: List[Chapter]) -> List[Chapter]:
|
| 392 |
+
"""Reorder chapters for better document structure"""
|
| 393 |
+
reordered = []
|
| 394 |
+
notation_chapter = next((ch for ch in chapters if ch.path == ["Notation and Explanations"]), None)
|
| 395 |
+
|
| 396 |
+
for chapter in chapters:
|
| 397 |
+
if chapter.path != ["Notation and Explanations"]:
|
| 398 |
+
reordered.append(chapter)
|
| 399 |
+
# Insert notation chapter after Explanation of Assumptions
|
| 400 |
+
if notation_chapter and chapter.path == ["Explanation of Assumptions"]:
|
| 401 |
+
reordered.append(notation_chapter)
|
| 402 |
+
|
| 403 |
+
return reordered
|
| 404 |
+
|
| 405 |
+
def _add_figure(self, figures: List[str]) -> str:
|
| 406 |
+
"""Add a figure to the content"""
|
| 407 |
+
figure_str = []
|
| 408 |
+
for i, figure_path in enumerate(figures):
|
| 409 |
+
name = figure_path.split('/')[-1].split('.')[0].replace('_', '\\_')
|
| 410 |
+
figure_str.append(f"""
|
| 411 |
+
\\begin{{figure}}[H]
|
| 412 |
+
\\centering
|
| 413 |
+
\\includegraphics[width=0.5\\textwidth]{{{figure_path}}}
|
| 414 |
+
\\caption{{{name}}}
|
| 415 |
+
\\end{{figure}}
|
| 416 |
+
""")
|
| 417 |
+
return figure_str
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
def _add_code(self, codes: List[str]) -> str:
|
| 421 |
+
"""
|
| 422 |
+
\subsection*{Python Code}
|
| 423 |
+
\subsubsection*{main1.py}
|
| 424 |
+
|
| 425 |
+
\begin{lstlisting}[language=Python, frame=single, basicstyle=\ttfamily\small]
|
| 426 |
+
def main1():
|
| 427 |
+
pass
|
| 428 |
+
\end{lstlisting}
|
| 429 |
+
"""
|
| 430 |
+
code_str = [
|
| 431 |
+
"\\clearpage",
|
| 432 |
+
"\\section{Appendix}",
|
| 433 |
+
]
|
| 434 |
+
for i, code_path in enumerate(codes):
|
| 435 |
+
with open(code_path, 'r') as f:
|
| 436 |
+
code = f.read()
|
| 437 |
+
name = code_path.split('/')[-1].replace('_', '\\_')
|
| 438 |
+
code_str.append(f"""
|
| 439 |
+
\\subsubsection*{{{name}}}
|
| 440 |
+
|
| 441 |
+
\\begin{{lstlisting}}[language=Python, frame=single, basicstyle=\\ttfamily\\small]
|
| 442 |
+
{code}
|
| 443 |
+
\\end{{lstlisting}}
|
| 444 |
+
""")
|
| 445 |
+
return code_str
|
| 446 |
+
|
| 447 |
+
def _create_preamble(self, metadata: Dict[str, Any]) -> str:
|
| 448 |
+
"""Create LaTeX preamble with document setup"""
|
| 449 |
+
title = metadata.get("title", "paper_title")
|
| 450 |
+
team = metadata.get("team", "team")
|
| 451 |
+
year = metadata.get("year", "2024")
|
| 452 |
+
problem_type = metadata.get("problem_type", "problem_type")
|
| 453 |
+
|
| 454 |
+
return f"""\\documentclass{{mcmthesis}}
|
| 455 |
+
\\mcmsetup{{CTeX = false,
|
| 456 |
+
tcn = {team}, problem = {problem_type},
|
| 457 |
+
year = {year},
|
| 458 |
+
sheet = true, titleinsheet = true, keywordsinsheet = true,
|
| 459 |
+
titlepage = false, abstract = true}}
|
| 460 |
+
|
| 461 |
+
\\usepackage{{palatino}}
|
| 462 |
+
\\usepackage{{algorithm}}
|
| 463 |
+
\\usepackage{{algpseudocode}}
|
| 464 |
+
\\usepackage{{tocloft}}
|
| 465 |
+
\\usepackage{{amsmath}}
|
| 466 |
+
|
| 467 |
+
\\usepackage{{lastpage}}
|
| 468 |
+
\\renewcommand{{\\cftdot}}{{.}}
|
| 469 |
+
\\renewcommand{{\\cftsecleader}}{{\\cftdotfill{{\\cftdotsep}}}}
|
| 470 |
+
\\renewcommand{{\\cftsubsecleader}}{{\\cftdotfill{{\\cftdotsep}}}}
|
| 471 |
+
\\renewcommand{{\\cftsubsubsecleader}}{{\\cftdotfill{{\\cftdotsep}}}}
|
| 472 |
+
\\renewcommand{{\\headset}}{{{year}\\\\MCM/ICM\\\\Summary Sheet}}
|
| 473 |
+
\\title{{{title}}}
|
| 474 |
+
|
| 475 |
+
\\begin{{document}}"""
|
| 476 |
+
|
| 477 |
+
def _create_abstract(self, metadata: Dict[str, str]) -> str:
|
| 478 |
+
"""Create the abstract section"""
|
| 479 |
+
return f"""\\begin{{abstract}}
|
| 480 |
+
{metadata.get('summary', '')}
|
| 481 |
+
|
| 482 |
+
\\begin{{keywords}}
|
| 483 |
+
{metadata.get('keywords', '')}
|
| 484 |
+
\\end{{keywords}}
|
| 485 |
+
\\end{{abstract}}"""
|
| 486 |
+
|
| 487 |
+
def _create_body(self, chapters: List[Chapter], metadata: Dict[str, Any]) -> str:
|
| 488 |
+
"""Create the main body of the document from chapters"""
|
| 489 |
+
body_parts = []
|
| 490 |
+
current_path = []
|
| 491 |
+
|
| 492 |
+
for chapter in chapters:
|
| 493 |
+
# Add section headings
|
| 494 |
+
if chapter.path == ["Model Conclusion", "Model Advantages"] and metadata.get('figures', []):
|
| 495 |
+
body_parts += self._add_figure(metadata['figures'])
|
| 496 |
+
|
| 497 |
+
for i, section in enumerate(chapter.path):
|
| 498 |
+
# If this path level is new or different
|
| 499 |
+
if i >= len(current_path) or section != current_path[i]:
|
| 500 |
+
# Update current path
|
| 501 |
+
if len(current_path) <= i:
|
| 502 |
+
current_path.append(section)
|
| 503 |
+
else:
|
| 504 |
+
current_path[i] = section
|
| 505 |
+
current_path = current_path[:i+1] # Truncate the path
|
| 506 |
+
|
| 507 |
+
# Use custom title if available for the last level
|
| 508 |
+
title = chapter.display_title if i == chapter.depth - 1 else section
|
| 509 |
+
|
| 510 |
+
# Add section heading at appropriate level
|
| 511 |
+
if i == 0:
|
| 512 |
+
body_parts.append(f"\\section{{{title}}}")
|
| 513 |
+
elif i == 1:
|
| 514 |
+
body_parts.append(f"\\subsection{{{title}}}")
|
| 515 |
+
elif i == 2:
|
| 516 |
+
body_parts.append(f"\\subsubsection{{{title}}}")
|
| 517 |
+
|
| 518 |
+
# Add chapter content if generated
|
| 519 |
+
if chapter.is_generated and chapter.content:
|
| 520 |
+
body_parts.append(chapter.content)
|
| 521 |
+
|
| 522 |
+
body_parts.append("\\section{References}")
|
| 523 |
+
body_parts += self._add_code(metadata['codes'])
|
| 524 |
+
return "\n\n".join(body_parts)
|
| 525 |
+
|
| 526 |
+
# --------------------------------
|
| 527 |
+
# File Operations
|
| 528 |
+
# --------------------------------
|
| 529 |
+
|
| 530 |
+
class FileManager:
|
| 531 |
+
"""Handles file operations for saving papers and generating PDFs"""
|
| 532 |
+
|
| 533 |
+
@staticmethod
|
| 534 |
+
def save_to_file(content: str, filepath: str) -> None:
|
| 535 |
+
"""Save content to a file"""
|
| 536 |
+
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
| 537 |
+
with open(filepath, 'w') as f:
|
| 538 |
+
f.write(content)
|
| 539 |
+
print(f"Document saved to {filepath}")
|
| 540 |
+
|
| 541 |
+
@staticmethod
|
| 542 |
+
def generate_pdf(latex_path: str) -> None:
|
| 543 |
+
"""Generate a PDF from a LaTeX file"""
|
| 544 |
+
print(f"Generating PDF from {latex_path}...")
|
| 545 |
+
|
| 546 |
+
# Run pdflatex twice to ensure references and TOC are correct
|
| 547 |
+
latex_dir = os.path.dirname(latex_path)
|
| 548 |
+
subprocess.run(["pdflatex", f"-output-directory={latex_dir}", "-interaction=nonstopmode", latex_path])
|
| 549 |
+
subprocess.run(["pdflatex", f"-output-directory={latex_dir}", "-interaction=nonstopmode", latex_path])
|
| 550 |
+
|
| 551 |
+
# Clean up auxiliary files
|
| 552 |
+
FileManager._clean_temp_files(latex_path)
|
| 553 |
+
|
| 554 |
+
pdf_path = latex_path.replace('.tex', '.pdf')
|
| 555 |
+
print(f"PDF generated at {pdf_path}")
|
| 556 |
+
|
| 557 |
+
@staticmethod
|
| 558 |
+
def _clean_temp_files(latex_path: str) -> None:
|
| 559 |
+
"""Clean up temporary files created during PDF generation"""
|
| 560 |
+
for ext in ["aux", "log", "toc", "out"]:
|
| 561 |
+
aux_file = latex_path.replace('.tex', f'.{ext}')
|
| 562 |
+
if os.path.exists(aux_file):
|
| 563 |
+
os.remove(aux_file)
|
| 564 |
+
|
| 565 |
+
# --------------------------------
|
| 566 |
+
# Main Paper Generator
|
| 567 |
+
# --------------------------------
|
| 568 |
+
|
| 569 |
+
class PaperGenerator:
|
| 570 |
+
"""Main class that orchestrates the paper generation process"""
|
| 571 |
+
|
| 572 |
+
def __init__(self, llm):
|
| 573 |
+
self.content_generator = ContentGenerator(llm)
|
| 574 |
+
self.outline_generator = OutlineGenerator()
|
| 575 |
+
self.context_extractor = ContextExtractor()
|
| 576 |
+
self.prompt_creator = PromptCreator()
|
| 577 |
+
self.document_assembler = LatexDocumentAssembler()
|
| 578 |
+
self.file_manager = FileManager()
|
| 579 |
+
self.llm = llm
|
| 580 |
+
|
| 581 |
+
def generate_paper(self,
|
| 582 |
+
json_data: Dict[str, Any],
|
| 583 |
+
metadata: Dict[str, Any],
|
| 584 |
+
output_dir: str,
|
| 585 |
+
filename: str) -> None:
|
| 586 |
+
"""Generate a complete academic paper from JSON data"""
|
| 587 |
+
# 1. Create chapter structure
|
| 588 |
+
task_count = len(json_data.get("tasks", []))
|
| 589 |
+
print(f"Starting paper generation with {task_count} tasks")
|
| 590 |
+
chapters = self.outline_generator.create_outline(task_count)
|
| 591 |
+
|
| 592 |
+
# Generate chapter relevance map if not provided
|
| 593 |
+
chapter_relevance_map = self.outline_generator.generate_chapter_relevance_map(task_count)
|
| 594 |
+
|
| 595 |
+
# 2. Generate content for each chapter that needs it
|
| 596 |
+
completed_chapters = []
|
| 597 |
+
for chapter in chapters:
|
| 598 |
+
if chapter.needs_content:
|
| 599 |
+
self._generate_chapter_content(chapter, json_data, completed_chapters, chapter_relevance_map)
|
| 600 |
+
completed_chapters.append(chapter)
|
| 601 |
+
|
| 602 |
+
# 3. Complete metadata if needed
|
| 603 |
+
complete_metadata = self._complete_metadata(chapters, metadata)
|
| 604 |
+
|
| 605 |
+
# 4. Assemble the final document
|
| 606 |
+
document = self.document_assembler.create_document(chapters, complete_metadata)
|
| 607 |
+
|
| 608 |
+
# 5. Save and convert to PDF
|
| 609 |
+
latex_path = f"{output_dir}/{filename}.tex"
|
| 610 |
+
self.file_manager.save_to_file(document, latex_path)
|
| 611 |
+
self.file_manager.generate_pdf(latex_path)
|
| 612 |
+
|
| 613 |
+
def _generate_chapter_content(self,
|
| 614 |
+
chapter: Chapter,
|
| 615 |
+
json_data: Dict[str, Any],
|
| 616 |
+
completed_chapters: List[Chapter],
|
| 617 |
+
chapter_relevance_map: Dict[str, List[str]]) -> None:
|
| 618 |
+
"""Generate content for a single chapter"""
|
| 619 |
+
print(f"Generating content for: {chapter.path_string}")
|
| 620 |
+
|
| 621 |
+
# Get relevant context data for this chapter
|
| 622 |
+
context = self.context_extractor.get_context_for_chapter(chapter, json_data)
|
| 623 |
+
|
| 624 |
+
# Get only the relevant completed chapters for context
|
| 625 |
+
relevant_chapters = self._get_relevant_chapters(chapter, completed_chapters, chapter_relevance_map)
|
| 626 |
+
|
| 627 |
+
# Create prompt and generate content
|
| 628 |
+
prompt = self.prompt_creator.create_prompt(
|
| 629 |
+
chapter, context, relevant_chapters
|
| 630 |
+
)
|
| 631 |
+
# Generate content
|
| 632 |
+
response = self.content_generator.generate_chapter_content(prompt)
|
| 633 |
+
|
| 634 |
+
# Update chapter with generated content
|
| 635 |
+
# chapter.content = response['content']
|
| 636 |
+
# chapter.title = self._format_title(chapter, response['title'])
|
| 637 |
+
chapter.content = response
|
| 638 |
+
chapter.title = ''
|
| 639 |
+
chapter.is_generated = True
|
| 640 |
+
|
| 641 |
+
def _get_relevant_chapters(self,
|
| 642 |
+
chapter: Chapter,
|
| 643 |
+
completed_chapters: List[Chapter],
|
| 644 |
+
chapter_relevance_map: Dict[str, List[str]]) -> List[Chapter]:
|
| 645 |
+
"""Filter completed chapters to only include those relevant to the current chapter"""
|
| 646 |
+
# Get the path string for the current chapter
|
| 647 |
+
current_path = chapter.path_string
|
| 648 |
+
|
| 649 |
+
# If this chapter has specific relevant chapters defined in the map
|
| 650 |
+
if current_path in chapter_relevance_map:
|
| 651 |
+
relevant_paths = chapter_relevance_map[current_path]
|
| 652 |
+
# Filter completed chapters to only include those in the relevant paths
|
| 653 |
+
return [ch for ch in completed_chapters
|
| 654 |
+
if ch.path_string in relevant_paths]
|
| 655 |
+
|
| 656 |
+
# Default: return all completed chapters if no specific relevance is defined
|
| 657 |
+
return completed_chapters
|
| 658 |
+
|
| 659 |
+
def _format_title(self, chapter: Chapter, generated_title: str) -> str:
|
| 660 |
+
"""Format title based on chapter type"""
|
| 661 |
+
# Only use custom titles for certain chapter types
|
| 662 |
+
if (chapter.path[0] == "Problem Analysis" or
|
| 663 |
+
chapter.path[0] == "Solution to the Problem"):
|
| 664 |
+
return generated_title
|
| 665 |
+
return ''
|
| 666 |
+
|
| 667 |
+
def _complete_metadata(self,
|
| 668 |
+
chapters: List[Chapter],
|
| 669 |
+
provided_metadata: Dict[str, Any]) -> Dict[str, Any]:
|
| 670 |
+
"""Complete paper metadata, generating missing fields if needed"""
|
| 671 |
+
# If we need to generate metadata
|
| 672 |
+
if not all(key in provided_metadata for key in
|
| 673 |
+
["title", "summary", "keywords"]):
|
| 674 |
+
print("Generating missing paper metadata...")
|
| 675 |
+
|
| 676 |
+
# Prepare prompt with chapter contents
|
| 677 |
+
chapters_text = "\n\n".join(
|
| 678 |
+
f"Chapter: {ch.path_string}\n{ch.content}"
|
| 679 |
+
for ch in chapters if ch.is_generated
|
| 680 |
+
)
|
| 681 |
+
|
| 682 |
+
prompt = PAPER_INFO_PROMPT.format(paper_chapters=chapters_text)
|
| 683 |
+
|
| 684 |
+
# Retry up to 3 times to get valid metadata
|
| 685 |
+
max_retries = 3
|
| 686 |
+
generated_metadata = {}
|
| 687 |
+
|
| 688 |
+
for attempt in range(max_retries):
|
| 689 |
+
try:
|
| 690 |
+
metadata_response = self.llm.generate(prompt)
|
| 691 |
+
generated_metadata = parse_llm_output_to_json(metadata_response)
|
| 692 |
+
if not generated_metadata:
|
| 693 |
+
raise Exception("No metadata generated")
|
| 694 |
+
break
|
| 695 |
+
except Exception as e:
|
| 696 |
+
print(f"Attempt {attempt+1} failed: {str(e)}")
|
| 697 |
+
if attempt == max_retries - 1: # If this was the last attempt
|
| 698 |
+
print("All attempts to generate metadata failed")
|
| 699 |
+
# Merge with provided metadata (provided takes precedence)
|
| 700 |
+
return {**generated_metadata, **provided_metadata}
|
| 701 |
+
|
| 702 |
+
return provided_metadata
|
| 703 |
+
|
| 704 |
+
# --------------------------------
|
| 705 |
+
# Main Function
|
| 706 |
+
# --------------------------------
|
| 707 |
+
|
| 708 |
+
def generate_paper_from_json(llm, json_data: dict, info: dict, output_dir: str, output_name: str) -> None:
|
| 709 |
+
"""Generate a paper from JSON data"""
|
| 710 |
+
if not os.path.exists(output_dir):
|
| 711 |
+
os.makedirs(output_dir)
|
| 712 |
+
generator = PaperGenerator(llm)
|
| 713 |
+
generator.generate_paper(json_data, info, output_dir, output_name)
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
if __name__ == "__main__":
|
| 718 |
+
# Example usage
|
| 719 |
+
metadata = {
|
| 720 |
+
"team": "Agent",
|
| 721 |
+
"year": "2024",
|
| 722 |
+
"problem_type": "C"
|
| 723 |
+
}
|
| 724 |
+
project_dir = "/Users/ann/Downloads/2024_C_2_20250307-144537"
|
| 725 |
+
json_file_path = f"{project_dir}/json/2024_C_2.json"
|
| 726 |
+
code_dir = f'{project_dir}/code'
|
| 727 |
+
metadata['figures'] = [os.path.join(code_dir, f) for f in os.listdir(code_dir) if f.lower().split('.')[-1] in ['png', 'jpg', 'jpeg']]
|
| 728 |
+
metadata['codes'] = sorted([os.path.join(code_dir, f) for f in os.listdir(code_dir) if f.lower().split('.')[-1] in ['py']])
|
| 729 |
+
with open(json_file_path, 'r') as f:
|
| 730 |
+
json_data = json.loads(f.read())
|
| 731 |
+
json_data['tasks'] = json_data['tasks'][:]
|
| 732 |
+
# Initialize language model
|
| 733 |
+
llm = LLM(model_name='gpt-4o')
|
| 734 |
+
# Generate paper with chapter relevance mapping
|
| 735 |
+
generate_paper_from_json(llm, json_data, metadata, f"{project_dir}/latex", 'solution')
|
| 736 |
+
|
core/utils/generate_problem.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llm.llm import LLM
|
| 2 |
+
from input.problem import problem_input
|
| 3 |
+
# from input.test_middle_result import problem_str, problem_analysis, selected_models, modeling_solution, modeling_solution, task_descriptions
|
| 4 |
+
from agent.problem_analysis import ProblemAnalysis
|
| 5 |
+
from agent.problem_modeling import ProblemModeling
|
| 6 |
+
from agent.task_decompse import TaskDecompose
|
| 7 |
+
from agent.task import Task
|
| 8 |
+
from agent.create_charts import Chart
|
| 9 |
+
from utils.utils import read_json_file, write_json_file, write_text_file, json_to_markdown
|
| 10 |
+
# from utils.convert_format import markdown_to_latex
|
| 11 |
+
import os
|
| 12 |
+
from prompt.template import PROBLEM_EXTRACT_PROMPT
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
config = {
|
| 16 |
+
'problem_analysis_round': 1,
|
| 17 |
+
'problem_modeling_round': 1,
|
| 18 |
+
'task_formulas_round': 1,
|
| 19 |
+
'tasknum': 4,
|
| 20 |
+
'chart_num': 3,
|
| 21 |
+
'model_name': 'chatgpt-4o-latest'
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
def run_batch(problem_path, config):
|
| 25 |
+
# Initialize LLM
|
| 26 |
+
llm = LLM(config['model_name'])
|
| 27 |
+
|
| 28 |
+
# Get problem input
|
| 29 |
+
problem_str, problem = problem_input(problem_path, llm)
|
| 30 |
+
problem_name = os.path.splitext(os.path.basename(problem_path))[0]
|
| 31 |
+
problem_type = os.path.splitext(os.path.basename(problem_path))[0].split('_')[-1]
|
| 32 |
+
|
| 33 |
+
return {problem_name: problem}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
import glob
|
| 38 |
+
# files = glob.glob('/Users/ann/Downloads/methmatical_paper_extraction/parse/2025_*/content/*.md')
|
| 39 |
+
files = glob.glob('../data/actor_data/input/problem/2025_*')
|
| 40 |
+
problems = read_json_file('../data/actor_data/output/problem_24.json')
|
| 41 |
+
for file in files:
|
| 42 |
+
problems.update(run_batch(file, config))
|
| 43 |
+
|
| 44 |
+
write_json_file('../data/actor_data/output/problem_25.json', problems)
|
| 45 |
+
print(problems.keys())
|
core/utils/problem2.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llm.llm import LLM
|
| 2 |
+
from utils.utils import read_json_file, write_json_file, write_text_file, json_to_markdown, read_text_file, parse_llm_output_to_json
|
| 3 |
+
from agent.create_charts import Chart
|
| 4 |
+
# from utils.convert_format import markdown_to_latex
|
| 5 |
+
import os
|
| 6 |
+
from prompt.template import PROBLEM_EXTRACT_PROMPT
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
if __name__ == "__main__":
|
| 11 |
+
import glob
|
| 12 |
+
files = glob.glob('/Users/ann/Downloads/methmatical_paper_extraction/parse/2025_*/content/*.md')
|
| 13 |
+
llm = LLM('chatgpt-4o-latest')
|
| 14 |
+
data = {}
|
| 15 |
+
for file in files:
|
| 16 |
+
year, _, _, problem_type = file.split('/')[-1].split('.')[0].split('_')
|
| 17 |
+
problem_name = f'{year}_{problem_type}'
|
| 18 |
+
problem_str = read_text_file(file)
|
| 19 |
+
problem = llm.generate(PROBLEM_EXTRACT_PROMPT.format(question=problem_str), problem_str)
|
| 20 |
+
problem = parse_llm_output_to_json(problem)
|
| 21 |
+
# data[problem_name] = problem
|
| 22 |
+
print(problem)
|
| 23 |
+
write_json_file(f'/Users/ann/Documents/projects/math_modeling/data/actor_data/input/problem/{problem_name}.json', problem)
|
core/utils/utils.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from typing import Dict
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def read_text_file(file_path: str) -> str:
|
| 6 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 7 |
+
return file.read()
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def read_json_file(file_path: str) -> Dict:
|
| 11 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 12 |
+
return json.load(file)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def write_text_file(file_path: str, content: str):
|
| 16 |
+
with open(file_path, 'w', encoding='utf-8') as file:
|
| 17 |
+
file.write(content)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def write_json_file(file_path: str, data:dict) -> Dict:
|
| 21 |
+
with open(file_path, "w", encoding="utf-8") as json_file:
|
| 22 |
+
json_file.write(json.dumps(data, indent=4, ensure_ascii=False))
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def parse_llm_output_to_json(output_text: str) -> dict:
|
| 26 |
+
"""
|
| 27 |
+
Safely parse LLM output text into a Python dictionary.
|
| 28 |
+
"""
|
| 29 |
+
start = output_text.find("{")
|
| 30 |
+
end = output_text.rfind("}") + 1
|
| 31 |
+
json_str = output_text[start:end]
|
| 32 |
+
try:
|
| 33 |
+
data = json.loads(json_str)
|
| 34 |
+
except:
|
| 35 |
+
raise
|
| 36 |
+
data = {}
|
| 37 |
+
return data
|
| 38 |
+
|
| 39 |
+
def json_to_markdown(paper):
|
| 40 |
+
"""
|
| 41 |
+
Converts a paper dictionary to a Markdown string with multi-level headlines.
|
| 42 |
+
|
| 43 |
+
Args:
|
| 44 |
+
paper (dict): The paper dictionary containing problem details and tasks.
|
| 45 |
+
|
| 46 |
+
Returns:
|
| 47 |
+
str: A Markdown-formatted string representing the paper.
|
| 48 |
+
"""
|
| 49 |
+
markdown_lines = []
|
| 50 |
+
|
| 51 |
+
# Problem Background
|
| 52 |
+
markdown_lines.append("## Problem Background")
|
| 53 |
+
markdown_lines.append(paper.get('problem_background', 'No background provided.') + "\n")
|
| 54 |
+
|
| 55 |
+
# Problem Requirement
|
| 56 |
+
markdown_lines.append("## Problem Requirement")
|
| 57 |
+
markdown_lines.append(paper.get('problem_requirement', 'No requirements provided.') + "\n")
|
| 58 |
+
|
| 59 |
+
# Problem Analysis
|
| 60 |
+
markdown_lines.append("## Problem Analysis")
|
| 61 |
+
markdown_lines.append(paper.get('problem_analysis', 'No analysis provided.') + "\n")
|
| 62 |
+
|
| 63 |
+
# Problem Modeling
|
| 64 |
+
if 'problem_modeling' in paper:
|
| 65 |
+
markdown_lines.append("## Problem Modeling")
|
| 66 |
+
markdown_lines.append(paper.get('problem_modeling', 'No modeling provided.') + "\n")
|
| 67 |
+
|
| 68 |
+
# Tasks
|
| 69 |
+
tasks = paper.get('tasks', [])
|
| 70 |
+
if tasks:
|
| 71 |
+
markdown_lines.append("## Tasks\n")
|
| 72 |
+
for idx, task in enumerate(tasks, start=1):
|
| 73 |
+
|
| 74 |
+
markdown_lines.append(f"### Task {idx}")
|
| 75 |
+
|
| 76 |
+
task_description = task.get('task_description', 'No description provided.')
|
| 77 |
+
markdown_lines.append("#### Task Description")
|
| 78 |
+
markdown_lines.append(task_description + "\n")
|
| 79 |
+
|
| 80 |
+
# Task Analysis
|
| 81 |
+
task_analysis = task.get('task_analysis', 'No analysis provided.')
|
| 82 |
+
markdown_lines.append("#### Task Analysis")
|
| 83 |
+
markdown_lines.append(task_analysis + "\n")
|
| 84 |
+
|
| 85 |
+
# Mathematical Formulas
|
| 86 |
+
task_formulas = task.get('mathematical_formulas', 'No formulas provided.')
|
| 87 |
+
markdown_lines.append("#### Mathematical Formulas")
|
| 88 |
+
if isinstance(task_formulas, list):
|
| 89 |
+
for formula in task_formulas:
|
| 90 |
+
markdown_lines.append(f"$${formula}$$")
|
| 91 |
+
else:
|
| 92 |
+
markdown_lines.append(f"$${task_formulas}$$")
|
| 93 |
+
markdown_lines.append("") # Add an empty line
|
| 94 |
+
|
| 95 |
+
# Mathematical Modeling Process
|
| 96 |
+
task_modeling = task.get('mathematical_modeling_process', 'No modeling process provided.')
|
| 97 |
+
markdown_lines.append("#### Mathematical Modeling Process")
|
| 98 |
+
markdown_lines.append(task_modeling + "\n")
|
| 99 |
+
|
| 100 |
+
# Result
|
| 101 |
+
task_result = task.get('result', 'No result provided.')
|
| 102 |
+
markdown_lines.append("#### Result")
|
| 103 |
+
markdown_lines.append(task_result + "\n")
|
| 104 |
+
|
| 105 |
+
# Answer
|
| 106 |
+
task_answer = task.get('answer', 'No answer provided.')
|
| 107 |
+
markdown_lines.append("#### Answer")
|
| 108 |
+
markdown_lines.append(task_answer + "\n")
|
| 109 |
+
|
| 110 |
+
# Charts
|
| 111 |
+
charts = task.get('charts', [])
|
| 112 |
+
if charts:
|
| 113 |
+
markdown_lines.append("#### Charts")
|
| 114 |
+
for i, chart in enumerate(charts, start=1):
|
| 115 |
+
markdown_lines.append(f"##### Chart {i}")
|
| 116 |
+
markdown_lines.append(chart + "\n")
|
| 117 |
+
|
| 118 |
+
# # Usage Information
|
| 119 |
+
# if 'usage' in paper:
|
| 120 |
+
# markdown_lines.append("## Usage Information")
|
| 121 |
+
# markdown_lines.append(paper.get('usage', 'No usage information provided.') + "\n")
|
| 122 |
+
|
| 123 |
+
# Combine all lines into a single string
|
| 124 |
+
markdown_str = "\n".join(markdown_lines)
|
| 125 |
+
return markdown_str
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def json_to_markdown_general(json_data):
|
| 129 |
+
"""
|
| 130 |
+
Convert a JSON object to a markdown format.
|
| 131 |
+
|
| 132 |
+
Args:
|
| 133 |
+
- json_data (str or dict): The JSON data to convert. It can be a JSON string or a dictionary.
|
| 134 |
+
|
| 135 |
+
Returns:
|
| 136 |
+
- str: The markdown formatted string.
|
| 137 |
+
"""
|
| 138 |
+
|
| 139 |
+
if isinstance(json_data, str):
|
| 140 |
+
json_data = json.loads(json_data) # If input is a JSON string, parse it.
|
| 141 |
+
|
| 142 |
+
def recursive_markdown(data, indent=0):
|
| 143 |
+
markdown_str = ""
|
| 144 |
+
indent_space = " " * indent
|
| 145 |
+
|
| 146 |
+
if isinstance(data, dict):
|
| 147 |
+
for key, value in data.items():
|
| 148 |
+
markdown_str += f"### {key}\n"
|
| 149 |
+
markdown_str += recursive_markdown(value, indent + 1)
|
| 150 |
+
elif isinstance(data, list):
|
| 151 |
+
for index, item in enumerate(data):
|
| 152 |
+
markdown_str += f"- **Item {index + 1}**\n"
|
| 153 |
+
markdown_str += recursive_markdown(item, indent + 1)
|
| 154 |
+
else:
|
| 155 |
+
markdown_str += f"- {data}\n"
|
| 156 |
+
|
| 157 |
+
return markdown_str
|
| 158 |
+
|
| 159 |
+
markdown = recursive_markdown(json_data)
|
| 160 |
+
return markdown
|
| 161 |
+
|
core/workflow/__init__.py
ADDED
|
File without changes
|
core/workflow/solution.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from prompt.constants import TASK_PROMPT
|
| 2 |
+
|
| 3 |
+
class Workflow:
|
| 4 |
+
def __init__(self):
|
| 5 |
+
self.agents = []
|
| 6 |
+
|
| 7 |
+
def add_agent(self, agent):
|
| 8 |
+
self.agents.append(agent)
|
| 9 |
+
|
| 10 |
+
def execute_workflow(self, task_description: str):
|
| 11 |
+
prompt = TASK_PROMPT.format(task_description=task_description)
|
| 12 |
+
for agent in self.agents:
|
| 13 |
+
agent.receive_prompt(prompt)
|
| 14 |
+
agent.execute()
|
data/.DS_Store
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d65165279105ca6773180500688df4bdc69a2c7b771752f0a46ef120b7fd8ec3
|
| 3 |
+
size 6148
|
data/actor_data/.DS_Store
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:764ed4022bd48062ec065bad80e512ade8e7a482312e989ee5ac1c44e574ffe3
|
| 3 |
+
size 6148
|
data/actor_data/docs/.DS_Store
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d65165279105ca6773180500688df4bdc69a2c7b771752f0a46ef120b7fd8ec3
|
| 3 |
+
size 6148
|
data/actor_data/input/.DS_Store
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c4f7d6d02b7c5d6f5e1e5a573881562319b1534e80d5b3067879b59981e466d8
|
| 3 |
+
size 6148
|
data/actor_data/input/code_template/main.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3ba7c8e238db048d21199cdadf96ccc7571bebdff130227f471d34ebbcf74836
|
| 3 |
+
size 350
|
data/actor_data/input/code_template/main1.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a3b8cb138acaa95ec917c075dfbec0d3d642ef65349a544ef20b52ea9a01dfcf
|
| 3 |
+
size 353
|
data/actor_data/input/code_template/main10.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5765acb721477a6b4323a8415d8fb0dd444122b0fde503e3c0637e3209990c85
|
| 3 |
+
size 356
|
data/actor_data/input/code_template/main2.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:488e549cc0d86c9fc43101ba10dbd4792f633bdc21f6af6cab6ec39cd6aef262
|
| 3 |
+
size 353
|
data/actor_data/input/code_template/main3.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:78ae56587f5dab567981b7143b1388580b889e19b0b3f9a992b72455ec8eed0d
|
| 3 |
+
size 353
|
data/actor_data/input/code_template/main4.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d60b7ad7cfda732c6143e50f283a344812f32a1df6dfbc4ba0da4917c5e120fa
|
| 3 |
+
size 353
|
data/actor_data/input/code_template/main5.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9a846a2f4fb918b853c277020997109dc36ea41328b225bfaf11caac96b378a5
|
| 3 |
+
size 353
|