Llama 3.3笔记代码

ollama

ollama run llama3.3

测试问题

✅ 講個故事吧


✅ how many 'r's in strawberrrry?


✅ 用python实现计算179424673是第几个质数?



✅ 三位传教士和三位食人族需要过河。
他们有一艘船,每次最多可以载两人。
如果在任何时候,食人族的数量超过了传教士的数量(无论是在河的哪一侧),食人族就会吃掉传教士。
如何让所有六个人安全过河?请提供分步骤的解决方案,并用ASCII图示展示解决方案。

算法测试

https://edabit.com/challenges

prompt

Begin by enclosing all thoughts within <thinking> tags, exploring multiple angles and approaches.
Break down the solution into clear steps within <step> tags. Start with a 20-step budget, requesting more for complex problems if needed.
Use <count> tags after each step to show the remaining budget. Stop when reaching 0.
Continuously adjust your reasoning based on intermediate results and reflections, adapting your strategy as you progress.
Regularly evaluate progress using <reflection> tags. Be critical and honest about your reasoning process.
Assign a quality score between 0.0 and 1.0 using <reward> tags after each reflection. Use this to guide your approach:

0.8+: Continue current approach
0.5-0.7: Consider minor adjustments
Below 0.5: Seriously consider backtracking and trying a different approach

If unsure or if reward score is low, backtrack and try a different approach, explaining your decision within <thinking> tags.
For mathematical problems, show all work explicitly using LaTeX for formal notation and provide detailed proofs.
Explore multiple solutions individually if possible, comparing approaches in reflections.
Use thoughts as a scratchpad, writing out all calculations and reasoning explicitly.
Synthesize the final answer within <answer> tags, providing a clear, comprehensive summary.
Conclude with a final reflection on the overall solution, discussing effectiveness, challenges, and solutions. Assign a final reward score.

Output all in Chinese


How many 'r's in strawberrrry?

🔥🔥🔥如有问题,请联系我的徽信 stoeng

🔥🔥🔥本项目代码由AI超元域频道制作,观看更多大模型微调视频请访问我的频道⬇

👉👉👉我的哔哩哔哩频道

👉👉👉我的YouTube频道

👉👉👉我的开源项目 https://github.com/win4r/AISuperDomain

You are an expert AI assistant tasked with providing thorough, step-by-step reasoning for complex problems or questions. Follow these guidelines:

1. For each step in your reasoning process:
   - Provide a clear, descriptive title
   - Explain your thought process in detail
   - Use markdown formatting for better readability

2. Use at least 3 different methods or approaches to analyze the problem

3. Include exploration of alternative answers and potential errors in your reasoning

4. Be aware of your limitations as a language model and explicitly state what you can and cannot do

5. When re-examining your reasoning, use a genuinely different approach

6. Apply best practices in problem-solving and critical thinking

7. Conclude with a final answer only when you've exhausted your analysis

8. Structure your response as follows:

```json
{
  "step": 1,
  "title": "Identifying Key Information",
  "content": "## Identifying Key Information\n\nTo begin solving this problem, we need to carefully examine the given information and identify the crucial elements that will guide our solution process. This involves...",
  "next_action": "continue"
}
```

9. For the final step, use "next_action": "final_answer" and include your conclusion

10. Strive for clarity, thoroughness, and intellectual honesty in your analysis

How many 'r's in strawberrrry?

aider

python -m pip install -U aider-chat


export OPENROUTER_API_KEY=<key> # Mac/Linux
setx   OPENROUTER_API_KEY <key> # Windows, restart shell after setx

aider --model openrouter/meta-llama/llama-3.3-70b-instruct

autogen

#这是一个多代理(multi-agent)协作聊天系统示例,它通过多个角色(分析专家、解决方案专家和整合专家)对输入问题进行处理和回答。
#代码的核心逻辑是使用GroupChat和GroupChatManager将多个助手机器人(AssistantAgent)协调起来,以分步骤解决问题并最终生成一个整合后的报告。


# 导入必要的库
import os
from autogen import AssistantAgent, UserProxyAgent, GroupChat, GroupChatManager, config_list_from_json
import openai
from google.colab import userdata


# 设置LLM API密钥
#
# os.environ["OPENAI_API_KEY"] = userdata.get('OPENAI_API_KEY')
# openai.api_key = os.getenv("OPENAI_API_KEY")

# LLM模型配置
# model: 使用的GPT模型
# temperature: 控制输出的随机性,越高越随机,越低越确定
# llm_config = {
#     "model": "gpt-4o-mini",
#     "api_key": os.getenv("OPENAI_API_KEY"),
#     "temperature": 0.7,
# }

os.environ["OPENROUTER_API_KEY"] = userdata.get('OPENROUTER_API_KEY')



llm_config = {
    "config_list": [
        {
            "model": "meta-llama/llama-3.3-70b-instruct",
            "base_url":"https://openrouter.ai/api/v1",
            "api_key":os.getenv("OPENROUTER_API_KEY"),
        }
    ]
}


def process_question(question):
    """
    使用GroupChat处理问题的主要函数
    参数:
        question: 需要分析和解决的问题
    返回:
        处理后的最终回答或错误信息
    """

    try:
        # 创建用户代理
        # 作为用户与其他AI代理交互的桥梁
        # human_input_mode="NEVER"表示不需要人类干预
        user_proxy = UserProxyAgent(
            name="user_proxy",
            system_message="A proxy for the user to communicate with the group chat.",
            human_input_mode="NEVER"
        )

        # 创建分析专家代理
        # 负责问题分析,识别关键组件和挑战
        analyst = AssistantAgent(
            name="analyst",
            system_message="""You are an analysis expert. Your task is ONLY to:
            1. Analyze the given problem thoroughly
            2. Identify key components and challenges
            3. Provide a structured analysis
            4. End your analysis with clear conclusions
            DO NOT propose solutions - that is the Solution Explorer's job.""",
            llm_config=llm_config
        )

        # 创建解决方案专家代理
        # 基于分析结果提出具体解决方案
        solution_explorer = AssistantAgent(
            name="solution_explorer",
            system_message="""You are a solution architect. Your task is ONLY to:
            1. Review the analyst's analysis
            2. Propose concrete solutions
            3. Provide implementation steps
            4. End with clear recommendations
            Focus ONLY on solutions, the analysis has already been done.""",
            llm_config=llm_config
        )

        # 创建技术文档撰写代理
        # 负责整合分析和解决方案,生成最终报告
        integrator = AssistantAgent(
            name="integrator",
            system_message="""You are a technical writer. Your task is to:
            1. Review both the analysis and solutions provided
            2. Create a comprehensive final report
            3. Ensure all sections are properly integrated
            4. End with actionable conclusions""",
            llm_config=llm_config
        )

        # 创建群聊,将所有代理加入其中
        # max_round=4确保每个代理都有机会发言
        groupchat = GroupChat(
            agents=[user_proxy, analyst, solution_explorer, integrator],
            messages=[],
            max_round=4  # 增加轮数以确保每个agent都有机会发言
        )

        # 创建群聊管理器,控制对话流程
        manager = GroupChatManager(groupchat=groupchat, llm_config=llm_config)

        # 构建初始问题消息
        # 定义明确的处理流程和每个代理的任务
        initial_message = f"""
        Please help analyze and provide solutions for: {question}

        Follow this EXACT process:
        1. First, Analyst will ONLY provide analysis
        2. Then, Solution Explorer will ONLY provide solutions based on the analysis
        3. Finally, Integrator will create the final report

        Each agent must wait for the previous agent to complete their task before starting.
        Analyst: Start by providing ONLY the analysis.
        """

        # 发起对话
        chat_result = user_proxy.initiate_chat(
            manager,
            message=initial_message
        )

        # 从对话历史中获取最终结果
        # 返回最后一条有效消息
        final_messages = chat_result.chat_history
        if final_messages:
            for msg in reversed(final_messages):
                if msg.get('content'):
                    return msg['content']

        return "No valid response generated"

    except Exception as e:
        return f"Error in processing: {str(e)}"

def main():
    # 设置日志
    import logging
    logging.basicConfig(level=logging.INFO)

    # 示例问题
    question = "How to implement a secure authentication system?"
    print("\nProcessing question:", question)
    print("\nGenerating response...\n")

    # 处理问题并输出结果
    try:
        response = process_question(question)
        print("\nFinal Response:")
        print(response)
    except Exception as e:
        print(f"Error occurred: {str(e)}")

# 程序入口点
if __name__ == "__main__":
    main()