Skip to content

Commit

Permalink
result
Browse files Browse the repository at this point in the history
  • Loading branch information
femto committed Jan 31, 2025
1 parent 6efffb4 commit 41ca291
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ async def solve_question(item):
)
return answer

#model = "gpt-4o-mini"
model = "default"
model = "gpt-4o"
#model = "default"

llm = create_llm_provider(config.models.get(model))
cost_manager = CostManager()
Expand All @@ -253,6 +253,7 @@ async def main():
validation_data = load_dataset("deepmind/code_contests", split='valid')
test_data = load_dataset("deepmind/code_contests", split='test')
validation_data = [validation_data[1]]
#validation_data = [validation_data[0]]
correct, count, matched_ids, mismatched_ids = await evaluate_dataset(
validation_data, run_filename=f"run_code_contests_{model}_hard.json", continue_process=True, concurrency_count=1
)
Expand Down
1 change: 1 addition & 0 deletions minion/configs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ImageDetail(str, Enum):
class LLMConfig(BaseModel):
api_type: str = "openai"
api_key: str
api_version: Optional[str] = None
# base_url: Optional[HttpUrl] = None
base_url: Optional[str] = None
model: str
Expand Down
29 changes: 15 additions & 14 deletions minion/main/improve.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from abc import ABC, abstractmethod
from minion.actions.lmp_action_node import LmpActionNode
from minion.main.minion import Minion, register_improver_minion
from minion.main.prompt import IMPROVE_CODE_PROMPT
from minion.main.prompt import IMPROVE_CODE_PROMPT, IMPROVE_PROMPT
from minion.utils.template import render_template_with_variables

class ImproverMinion(Minion):
"""所有 improver minion 的基类"""
Expand All @@ -15,26 +16,26 @@ async def execute(self):

@register_improver_minion(name="feedback")
class FeedbackMinion(ImproverMinion):
"""基于反馈进行通用内容改进的 Minion"""
async def execute(self):
# 使用测试用例来改进代码
test_cases = self.worker.input.metadata.get("test_cases", [])
ai_test_cases = self.worker.input.metadata.get("ai_test_cases", [])

"""基于反馈进行通用内容改进的执行方法"""
# 构建改进提示
prompt = IMPROVE_CODE_PROMPT.format(
code=self.worker.answer,
test_cases=test_cases,
ai_test_cases=ai_test_cases,
entry_point=self.worker.input.entry_point
prompt = render_template_with_variables(
template_str=IMPROVE_PROMPT,
input={
"answer": self.worker.input.answer, #todo, maybe stateful agent connections?
"feedback": self.worker.input.feedback,
**self.worker.input.__dict__ # 包含其他上下文信息
}
)

# 使用 LLM 改进代码
# 使用 LLM 改进内容
node = LmpActionNode(self.brain.llm)
improved_code = await node.execute(prompt)
improved_answer = await node.execute(prompt)

# 更新 worker 的答案
self.worker.answer = improved_code
return improved_code
self.worker.answer = improved_answer
return improved_answer

@register_improver_minion(name="reasoning")
class ReasoningMinion(ImproverMinion):
Expand Down
20 changes: 20 additions & 0 deletions minion/main/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,26 @@
Reasoning:
"""

IMPROVE_PROMPT = f"""Given the following problem details:
{ASK_PROMPT_JINJA}
{ASK_ADDITIONAL_INFO_JINJA}
Current answer:
{{ input.answer }}
Feedback for improvement:
{{ input.feedback }}
Based on the above feedback, please provide an improved answer. The improved answer should:
1. Address all points mentioned in the feedback
2. Maintain the strengths of the original answer
3. Be clear, accurate, and well-structured
4. Be complete and self-contained
Return only the improved answer without any explanations or comments.
"""

IMPROVE_CODE_PROMPT = """You are a code improvement expert. Your task is to improve the given code based on the test cases.
Current code:
Expand Down
4 changes: 2 additions & 2 deletions minion/main/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
)
from minion.main.symbol_table import Symbol
from minion.main.task_graph import convert_tasks_to_graph
from minion.utils.utils import most_similar_minion
from minion.utils.utils import most_similar_minion, camel_case_to_snake_case
from minion.actions.lmp_action_node import LmpActionNode
from minion.models.schemas import (
MetaPlan,
Expand Down Expand Up @@ -746,7 +746,7 @@ async def get_minion_class_and_name(self):
if self.input.execution_state.chosen_minion:
# 从上次状态恢复
name = self.input.execution_state.chosen_minion
klass = MINION_REGISTRY.get(name, CotMinion)
klass = MINION_REGISTRY.get(camel_case_to_snake_case(name), CotMinion) #todo: tmp fix here, actually is other place's bug to store "CotMinion"
return klass, name

# 新的执行流程
Expand Down

0 comments on commit 41ca291

Please sign in to comment.