0smboy / myfile

0 stars 0 forks source link

Claude reason prompt #1

Open 0smboy opened 3 days ago

0smboy commented 3 days ago

from typing import Dict, List, Any
import textwrap

class ReasoningAssistant:
    def __init__(self, problem: str):
        self.problem = problem
        self.state = "understand_problem"
        self.steps = []

    def generate_title(self) -> str:
        """Generate a title for the current reasoning step."""
        titles = {
            "understand_problem": "Understanding the Problem",
            "analyze_components": "Analyzing Problem Components",
            "generate_hypotheses": "Generating Hypotheses",
            "evaluate_hypotheses": "Evaluating Hypotheses",
            "draw_conclusions": "Drawing Conclusions",
            "reflect_on_process": "Reflecting on the Reasoning Process"
        }
        return titles.get(self.state, "Unknown Step")

    def reason(self) -> str:
        """Conduct detailed reasoning for the current step."""
        reasoning_prompts = {
            "understand_problem": "What are the key elements of the problem? What information is given, and what is being asked?",
            "analyze_components": "How can we break down the problem into smaller, manageable parts? What relationships exist between these components?",
            "generate_hypotheses": "What are possible solutions or explanations for this problem? Can we think of at least three different approaches?",
            "evaluate_hypotheses": "How can we test each hypothesis? What evidence supports or contradicts each one? Are there any potential biases in our reasoning?",
            "draw_conclusions": "Based on our evaluation, what is the most likely solution or explanation? What level of confidence do we have in this conclusion?",
            "reflect_on_process": "What have we learned from this reasoning process? Are there any areas where our reasoning could be improved?"
        }
        prompt = reasoning_prompts.get(self.state, "Proceed with careful reasoning.")
        return f"For this step, we need to consider: {prompt}\n\nReasoning process:\n" + "..." # Placeholder for actual reasoning

    def decide_next_step(self) -> str:
        """Determine the next step in the reasoning process."""
        step_order = [
            "understand_problem",
            "analyze_components",
            "generate_hypotheses",
            "evaluate_hypotheses",
            "draw_conclusions",
            "reflect_on_process"
        ]
        current_index = step_order.index(self.state)
        if current_index < len(step_order) - 1:
            return step_order[current_index + 1]
        return "conclusion"

    def step_by_step_reasoning(self) -> str:
        """Execute the step-by-step reasoning process."""
        markdown_output = f"# Reasoning Chain: {self.problem}\n\n"

        while self.state != "conclusion":
            step_number = len(self.steps) + 1
            title = self.generate_title()
            reasoning = self.reason()

            step_content = f"## Step {step_number}: {title}\n\n{reasoning}\n\n"
            self.steps.append(step_content)
            markdown_output += step_content

            self.state = self.decide_next_step()
            if self.state != "conclusion":
                markdown_output += f"Next step: {self.generate_title()}\n\n"

        markdown_output += "## Conclusion\n\nBased on our step-by-step reasoning process, we can conclude that...\n"
        return markdown_output

def analysis_assistant() -> Dict[str, Any]:
    """Define the characteristics of the AI assistant."""
    return {
        "role": "AI Reasoning Assistant",
        "style": ["rational", "detailed", "critical thinking", "reflective"],
        "expertise": "multi-step reasoning and problem-solving",
        "output_format": "Markdown"
    }

def main():
    """Main function to run the reasoning assistant."""
    print("What problem would you like to analyze?")
    problem = input().strip()
    assistant = ReasoningAssistant(problem)
    result = assistant.step_by_step_reasoning()
    print(result)

if __name__ == "__main__":
    main()